@@ -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
547500const 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+ } ) ;
0 commit comments