|
| 1 | +import { execSync } from 'child_process'; |
1 | 2 | import * as os from 'os';
|
2 | 3 | import * as path from 'path';
|
3 | 4 | import { testDeprecated } from '@aws-cdk/cdk-build-tools';
|
@@ -610,13 +611,13 @@ describe('staging', () => {
|
610 | 611 | image: DockerImage.fromRegistry('alpine'),
|
611 | 612 | command: [DockerStubCommand.FAIL],
|
612 | 613 | },
|
613 |
| - })).toThrow(/Failed.*bundl.*asset.*-error/); |
| 614 | + })).toThrow(/Failed.*bundl.*asset.*-building/); |
614 | 615 |
|
615 | 616 | // THEN
|
616 | 617 | const assembly = app.synth();
|
617 | 618 |
|
618 | 619 | const dir = fs.readdirSync(assembly.directory);
|
619 |
| - expect(dir.some(entry => entry.match(/asset.*-error/))).toEqual(true); |
| 620 | + expect(dir.some(entry => entry.match(/asset.*-building/))).toEqual(true); |
620 | 621 | });
|
621 | 622 |
|
622 | 623 | test('bundler re-uses assets from previous synths', () => {
|
@@ -675,6 +676,44 @@ describe('staging', () => {
|
675 | 676 | ]);
|
676 | 677 | });
|
677 | 678 |
|
| 679 | + test('if bundling is interrupted, target asset directory is not produced', () => { |
| 680 | + // GIVEN |
| 681 | + const TEST_OUTDIR = path.join(__dirname, 'cdk.out'); |
| 682 | + if (fs.existsSync(TEST_OUTDIR)) { |
| 683 | + fs.removeSync(TEST_OUTDIR); |
| 684 | + } |
| 685 | + |
| 686 | + // WHEN |
| 687 | + try { |
| 688 | + execSync(`npx ts-node ${__dirname}/app-that-is-interrupted-during-staging.ts`, { |
| 689 | + env: { |
| 690 | + ...process.env, |
| 691 | + CDK_OUTDIR: TEST_OUTDIR, |
| 692 | + }, |
| 693 | + }); |
| 694 | + throw new Error('We expected the above command to fail'); |
| 695 | + } catch (e) { |
| 696 | + // We expect the command to be terminated with a signal, which sometimes shows |
| 697 | + // as 'signal' is set to SIGTERM, and on some Linuxes as exitCode = 128 + 15 = 143 |
| 698 | + if (e.signal === 'SIGTERM' || e.status === 143) { |
| 699 | + // pass |
| 700 | + } else { |
| 701 | + throw e; |
| 702 | + } |
| 703 | + } |
| 704 | + |
| 705 | + // THEN |
| 706 | + const generatedFiles = fs.readdirSync(TEST_OUTDIR); |
| 707 | + // We expect a 'building' asset directory... |
| 708 | + expect(generatedFiles).toContainEqual( |
| 709 | + expect.stringMatching(/^asset\.[0-9a-f]+-building$/), |
| 710 | + ); |
| 711 | + // ...not a complete asset directory |
| 712 | + expect(generatedFiles).not.toContainEqual( |
| 713 | + expect.stringMatching(/^asset\.[0-9a-f]+$/), |
| 714 | + ); |
| 715 | + }); |
| 716 | + |
678 | 717 | test('bundler re-uses assets from previous synths, ignoring tokens', () => {
|
679 | 718 | // GIVEN
|
680 | 719 | const TEST_OUTDIR = path.join(__dirname, 'cdk.out');
|
|
0 commit comments