Skip to content

Commit

Permalink
chore(e2e tests): right trim stdout and stderr consistently (#10982)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Dec 28, 2020
1 parent 0c75d62 commit e3d5491
Show file tree
Hide file tree
Showing 39 changed files with 352 additions and 329 deletions.
29 changes: 19 additions & 10 deletions e2e/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ export const sortLines = (output: string) =>
.split('\n')
.sort()
.map(str => str.trim())
.filter(Boolean)
.join('\n');

const DEFAULT_PACKAGE_JSON: PackageJson = {
Expand Down Expand Up @@ -222,21 +221,20 @@ export const extractSummary = (stdout: string) => {
const sortTests = (stdout: string) =>
stdout
.split('\n')
.reduce((tests: Array<Array<string>>, line) => {
.reduce<Array<Array<string>>>((tests, line) => {
if (['RUNS', 'PASS', 'FAIL'].includes(line.slice(0, 4))) {
tests.push([line.trimRight()]);
} else if (line) {
tests[tests.length - 1].push(line.trimRight());
tests.push([line]);
} else {
tests[tests.length - 1].push(line);
}
return tests;
}, [])
.sort(([a], [b]) => (a > b ? 1 : -1))
.reduce(
(array, lines = []) =>
lines.length > 1 ? array.concat(lines, '') : array.concat(lines),
[],
.map(strings =>
strings.length > 1 ? `${strings.join('\n').trimRight()}\n` : strings[0],
)
.join('\n');
.join('\n')
.trim();

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

export const rightTrimStdout = (str: string) => {
if (!str) {
return str;
}

return str
.split('\n')
.map(str => str.trimRight())
.join('\n');
};

// Certain environments (like CITGM and GH Actions) do not come with mercurial installed
let hgIsInstalled: boolean | null = null;

Expand Down
12 changes: 6 additions & 6 deletions e2e/__tests__/__snapshots__/asyncAndCallback.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ FAIL __tests__/promise-and-callback.test.js
Returned value: Promise {}
8 | 'use strict';
9 |
9 |
> 10 | it('promise-returning test with callback', done => {
| ^
11 | done();
12 |
12 |
13 | return Promise.resolve();
at Object.it (__tests__/promise-and-callback.test.js:10:1)
Expand All @@ -27,12 +27,12 @@ FAIL __tests__/promise-and-callback.test.js
Returned value: Promise {}
14 | });
15 |
15 |
> 16 | it('async test with callback', async done => {
| ^
17 | done();
18 | });
19 |
19 |
at Object.it (__tests__/promise-and-callback.test.js:16:1)
Expand All @@ -42,11 +42,11 @@ FAIL __tests__/promise-and-callback.test.js
Returned value: "foobar"
18 | });
19 |
19 |
> 20 | it('test done before return value', done => {
| ^
21 | done();
22 |
22 |
23 | return 'foobar';
at Object.it (__tests__/promise-and-callback.test.js:20:1)
Expand Down
10 changes: 5 additions & 5 deletions e2e/__tests__/__snapshots__/callDoneTwice.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ FAIL __tests__/index.test.js
> 10 | done();
| ^
11 | });
12 |
12 |
13 | it('should fail inside a promise', done => {
at Object.done (__tests__/index.test.js:10:5)
Expand Down Expand Up @@ -39,7 +39,7 @@ FAIL __tests__/index.test.js
> 26 | done();
| ^
27 | });
28 |
28 |
29 | it('should fail', () => {
at Object.done (__tests__/index.test.js:26:5)
Expand All @@ -53,7 +53,7 @@ FAIL __tests__/index.test.js
> 37 | done();
| ^
38 | });
39 |
39 |
40 | it('should fail', () => {
at Object.done (__tests__/index.test.js:37:5)
Expand All @@ -67,7 +67,7 @@ FAIL __tests__/index.test.js
> 48 | done();
| ^
49 | });
50 |
50 |
51 | it('should fail', () => {
at done (__tests__/index.test.js:48:5)
Expand All @@ -82,7 +82,7 @@ FAIL __tests__/index.test.js
> 59 | done();
| ^
60 | });
61 |
61 |
62 | it('should fail', () => {
at done (__tests__/index.test.js:59:5)
Expand Down
8 changes: 4 additions & 4 deletions e2e/__tests__/__snapshots__/chaiAssertionLibrary.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ FAIL __tests__/chai_assertion.js
> 13 | chai.expect('hello world').to.equal('hello sunshine');
| ^
14 | });
15 |
15 |
16 | it('should', () => {
at Object.equal (__tests__/chai_assertion.js:13:35)
Expand All @@ -51,7 +51,7 @@ FAIL __tests__/chai_assertion.js
> 20 | actualString.should.equal(expectedString);
| ^
21 | });
22 |
22 |
23 | it('assert', () => {
at Object.equal (__tests__/chai_assertion.js:20:25)
Expand All @@ -73,13 +73,13 @@ FAIL __tests__/chai_assertion.js
- hello sunshine
+ hello world
22 |
22 |
23 | it('assert', () => {
> 24 | chai.assert.strictEqual('hello world', 'hello sunshine');
| ^
25 | });
26 | });
27 |
27 |
at Object.strictEqual (__tests__/chai_assertion.js:24:17)
`;
10 changes: 5 additions & 5 deletions e2e/__tests__/__snapshots__/circusDeclarationErrors.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FAIL __tests__/asyncDefinition.test.js
Cannot add a test after tests have started running. Tests must be defined synchronously.
10 |
10 |
11 | Promise.resolve().then(() => {
> 12 | test('async definition inside describe', () => {});
| ^
Expand All @@ -29,7 +29,7 @@ FAIL __tests__/asyncDefinition.test.js
| ^
14 | });
15 | });
16 |
16 |
at eventHandler (../../packages/jest-circus/build/eventHandler.js:114:11)
at afterAll (__tests__/asyncDefinition.test.js:13:5)
Expand All @@ -38,13 +38,13 @@ FAIL __tests__/asyncDefinition.test.js
Cannot add a test after tests have started running. Tests must be defined synchronously.
16 |
16 |
17 | Promise.resolve().then(() => {
> 18 | test('async definition outside describe', () => {});
| ^
19 | afterAll(() => {});
20 | });
21 |
21 |
at eventHandler (../../packages/jest-circus/build/eventHandler.js:146:11)
at test (__tests__/asyncDefinition.test.js:18:3)
Expand All @@ -58,7 +58,7 @@ FAIL __tests__/asyncDefinition.test.js
> 19 | afterAll(() => {});
| ^
20 | });
21 |
21 |
at eventHandler (../../packages/jest-circus/build/eventHandler.js:114:11)
at afterAll (__tests__/asyncDefinition.test.js:19:3)
Expand Down
16 changes: 8 additions & 8 deletions e2e/__tests__/__snapshots__/console.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ PASS __tests__/console.test.js
This is a warning message.
12 | console.info('This is an info message.');
13 |
13 |
> 14 | console.warn('This is a warning message.');
| ^
15 |
15 |
16 | console.error('This is an error message.');
17 | });
Expand All @@ -31,11 +31,11 @@ PASS __tests__/console.test.js
This is an error message.
14 | console.warn('This is a warning message.');
15 |
15 |
> 16 | console.error('This is an error message.');
| ^
17 | });
18 |
18 |
at Object.error (__tests__/console.test.js:16:11)
`;
Expand Down Expand Up @@ -63,10 +63,10 @@ exports[`console printing with --verbose 1`] = `
This is a warning message.
12 | console.info('This is an info message.');
13 |
13 |
> 14 | console.warn('This is a warning message.');
| ^
15 |
15 |
16 | console.error('This is an error message.');
17 | });
Expand All @@ -76,11 +76,11 @@ exports[`console printing with --verbose 1`] = `
This is an error message.
14 | console.warn('This is a warning message.');
15 |
15 |
> 16 | console.error('This is an error message.');
| ^
17 | });
18 |
18 |
at Object.error (__tests__/console.test.js:16:11)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ PASS __tests__/console.test.js
| ^
13 | });
14 | });
15 |
15 |
`;
6 changes: 3 additions & 3 deletions e2e/__tests__/__snapshots__/coverageHandlebars.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

exports[`code coverage for Handlebars 1`] = `
-----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------|---------|----------|---------|---------|-------------------
All files | 75 | 66.67 | 66.67 | 66.67 |
greet.hbs | 75 | 66.67 | 66.67 | 66.67 | 10
All files | 75 | 66.67 | 66.67 | 66.67 |
greet.hbs | 75 | 66.67 | 66.67 | 66.67 | 10
-----------|---------|----------|---------|---------|-------------------
`;
Loading

0 comments on commit e3d5491

Please sign in to comment.