Skip to content

Commit 647111e

Browse files
authored
fix(integ-runner): assertion failures are incorrectly passing tests (#1024)
Fixes #1007 Integration tests were incorrectly reporting success even when assertions failed. The test output would show assertion failures in the CloudFormation stack outputs (with `"status":"fail"` messages), but the integ-runner would still report the test as passed. This happened because the integ-runner wasn't passing the `outputsFile` option through to the toolkit-lib deploy method. Without this, assertion results were never written to disk and couldn't be evaluated by the test runner. The fix ensures the `outputsFile` path is properly resolved to an absolute path and passed through to the deploy method, allowing the runner to correctly detect and report assertion failures. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 9c322c7 commit 647111e

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

packages/@aws-cdk/integ-runner/lib/engines/toolkit-lib.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export class ToolkitLibRunnerEngine implements ICdk {
177177
traceLogs: options.traceLogs,
178178
stacks: this.stackSelector(options),
179179
deploymentMethod: this.deploymentMethod(options),
180+
outputsFile: options.outputsFile ? path.join(this.options.workingDirectory, options.outputsFile) : undefined,
180181
});
181182
}
182183

packages/@aws-cdk/integ-runner/test/engines/toolkit-lib.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,30 @@ describe('ToolkitLibRunnerEngine', () => {
144144
method: 'hotswap',
145145
fallback: { method: 'change-set' },
146146
},
147+
outputsFile: undefined,
148+
});
149+
});
150+
151+
it('should pass outputsFile with absolute path when provided', async () => {
152+
const mockCx = {};
153+
mockToolkit.fromCdkApp.mockResolvedValue(mockCx as any);
154+
155+
await engine.deploy({
156+
app: 'test-app',
157+
stacks: ['stack1'],
158+
outputsFile: 'assertion-results.json',
159+
});
160+
161+
expect(mockToolkit.deploy).toHaveBeenCalledWith(mockCx, {
162+
stacks: {
163+
strategy: 'pattern-must-match',
164+
patterns: ['stack1'],
165+
expand: 'upstream',
166+
},
167+
deploymentMethod: {
168+
method: 'change-set',
169+
},
170+
outputsFile: '/test/dir/assertion-results.json',
147171
});
148172
});
149173

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,44 @@ describe('IntegTest runIntegTests', () => {
650650
app: 'node --no-warnings test/test-data/xxxxx.test-with-snapshot.js',
651651
}));
652652
});
653+
654+
test('with failed assertions', async () => {
655+
// GIVEN
656+
const outputsFile = 'cdk-integ.out.xxxxx.test-with-snapshot.js.snapshot/assertion-results.json';
657+
const fullOutputsPath = `test/test-data/${outputsFile}`;
658+
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
659+
jest.spyOn(fs, 'readJSONSync').mockReturnValue({
660+
BundlingDefaultTestDeployAssertAACA0CAF: {
661+
AssertionResultsTest123: '{"status":"fail","message":"Expected 2 but received 1"}',
662+
},
663+
});
664+
jest.spyOn(fs, 'unlinkSync').mockImplementation();
665+
666+
const integTest = new IntegTestRunner({
667+
cdk: cdkMock.cdk,
668+
region: 'eu-west-1',
669+
test: new IntegTest({
670+
fileName: 'test/test-data/xxxxx.test-with-snapshot.js',
671+
discoveryRoot: 'test/test-data',
672+
}),
673+
});
674+
675+
// WHEN
676+
const results = await integTest.runIntegTestCase({
677+
testCaseName: 'xxxxx.test-with-snapshot',
678+
});
679+
680+
// THEN
681+
expect(results).toBeDefined();
682+
expect(results?.AssertionResultsTest123).toEqual({
683+
status: 'fail',
684+
message: 'Expected 2 but received 1',
685+
});
686+
expect(cdkMock.mocks.deploy).toHaveBeenCalledWith(expect.objectContaining({
687+
outputsFile: fullOutputsPath,
688+
}));
689+
expect(fs.readJSONSync).toHaveBeenCalledWith(fullOutputsPath);
690+
});
653691
});
654692

655693
describe('IntegTest watchIntegTest', () => {

0 commit comments

Comments
 (0)