Skip to content

Commit 4a88cbb

Browse files
authored
chore(integ-runner): fix a race in the unit tests (#22960)
We weren't actually mocking the `writeFileSync` call we thought we were, as the internal libraries call `fs.writeFileSync`, but we were mocking `fs-extra.writeFileSync`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 48e3035 commit 4a88cbb

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

packages/@aws-cdk/integ-runner/test/runner/integ-test-runner.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as child_process from 'child_process';
2+
import * as builtinFs from 'fs';
23
import { Manifest } from '@aws-cdk/cloud-assembly-schema';
34
import { AVAILABILITY_ZONE_FALLBACK_CONTEXT_KEY } from '@aws-cdk/cx-api';
45
import * as fs from 'fs-extra';
@@ -24,7 +25,9 @@ beforeEach(() => {
2425
});
2526
jest.spyOn(fs, 'moveSync').mockImplementation(() => { return true; });
2627
removeSyncMock = jest.spyOn(fs, 'removeSync').mockImplementation(() => { return true; });
27-
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => { return true; });
28+
29+
// fs-extra delegates to the built-in one, this also catches calls done directly
30+
jest.spyOn(builtinFs, 'writeFileSync').mockImplementation(() => { return true; });
2831
});
2932

3033
afterEach(() => {

packages/@aws-cdk/integ-runner/test/runner/snapshot-test-runner.test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as child_process from 'child_process';
2+
import * as builtinFs from 'fs';
23
import * as path from 'path';
34
import * as fs from 'fs-extra';
45
import { IntegSnapshotRunner, IntegTest } from '../../lib/runner';
@@ -24,8 +25,10 @@ beforeEach(() => {
2425
jest.spyOn(process.stdout, 'write').mockImplementation(() => { return true; });
2526
jest.spyOn(fs, 'moveSync').mockImplementation(() => { return true; });
2627
jest.spyOn(fs, 'removeSync').mockImplementation(() => { return true; });
27-
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => { return true; });
28-
jest.spyOn(fs, 'rmdirSync').mockImplementation(() => { return true; });
28+
29+
// fs-extra delegates to the built-in one, this also catches calls done directly
30+
jest.spyOn(builtinFs, 'writeFileSync').mockImplementation(() => { return true; });
31+
jest.spyOn(builtinFs, 'rmdirSync').mockImplementation(() => { return true; });
2932
});
3033

3134
afterEach(() => {

packages/@aws-cdk/integ-runner/test/workers/integ-worker.test.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as child_process from 'child_process';
2+
import * as builtinFs from 'fs';
23
import * as path from 'path';
34
import * as fs from 'fs-extra';
45
import * as workerpool from 'workerpool';
@@ -13,10 +14,13 @@ beforeAll(() => {
1314
beforeEach(() => {
1415
jest.spyOn(fs, 'moveSync').mockImplementation(() => { return true; });
1516
jest.spyOn(fs, 'emptyDirSync').mockImplementation(() => { return true; });
16-
jest.spyOn(fs, 'unlinkSync').mockImplementation(() => { return true; });
1717
jest.spyOn(fs, 'removeSync').mockImplementation(() => { return true; });
18-
jest.spyOn(fs, 'rmdirSync').mockImplementation(() => { return true; });
19-
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => { return true; });
18+
19+
// fs-extra delegates to the built-in one, this also catches calls done directly
20+
jest.spyOn(builtinFs, 'rmdirSync').mockImplementation(() => { return true; });
21+
jest.spyOn(builtinFs, 'writeFileSync').mockImplementation(() => { return true; });
22+
jest.spyOn(builtinFs, 'unlinkSync').mockImplementation(() => { return true; });
23+
2024
spawnSyncMock = jest.spyOn(child_process, 'spawnSync')
2125
.mockReturnValueOnce({
2226
status: 0,

0 commit comments

Comments
 (0)