Skip to content

Commit 62729ed

Browse files
authored
chore(cli): stops tests from interfering with each other (#32319)
Turn on test randomization: this causes tests to run in a random order, which will expose tests that only succeed because tests before them have left the system in a specific state (or that poison tests after them because they don't clean up). Of course, doing this exposed that we have a number of such tests, clean those up as well. This needed to clean up mocking a lot in the garbage collector code, because it was confusing. Also remove the side-effect mock resetting that happens whenver a `MockSdk()` is instantiated, since that caused prepared mock behavior to be cleared. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 6458439 commit 62729ed

File tree

10 files changed

+126
-152
lines changed

10 files changed

+126
-152
lines changed

packages/aws-cdk/jest.config.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const baseConfig = require('@aws-cdk/cdk-build-tools/config/jest.config');
2-
module.exports = {
2+
3+
const config = {
34
...baseConfig,
45
coverageThreshold: {
56
global: {
@@ -21,4 +22,18 @@ module.exports = {
2122
// We have many tests here that commonly time out
2223
testTimeout: 30_000,
2324
setupFilesAfterEnv: ["<rootDir>/test/jest-setup-after-env.ts"],
25+
26+
// Randomize test order: this will catch tests that accidentally pass or
27+
// fail because they rely on shared mutable state left by other tests
28+
// (files on disk, global mocks, etc).
29+
randomize: true,
2430
};
31+
32+
// Disable coverage running in the VSCode debug terminal: we never want coverage
33+
// when we're attaching a debugger because the coverage injection messes with
34+
// the source maps.
35+
if (process.env.VSCODE_INJECTION) {
36+
config.collectCoverage = false;
37+
}
38+
39+
module.exports = config;

0 commit comments

Comments
 (0)