Skip to content

Commit

Permalink
chore(cdk-cli-wrapper): fix tests for monorepo (aws#32511)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
rix0rrr authored Dec 13, 2024
1 parent 62a0638 commit ad1699a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/@aws-cdk/cdk-cli-wrapper/test/cdk-wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { RequireApproval, StackActivityProgress } from '../lib/commands';
let spawnSyncMock: jest.SpyInstance;
let spawnMock: jest.SpyInstance;

// Necessary to make the spyOn below work
jest.mock('child_process', () => ({ __esModule: true, ...jest.requireActual('child_process') }));

beforeEach(() => {
spawnSyncMock = jest.spyOn(child_process, 'spawnSync').mockReturnValue({
status: 0,
Expand Down

0 comments on commit ad1699a

Please sign in to comment.