Skip to content

Commit bb5b730

Browse files
authored
chore: fix ci=true integ tests (#21000)
`beforeEach()`/`afterEach()` do not work because of the crazy way we're doing parallelism in the CLI integ tests. Remove the mechanism, explain that it does not work. Also turn `warning()` logging into `stdout` so it doesn't fail builds on Azure. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 27160c3 commit bb5b730

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

packages/aws-cdk-lib/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@
560560
"./aws-ram": "./aws-ram/index.js",
561561
"./aws-rds": "./aws-rds/index.js",
562562
"./aws-redshift": "./aws-redshift/index.js",
563+
"./aws-redshiftserverless": "./aws-redshiftserverless/index.js",
563564
"./aws-refactorspaces": "./aws-refactorspaces/index.js",
564565
"./aws-rekognition": "./aws-rekognition/index.js",
565566
"./aws-resiliencehub": "./aws-resiliencehub/index.js",

packages/aws-cdk/CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ You can also run just these tests by executing:
8989
yarn integ-cli-no-regression
9090
```
9191

92+
##### Warning
93+
94+
Since the tests take a long time to run, we run them in parallel in order to minimize running time. Jest does not have
95+
good support for parallelism, the only thing that exists is `test.concurrent()` and it has a couple of limitations:
96+
97+
- It's not possible to only run a subset of tests, all tests will execute (the reason for this is that it will start all
98+
tests in parallel, but only `await` your selected subset specified with the `-t TESTNAME` option. However, all tests
99+
are running and Node will not exit until they're all finished).
100+
- It's not possible to use `beforeEach()` and `afterEach()`.
101+
102+
Because of the first limitation, concurrency is only enabled on the build server (via the `JEST_TEST_CONCURRENT`
103+
environment variable), not locally. Note: tests using `beforeEach()` will appear to work locally, but will fail on the
104+
build server! Don't use it!
105+
92106
#### Regression
93107

94108
Validate that previously tested functionality still works in light of recent changes to the CLI. This is done by fetching the functional tests of the previous published release, and running them against the new CLI code.

packages/aws-cdk/lib/logging.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import * as chalk from 'chalk';
55
type StyleFn = (str: string) => string;
66
const { stdout, stderr } = process;
77

8-
const logger = (stream: Writable, styles?: StyleFn[]) => (fmt: string, ...args: any[]) => {
8+
type WritableFactory = () => Writable;
9+
10+
const logger = (stream: Writable | WritableFactory, styles?: StyleFn[]) => (fmt: string, ...args: any[]) => {
911
let str = util.format(fmt, ...args);
1012
if (styles && styles.length) {
1113
str = styles.reduce((a, style) => style(a), str);
1214
}
13-
stream.write(str + '\n');
15+
16+
const realStream = typeof stream === 'function' ? stream() : stream;
17+
realStream.write(str + '\n');
1418
};
1519

1620
export enum LogLevel {
@@ -39,15 +43,15 @@ export function increaseVerbosity() {
3943
}
4044

4145
const stream = () => CI ? stdout : stderr;
42-
const _debug = (fmt: string, ...args: any) => logger(stream(), [chalk.gray])(fmt, ...args);
46+
const _debug = logger(stream, [chalk.gray]);
4347

4448
export const trace = (fmt: string, ...args: any) => logLevel >= LogLevel.TRACE && _debug(fmt, ...args);
4549
export const debug = (fmt: string, ...args: any[]) => logLevel >= LogLevel.DEBUG && _debug(fmt, ...args);
4650
export const error = logger(stderr, [chalk.red]);
47-
export const warning = logger(stderr, [chalk.yellow]);
48-
export const success = (fmt: string, ...args: any) => logger(stream(), [chalk.green])(fmt, ...args);
49-
export const highlight = (fmt: string, ...args: any) => logger(stream(), [chalk.bold])(fmt, ...args);
50-
export const print = (fmt: string, ...args: any) => logger(stream())(fmt, ...args);
51+
export const warning = logger(stream, [chalk.yellow]);
52+
export const success = logger(stream, [chalk.green]);
53+
export const highlight = logger(stream, [chalk.bold]);
54+
export const print = logger(stream);
5155
export const data = logger(stdout);
5256

5357
export type LoggerFunction = (fmt: string, ...args: any[]) => void;

packages/aws-cdk/test/integ/cli/cli.integtest.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ describe('ci', () => {
1818
expect(diffOutput).not.toEqual('');
1919
}));
2020
describe('ci=true', () => {
21-
beforeEach(() => {
22-
process.env.CI = 'true';
23-
});
24-
afterEach(() => {
25-
process.env.CI = undefined;
26-
});
2721
integTest('output to stdout', withDefaultFixture(async (fixture) => {
28-
const deployOutput = await fixture.cdkDeploy('test-2', { captureStderr: true, onlyStderr: true });
29-
const diffOutput = await fixture.cdk(['diff', fixture.fullStackName('test-2')], { captureStderr: true, onlyStderr: true });
30-
const destroyOutput = await fixture.cdkDestroy('test-2', { captureStderr: true, onlyStderr: true });
22+
23+
const execOptions = {
24+
captureStderr: true,
25+
onlyStderr: true,
26+
modEnv: { CI: 'true' },
27+
};
28+
29+
const deployOutput = await fixture.cdkDeploy('test-2', execOptions);
30+
const diffOutput = await fixture.cdk(['diff', fixture.fullStackName('test-2')], execOptions);
31+
const destroyOutput = await fixture.cdkDestroy('test-2', execOptions);
3132
expect(deployOutput).toEqual('');
3233
expect(destroyOutput).toEqual('');
3334
expect(diffOutput).toEqual('');

0 commit comments

Comments
 (0)