Skip to content

Commit ad1699a

Browse files
authored
chore(cdk-cli-wrapper): fix tests for monorepo (#32511)
In a slightly different testing setup, the `jest.spyOn` calls fail with the error: ``` Cannot redefine property: spawnSync ``` This has to do with how the object representing the `fs` module is defined. We can override the module and return a plain object with all the functions, so that the elements can be mocked later on. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 62a0638 commit ad1699a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

packages/@aws-cdk/cdk-cli-wrapper/test/cdk-wrapper.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { RequireApproval, StackActivityProgress } from '../lib/commands';
44
let spawnSyncMock: jest.SpyInstance;
55
let spawnMock: jest.SpyInstance;
66

7+
// Necessary to make the spyOn below work
8+
jest.mock('child_process', () => ({ __esModule: true, ...jest.requireActual('child_process') }));
9+
710
beforeEach(() => {
811
spawnSyncMock = jest.spyOn(child_process, 'spawnSync').mockReturnValue({
912
status: 0,

0 commit comments

Comments
 (0)