Skip to content

Comments

test: cdk watch integ tests for cli and toolkit lib#1139

Open
iankhou wants to merge 9 commits intomainfrom
iankhou-cdk-watch-integ
Open

test: cdk watch integ tests for cli and toolkit lib#1139
iankhou wants to merge 9 commits intomainfrom
iankhou-cdk-watch-integ

Conversation

@iankhou
Copy link
Contributor

@iankhou iankhou commented Feb 12, 2026

Tests #1134

Description of tests

cdk watch in CLI

  • Test: Detects file changes
  • **OMIT Test: ** negative test, since we would have to wait for "nothing" to happen—this takes a lot more time

Toolkit.watch()

  • Test: Detects file changes for watched files
  • Test: Does NOT detect file changes for unwatched files

We used AI 🤖 to help with this contribution.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@codecov-commenter
Copy link

codecov-commenter commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.72%. Comparing base (6b190a2) to head (e5bafec).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    aws/aws-cdk-cli#1139   +/-   ##
=======================================
  Coverage   87.71%   87.72%           
=======================================
  Files          72       72           
  Lines       10129    10129           
  Branches     1338     1337    -1     
=======================================
+ Hits         8885     8886    +1     
+ Misses       1218     1217    -1     
  Partials       26       26           
Flag Coverage Δ
suite.unit 87.72% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@iankhou iankhou marked this pull request as ready for review February 17, 2026 15:57
@iankhou iankhou enabled auto-merge February 17, 2026 16:23
@iankhou iankhou assigned iankhou and unassigned iankhou Feb 17, 2026
Comment on lines +78 to +79
// Use separate output dir to avoid conflicts with lingering watch process
await fixture.cdkDestroy('test-1', { options: ['--output', 'cdk-destroy.out'] });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to manually delete. The rest harness is doing this for us.

Suggested change
// Use separate output dir to avoid conflicts with lingering watch process
await fixture.cdkDestroy('test-1', { options: ['--output', 'cdk-destroy.out'] });

}),
);

integTest(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one test per file. Pls move to separate file.

Comment on lines +84 to +110
async function waitForOutput(getOutput: () => string, searchString: string, timeoutMs: number): Promise<void> {
const startTime = Date.now();
return new Promise((resolve, reject) => {
const check = () => {
if (getOutput().includes(searchString)) return resolve();
if (Date.now() - startTime > timeoutMs) {
return reject(new Error(`Timeout waiting for: "${searchString}"`));
}
setTimeout(check, 1000);
};
check();
});
}

async function waitForCondition(condition: () => boolean, timeoutMs: number, description: string): Promise<void> {
const startTime = Date.now();
return new Promise((resolve, reject) => {
const check = () => {
if (condition()) return resolve();
if (Date.now() - startTime > timeoutMs) {
return reject(new Error(`Timeout waiting for ${description}`));
}
setTimeout(check, 1000);
};
check();
});
}
Copy link
Contributor

@mrgrain mrgrain Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there really no existing helpers for this?

});

try {
await waitForOutput(() => output, "Triggering initial 'cdk deploy'", 120000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did you come up with these timeout durations?

);

integTest(
'toolkit watch excludes node_modules and dotfiles by default',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this test not part of the cli integ tests also?

Copy link
Contributor Author

@iankhou iankhou Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it will add more time to the test, while offering limited utility IMO. Probably another minute or so. See my PR description where I addressed this discrepancy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont understand why this would be the case. i think you need to
a) touch node_modules / dotfiles
b) assert that we do not see Detected change to '<file>' -- this happens nearly instantly if the file is being watched, so i dont see why it would take another minute.

as for whether this offers utility, i think its worse if we accidentally don't exclude files from watch than if we accidentally don't include files.

const cdkJsonPath = path.join(fixture.integTestDir, 'cdk.json');
const cdkJson = JSON.parse(fs.readFileSync(cdkJsonPath, 'utf-8'));
cdkJson.watch = {
include: ['**/*.ts', '**/*.js'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: including the .js files is a bad idea for some use cases (say you're also auto-compiling ts changes, now you're double counting). doesn't seem necessary in your test

const cdkJson = JSON.parse(fs.readFileSync(cdkJsonPath, 'utf-8'));
cdkJson.watch = {
include: ['**/*.ts', '**/*.js'],
exclude: ['node_modules/**', 'cdk.out/**', '**/*.d.ts'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part isn't tested. in this test or a new one, we should be testing that changes to exclude files do not trigger deployment.

include: ['**/*.ts', '**/*.js'],
exclude: ['node_modules/**', 'cdk.out/**', '**/*.d.ts'],
};
fs.writeFileSync(cdkJsonPath, JSON.stringify(cdkJson, null, 2));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can also just call touch on the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants