Skip to content

Commit 5cb99a5

Browse files
authored
revert(core): temp cleanup does not work with jest (#36237)
Reverts #36226, which is now causing `ENOMEM` errors on CodeBuild. Revert for now.
1 parent 4056e14 commit 5cb99a5

File tree

4 files changed

+5
-76
lines changed

4 files changed

+5
-76
lines changed

packages/aws-cdk-lib/cx-api/lib/cloud-assembly.ts

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -33,53 +33,6 @@ export class CloudAssembly implements ICloudAssembly {
3333
return x !== null && typeof(x) === 'object' && CLOUD_ASSEMBLY_SYMBOL in x;
3434
}
3535

36-
/**
37-
* Cleans up any temporary assembly directories that got created in this process
38-
*
39-
* If a Cloud Assembly is emitted to a temporary directory, its directory gets
40-
* added to a list. This function iterates over that list and deletes each
41-
* directory in it, to free up disk space.
42-
*
43-
* This function will normally be called automatically during Node process
44-
* exit and so you don't need to call this. However, some test environments do
45-
* not properly trigger Node's `exit` event. Notably: Jest does not trigger
46-
* the `exit` event (<https://github.com/jestjs/jest/issues/10927>).
47-
*
48-
* ## Cleaning up temporary directories in jest
49-
*
50-
* For Jest, you have to make sure this function is called at the end of the
51-
* test suite instead:
52-
*
53-
* ```js
54-
* import { CloudAssembly } from 'aws-cdk-lib/cx-api';
55-
*
56-
* afterAll(CloudAssembly.cleanupTemporaryDirectories);
57-
* ```
58-
*
59-
* Alternatively, you can use the `setupFilesAfterEnv` feature and use a
60-
* provided helper script to automatically inject the above into every
61-
* test file, so you don't have to do it by hand.
62-
*
63-
* ```
64-
* $ npx jest --setupFilesAfterEnv aws-cdk-lib/testhelpers/jest-autoclean
65-
* ```
66-
*
67-
* Or put the following into `jest.config.js`:
68-
*
69-
* ```js
70-
* module.exports = {
71-
* // ...
72-
* setupFilesAfterEnv: ['aws-cdk-lib/testhelpers/jest-cleanup'],
73-
* };
74-
* ```
75-
*/
76-
public static cleanupTemporaryDirectories() {
77-
for (const dir of TEMPORARY_ASSEMBLY_DIRS) {
78-
fs.rmSync(dir, { recursive: true, force: true });
79-
}
80-
TEMPORARY_ASSEMBLY_DIRS.splice(0, TEMPORARY_ASSEMBLY_DIRS.length);
81-
}
82-
8336
/**
8437
* The root directory of the cloud assembly.
8538
*/
@@ -545,4 +498,8 @@ function ensureDirSync(dir: string) {
545498

546499
// On process exit, delete all temporary assembly directories
547500
const TEMPORARY_ASSEMBLY_DIRS: string[] = [];
548-
process.on('exit', () => CloudAssembly.cleanupTemporaryDirectories());
501+
process.on('exit', () => {
502+
for (const dir of TEMPORARY_ASSEMBLY_DIRS) {
503+
fs.rmSync(dir, { recursive: true, force: true });
504+
}
505+
});

packages/aws-cdk-lib/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@
530530
"./pipelines/package.json": "./pipelines/package.json",
531531
"./recommended-feature-flags.json": "./recommended-feature-flags.json",
532532
"./region-info": "./region-info/index.js",
533-
"./testhelpers/jest-autoclean": "./testhelpers/jest-autoclean.js",
534533
"./triggers": "./triggers/index.js"
535534
},
536535
"publishConfig": {

packages/aws-cdk-lib/testhelpers/jest-autoclean.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

tools/@aws-cdk/cdk-build-tools/config/jest.config.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
const thisPackagesPackageJson = require(`${process.cwd()}/package.json`);
2-
const setupFilesAfterEnv = [];
3-
if ('aws-cdk-lib' in thisPackagesPackageJson.devDependencies ?? {}) {
4-
// If we depend on aws-cdk-lib, use the provided autoclean hook
5-
setupFilesAfterEnv.push('aws-cdk-lib/testhelpers/jest-autoclean');
6-
} else if (thisPackagesPackageJson.name === 'aws-cdk-lib') {
7-
// If we *ARE* aws-cdk-lib, use the hook in a slightly different way
8-
setupFilesAfterEnv.push('./testhelpers/jest-autoclean.ts');
9-
}
10-
111
module.exports = {
122
// The preset deals with preferring TS over JS
133
moduleFileExtensions: [
@@ -41,6 +31,4 @@ module.exports = {
4131
],
4232
coveragePathIgnorePatterns: ['\\.generated\\.[jt]s$', '<rootDir>/test/', '.warnings.jsii.js$', '/node_modules/'],
4333
reporters: ['default', ['jest-junit', { suiteName: 'jest tests', outputDirectory: 'coverage' }]],
44-
45-
setupFilesAfterEnv,
4634
};

0 commit comments

Comments
 (0)