Skip to content

Commit c3bd4d9

Browse files
authored
chore(toolkit): randomize tests (#33429)
### Reason for this change Randomizing tests is good practice to ensure test cases are written in a self-contained way. ### Description of changes Enable randomizing tests and fix mocks that were dependent on state. Also increase minimum coverage thresholds to match current reality. ### Describe any new or updated permissions being added n/a ### Description of how you validated changes existing tests ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 23c912f commit c3bd4d9

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed
+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
const baseConfig = require('@aws-cdk/cdk-build-tools/config/jest.config');
22
module.exports = {
33
...baseConfig,
4+
randomize: true,
45
coverageThreshold: {
56
global: {
67
// this is very sad but we will get better
7-
branches: 42,
8-
statements: 69,
8+
statements: 75,
9+
branches: 55,
10+
functions: 70,
11+
lines: 75,
912
},
1013
},
1114
};

packages/@aws-cdk/toolkit/test/actions/destroy.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const ioHost = new TestIoHost();
77
const toolkit = new Toolkit({ ioHost });
88
jest.spyOn(toolkit, 'rollback').mockResolvedValue();
99

10-
let mockDestroyStack = jest.fn().mockResolvedValue({});
10+
let mockDestroyStack = jest.fn();
1111

1212
jest.mock('../../lib/api/aws-cdk', () => {
1313
return {
@@ -22,6 +22,7 @@ beforeEach(() => {
2222
ioHost.notifySpy.mockClear();
2323
ioHost.requestSpy.mockClear();
2424
jest.clearAllMocks();
25+
mockDestroyStack.mockResolvedValue({});
2526
});
2627

2728
describe('destroy', () => {
@@ -68,7 +69,7 @@ describe('destroy', () => {
6869

6970
test('destroy deployment fails', async () => {
7071
// GIVEN
71-
mockDestroyStack = jest.fn().mockRejectedValue({});
72+
mockDestroyStack.mockRejectedValue({});
7273

7374
// WHEN
7475
const cx = await builderFixture(toolkit, 'stack-with-role');

packages/@aws-cdk/toolkit/test/actions/rollback.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import { builderFixture, TestIoHost } from '../_helpers';
55
const ioHost = new TestIoHost();
66
const toolkit = new Toolkit({ ioHost });
77

8-
let mockRollbackStack = jest.fn().mockResolvedValue({
9-
notInRollbackableState: false,
10-
success: true,
11-
});
12-
8+
let mockRollbackStack = jest.fn();
139
jest.mock('../../lib/api/aws-cdk', () => {
1410
return {
1511
...jest.requireActual('../../lib/api/aws-cdk'),
@@ -23,6 +19,10 @@ beforeEach(() => {
2319
ioHost.notifySpy.mockClear();
2420
ioHost.requestSpy.mockClear();
2521
jest.clearAllMocks();
22+
mockRollbackStack.mockResolvedValue({
23+
notInRollbackableState: false,
24+
success: true,
25+
});
2626
});
2727

2828
describe('rollback', () => {

0 commit comments

Comments
 (0)