Skip to content

Commit e3d5491

Browse files
authored
chore(e2e tests): right trim stdout and stderr consistently (jestjs#10982)
1 parent 0c75d62 commit e3d5491

39 files changed

Lines changed: 352 additions & 329 deletions

ā€Že2e/Utils.tsā€Ž

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ export const sortLines = (output: string) =>
169169
.split('\n')
170170
.sort()
171171
.map(str => str.trim())
172-
.filter(Boolean)
173172
.join('\n');
174173

175174
const DEFAULT_PACKAGE_JSON: PackageJson = {
@@ -222,21 +221,20 @@ export const extractSummary = (stdout: string) => {
222221
const sortTests = (stdout: string) =>
223222
stdout
224223
.split('\n')
225-
.reduce((tests: Array<Array<string>>, line) => {
224+
.reduce<Array<Array<string>>>((tests, line) => {
226225
if (['RUNS', 'PASS', 'FAIL'].includes(line.slice(0, 4))) {
227-
tests.push([line.trimRight()]);
228-
} else if (line) {
229-
tests[tests.length - 1].push(line.trimRight());
226+
tests.push([line]);
227+
} else {
228+
tests[tests.length - 1].push(line);
230229
}
231230
return tests;
232231
}, [])
233232
.sort(([a], [b]) => (a > b ? 1 : -1))
234-
.reduce(
235-
(array, lines = []) =>
236-
lines.length > 1 ? array.concat(lines, '') : array.concat(lines),
237-
[],
233+
.map(strings =>
234+
strings.length > 1 ? `${strings.join('\n').trimRight()}\n` : strings[0],
238235
)
239-
.join('\n');
236+
.join('\n')
237+
.trim();
240238

241239
export const extractSortedSummary = (stdout: string) => {
242240
const {rest, summary} = extractSummary(stdout);
@@ -280,6 +278,17 @@ export const normalizeIcons = (str: string) => {
280278
.replace(new RegExp('\u221A', 'g'), '\u2713');
281279
};
282280

281+
export const rightTrimStdout = (str: string) => {
282+
if (!str) {
283+
return str;
284+
}
285+
286+
return str
287+
.split('\n')
288+
.map(str => str.trimRight())
289+
.join('\n');
290+
};
291+
283292
// Certain environments (like CITGM and GH Actions) do not come with mercurial installed
284293
let hgIsInstalled: boolean | null = null;
285294

ā€Že2e/__tests__/__snapshots__/asyncAndCallback.test.ts.snapā€Ž

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ FAIL __tests__/promise-and-callback.test.js
1212
Returned value: Promise {}
1313
1414
8 | 'use strict';
15-
9 |
15+
9 |
1616
> 10 | it('promise-returning test with callback', done => {
1717
| ^
1818
11 | done();
19-
12 |
19+
12 |
2020
13 | return Promise.resolve();
2121
2222
at Object.it (__tests__/promise-and-callback.test.js:10:1)
@@ -27,12 +27,12 @@ FAIL __tests__/promise-and-callback.test.js
2727
Returned value: Promise {}
2828
2929
14 | });
30-
15 |
30+
15 |
3131
> 16 | it('async test with callback', async done => {
3232
| ^
3333
17 | done();
3434
18 | });
35-
19 |
35+
19 |
3636
3737
at Object.it (__tests__/promise-and-callback.test.js:16:1)
3838
@@ -42,11 +42,11 @@ FAIL __tests__/promise-and-callback.test.js
4242
Returned value: "foobar"
4343
4444
18 | });
45-
19 |
45+
19 |
4646
> 20 | it('test done before return value', done => {
4747
| ^
4848
21 | done();
49-
22 |
49+
22 |
5050
23 | return 'foobar';
5151
5252
at Object.it (__tests__/promise-and-callback.test.js:20:1)

ā€Že2e/__tests__/__snapshots__/callDoneTwice.test.ts.snapā€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ FAIL __tests__/index.test.js
1111
> 10 | done();
1212
| ^
1313
11 | });
14-
12 |
14+
12 |
1515
13 | it('should fail inside a promise', done => {
1616
1717
at Object.done (__tests__/index.test.js:10:5)
@@ -39,7 +39,7 @@ FAIL __tests__/index.test.js
3939
> 26 | done();
4040
| ^
4141
27 | });
42-
28 |
42+
28 |
4343
29 | it('should fail', () => {
4444
4545
at Object.done (__tests__/index.test.js:26:5)
@@ -53,7 +53,7 @@ FAIL __tests__/index.test.js
5353
> 37 | done();
5454
| ^
5555
38 | });
56-
39 |
56+
39 |
5757
40 | it('should fail', () => {
5858
5959
at Object.done (__tests__/index.test.js:37:5)
@@ -67,7 +67,7 @@ FAIL __tests__/index.test.js
6767
> 48 | done();
6868
| ^
6969
49 | });
70-
50 |
70+
50 |
7171
51 | it('should fail', () => {
7272
7373
at done (__tests__/index.test.js:48:5)
@@ -82,7 +82,7 @@ FAIL __tests__/index.test.js
8282
> 59 | done();
8383
| ^
8484
60 | });
85-
61 |
85+
61 |
8686
62 | it('should fail', () => {
8787
8888
at done (__tests__/index.test.js:59:5)

ā€Že2e/__tests__/__snapshots__/chaiAssertionLibrary.ts.snapā€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ FAIL __tests__/chai_assertion.js
2424
> 13 | chai.expect('hello world').to.equal('hello sunshine');
2525
| ^
2626
14 | });
27-
15 |
27+
15 |
2828
16 | it('should', () => {
2929
3030
at Object.equal (__tests__/chai_assertion.js:13:35)
@@ -51,7 +51,7 @@ FAIL __tests__/chai_assertion.js
5151
> 20 | actualString.should.equal(expectedString);
5252
| ^
5353
21 | });
54-
22 |
54+
22 |
5555
23 | it('assert', () => {
5656
5757
at Object.equal (__tests__/chai_assertion.js:20:25)
@@ -73,13 +73,13 @@ FAIL __tests__/chai_assertion.js
7373
- hello sunshine
7474
+ hello world
7575
76-
22 |
76+
22 |
7777
23 | it('assert', () => {
7878
> 24 | chai.assert.strictEqual('hello world', 'hello sunshine');
7979
| ^
8080
25 | });
8181
26 | });
82-
27 |
82+
27 |
8383
8484
at Object.strictEqual (__tests__/chai_assertion.js:24:17)
8585
`;

ā€Že2e/__tests__/__snapshots__/circusDeclarationErrors.test.ts.snapā€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ FAIL __tests__/asyncDefinition.test.js
88
99
Cannot add a test after tests have started running. Tests must be defined synchronously.
1010
11-
10 |
11+
10 |
1212
11 | Promise.resolve().then(() => {
1313
> 12 | test('async definition inside describe', () => {});
1414
| ^
@@ -29,7 +29,7 @@ FAIL __tests__/asyncDefinition.test.js
2929
| ^
3030
14 | });
3131
15 | });
32-
16 |
32+
16 |
3333
3434
at eventHandler (../../packages/jest-circus/build/eventHandler.js:114:11)
3535
at afterAll (__tests__/asyncDefinition.test.js:13:5)
@@ -38,13 +38,13 @@ FAIL __tests__/asyncDefinition.test.js
3838
3939
Cannot add a test after tests have started running. Tests must be defined synchronously.
4040
41-
16 |
41+
16 |
4242
17 | Promise.resolve().then(() => {
4343
> 18 | test('async definition outside describe', () => {});
4444
| ^
4545
19 | afterAll(() => {});
4646
20 | });
47-
21 |
47+
21 |
4848
4949
at eventHandler (../../packages/jest-circus/build/eventHandler.js:146:11)
5050
at test (__tests__/asyncDefinition.test.js:18:3)
@@ -58,7 +58,7 @@ FAIL __tests__/asyncDefinition.test.js
5858
> 19 | afterAll(() => {});
5959
| ^
6060
20 | });
61-
21 |
61+
21 |
6262
6363
at eventHandler (../../packages/jest-circus/build/eventHandler.js:114:11)
6464
at afterAll (__tests__/asyncDefinition.test.js:19:3)

ā€Že2e/__tests__/__snapshots__/console.test.ts.snapā€Ž

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ PASS __tests__/console.test.js
1818
This is a warning message.
1919
2020
12 | console.info('This is an info message.');
21-
13 |
21+
13 |
2222
> 14 | console.warn('This is a warning message.');
2323
| ^
24-
15 |
24+
15 |
2525
16 | console.error('This is an error message.');
2626
17 | });
2727
@@ -31,11 +31,11 @@ PASS __tests__/console.test.js
3131
This is an error message.
3232
3333
14 | console.warn('This is a warning message.');
34-
15 |
34+
15 |
3535
> 16 | console.error('This is an error message.');
3636
| ^
3737
17 | });
38-
18 |
38+
18 |
3939
4040
at Object.error (__tests__/console.test.js:16:11)
4141
`;
@@ -63,10 +63,10 @@ exports[`console printing with --verbose 1`] = `
6363
This is a warning message.
6464
6565
12 | console.info('This is an info message.');
66-
13 |
66+
13 |
6767
> 14 | console.warn('This is a warning message.');
6868
| ^
69-
15 |
69+
15 |
7070
16 | console.error('This is an error message.');
7171
17 | });
7272
@@ -76,11 +76,11 @@ exports[`console printing with --verbose 1`] = `
7676
This is an error message.
7777
7878
14 | console.warn('This is a warning message.');
79-
15 |
79+
15 |
8080
> 16 | console.error('This is an error message.');
8181
| ^
8282
17 | });
83-
18 |
83+
18 |
8484
8585
at Object.error (__tests__/console.test.js:16:11)
8686

ā€Že2e/__tests__/__snapshots__/consoleAfterTeardown.test.ts.snapā€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ PASS __tests__/console.test.js
1313
| ^
1414
13 | });
1515
14 | });
16-
15 |
16+
15 |
1717
`;

ā€Že2e/__tests__/__snapshots__/coverageHandlebars.test.ts.snapā€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
exports[`code coverage for Handlebars 1`] = `
44
-----------|---------|----------|---------|---------|-------------------
5-
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
5+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
66
-----------|---------|----------|---------|---------|-------------------
7-
All files | 75 | 66.67 | 66.67 | 66.67 |
8-
greet.hbs | 75 | 66.67 | 66.67 | 66.67 | 10
7+
All files | 75 | 66.67 | 66.67 | 66.67 |
8+
greet.hbs | 75 | 66.67 | 66.67 | 66.67 | 10
99
-----------|---------|----------|---------|---------|-------------------
1010
`;

0 commit comments

Comments
Ā (0)
⚔