2021-06-06 17:09:53 -07:00
|
|
|
|
/**
|
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-03-11 18:19:33 -08:00
|
|
|
|
import { test, expect, trimLineEnds, stripAnsi } from './playwright-test-fixtures';
|
2021-06-06 17:09:53 -07:00
|
|
|
|
|
2022-03-11 18:19:33 -08:00
|
|
|
|
test('should work with tty', async ({ runInlineTest }, testInfo) => {
|
2021-06-06 17:09:53 -07:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2021-06-06 22:07:07 -07:00
|
|
|
|
const { test } = pwt;
|
2022-03-11 18:19:33 -08:00
|
|
|
|
test('passing test', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
test.skip('skipped test', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
test('flaky test', async ({}, testInfo) => {
|
|
|
|
|
expect(testInfo.retry).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
test('failing test', async ({}) => {
|
2021-06-06 17:09:53 -07:00
|
|
|
|
expect(1).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
`,
|
2022-03-11 18:19:33 -08:00
|
|
|
|
}, { retries: '1', reporter: 'line', workers: '1' }, {
|
|
|
|
|
PLAYWRIGHT_LIVE_TERMINAL: '1',
|
|
|
|
|
FORCE_COLOR: '0',
|
|
|
|
|
PW_TEST_DEBUG_REPORTERS: '1',
|
|
|
|
|
});
|
2021-06-06 17:09:53 -07:00
|
|
|
|
expect(result.exitCode).toBe(1);
|
2022-03-11 18:19:33 -08:00
|
|
|
|
expect(trimLineEnds(result.output)).toContain(trimLineEnds(`Running 4 tests using 1 worker
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<lineup><erase><lineup><erase>a.test.js:6:7 › passing test
|
|
|
|
|
25% [1/4] Passed: 1 Flaky: 0 Failed: 0 Skipped: 0 (XXms)
|
|
|
|
|
<lineup><erase><lineup><erase>a.test.js:8:12 › skipped test
|
|
|
|
|
50% [2/4] Passed: 1 Flaky: 0 Failed: 0 Skipped: 1 (XXms)
|
|
|
|
|
<lineup><erase><lineup><erase>a.test.js:10:7 › flaky test
|
|
|
|
|
75% [3/4] Passed: 1 Flaky: 0 Failed: 0 Skipped: 1 (XXms)
|
|
|
|
|
<lineup><erase><lineup><erase>a.test.js:10:7 › flaky test (retry #1)
|
|
|
|
|
99% [4/4] (retries) Passed: 1 Flaky: 1 Failed: 0 Skipped: 1 (XXms)
|
|
|
|
|
<lineup><erase><lineup><erase> 1) a.test.js:10:7 › flaky test ===================================================================
|
|
|
|
|
|
|
|
|
|
Error: expect(received).toBe(expected) // Object.is equality
|
|
|
|
|
|
|
|
|
|
Expected: 1
|
|
|
|
|
Received: 0
|
|
|
|
|
|
|
|
|
|
9 | });
|
|
|
|
|
10 | test('flaky test', async ({}, testInfo) => {
|
|
|
|
|
> 11 | expect(testInfo.retry).toBe(1);
|
|
|
|
|
| ^
|
|
|
|
|
12 | });
|
|
|
|
|
13 | test('failing test', async ({}) => {
|
|
|
|
|
14 | expect(1).toBe(0);
|
|
|
|
|
|
|
|
|
|
at ${testInfo.outputPath('a.test.js')}:11:32
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<lineup><erase><lineup><erase>a.test.js:13:7 › failing test
|
|
|
|
|
99% [5/4] (retries) Passed: 1 Flaky: 1 Failed: 0 Skipped: 1 (XXms)
|
|
|
|
|
<lineup><erase><lineup><erase>a.test.js:13:7 › failing test (retry #1)
|
|
|
|
|
99% [6/4] (retries) Passed: 1 Flaky: 1 Failed: 1 Skipped: 1 (XXms)
|
|
|
|
|
<lineup><erase><lineup><erase> 2) a.test.js:13:7 › failing test =================================================================
|
|
|
|
|
|
|
|
|
|
Error: expect(received).toBe(expected) // Object.is equality
|
|
|
|
|
|
|
|
|
|
Expected: 0
|
|
|
|
|
Received: 1
|
|
|
|
|
|
|
|
|
|
12 | });
|
|
|
|
|
13 | test('failing test', async ({}) => {
|
|
|
|
|
> 14 | expect(1).toBe(0);
|
|
|
|
|
| ^
|
|
|
|
|
15 | });
|
|
|
|
|
16 |
|
|
|
|
|
|
|
|
|
|
at ${testInfo.outputPath('a.test.js')}:14:19
|
|
|
|
|
|
|
|
|
|
Retry #1 ---------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Error: expect(received).toBe(expected) // Object.is equality
|
|
|
|
|
|
|
|
|
|
Expected: 0
|
|
|
|
|
Received: 1
|
|
|
|
|
|
|
|
|
|
12 | });
|
|
|
|
|
13 | test('failing test', async ({}) => {
|
|
|
|
|
> 14 | expect(1).toBe(0);
|
|
|
|
|
| ^
|
|
|
|
|
15 | });
|
|
|
|
|
16 |
|
|
|
|
|
|
|
|
|
|
at ${testInfo.outputPath('a.test.js')}:14:19
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<lineup><erase><lineup><erase>
|
|
|
|
|
1 failed
|
|
|
|
|
a.test.js:13:7 › failing test ==================================================================
|
|
|
|
|
1 flaky
|
|
|
|
|
a.test.js:10:7 › flaky test ====================================================================
|
|
|
|
|
1 skipped
|
|
|
|
|
1 passed`));
|
2021-06-06 17:09:53 -07:00
|
|
|
|
});
|
|
|
|
|
|
2022-03-11 18:19:33 -08:00
|
|
|
|
test('should work with non-tty', async ({ runInlineTest }, testInfo) => {
|
2021-06-06 17:09:53 -07:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
2021-06-06 22:07:07 -07:00
|
|
|
|
const { test } = pwt;
|
2022-03-11 18:19:33 -08:00
|
|
|
|
test('passing test', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
test.skip('skipped test', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
test('flaky test', async ({}, testInfo) => {
|
|
|
|
|
expect(testInfo.retry).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
test('failing test', async ({}) => {
|
|
|
|
|
expect(1).toBe(0);
|
2021-06-06 17:09:53 -07:00
|
|
|
|
});
|
|
|
|
|
`,
|
2022-03-11 18:19:33 -08:00
|
|
|
|
}, { retries: '1', reporter: 'line', workers: '1' }, {
|
|
|
|
|
FORCE_COLOR: '0',
|
|
|
|
|
PW_TEST_DEBUG_REPORTERS: '1',
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(trimLineEnds(result.output)).toContain(trimLineEnds(`
|
|
|
|
|
Running 4 tests using 1 worker
|
|
|
|
|
25% [1/4] Passed: 1 Flaky: 0 Failed: 0 Skipped: 0 (XXms)
|
|
|
|
|
50% [2/4] Passed: 1 Flaky: 0 Failed: 0 Skipped: 1 (XXms)
|
|
|
|
|
75% [3/4] Passed: 1 Flaky: 0 Failed: 0 Skipped: 1 (XXms)
|
|
|
|
|
99% [4/4] (retries) Passed: 1 Flaky: 1 Failed: 0 Skipped: 1 (XXms)
|
|
|
|
|
1) a.test.js:10:7 › flaky test ===================================================================
|
|
|
|
|
|
|
|
|
|
Error: expect(received).toBe(expected) // Object.is equality
|
|
|
|
|
|
|
|
|
|
Expected: 1
|
|
|
|
|
Received: 0
|
|
|
|
|
|
|
|
|
|
9 | });
|
|
|
|
|
10 | test('flaky test', async ({}, testInfo) => {
|
|
|
|
|
> 11 | expect(testInfo.retry).toBe(1);
|
|
|
|
|
| ^
|
|
|
|
|
12 | });
|
|
|
|
|
13 | test('failing test', async ({}) => {
|
|
|
|
|
14 | expect(1).toBe(0);
|
|
|
|
|
|
|
|
|
|
at ${testInfo.outputPath('a.test.js')}:11:32
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2) a.test.js:13:7 › failing test =================================================================
|
|
|
|
|
|
|
|
|
|
Error: expect(received).toBe(expected) // Object.is equality
|
|
|
|
|
|
|
|
|
|
Expected: 0
|
|
|
|
|
Received: 1
|
|
|
|
|
|
|
|
|
|
12 | });
|
|
|
|
|
13 | test('failing test', async ({}) => {
|
|
|
|
|
> 14 | expect(1).toBe(0);
|
|
|
|
|
| ^
|
|
|
|
|
15 | });
|
|
|
|
|
16 |
|
|
|
|
|
|
|
|
|
|
at ${testInfo.outputPath('a.test.js')}:14:19
|
|
|
|
|
|
|
|
|
|
Retry #1 ---------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Error: expect(received).toBe(expected) // Object.is equality
|
|
|
|
|
|
|
|
|
|
Expected: 0
|
|
|
|
|
Received: 1
|
|
|
|
|
|
|
|
|
|
12 | });
|
|
|
|
|
13 | test('failing test', async ({}) => {
|
|
|
|
|
> 14 | expect(1).toBe(0);
|
|
|
|
|
| ^
|
|
|
|
|
15 | });
|
|
|
|
|
16 |
|
|
|
|
|
|
|
|
|
|
at ${testInfo.outputPath('a.test.js')}:14:19
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 failed
|
|
|
|
|
a.test.js:13:7 › failing test ==================================================================
|
|
|
|
|
1 flaky
|
|
|
|
|
a.test.js:10:7 › flaky test ====================================================================
|
|
|
|
|
1 skipped
|
|
|
|
|
1 passed`));
|
2021-06-06 17:09:53 -07:00
|
|
|
|
});
|
2021-08-19 18:20:53 -07:00
|
|
|
|
|
2022-03-11 18:19:33 -08:00
|
|
|
|
test('should respect tty width', async ({ runInlineTest }) => {
|
2021-08-19 18:20:53 -07:00
|
|
|
|
const result = await runInlineTest({
|
2022-03-11 18:19:33 -08:00
|
|
|
|
'a.test.js': `
|
2021-08-19 18:20:53 -07:00
|
|
|
|
const { test } = pwt;
|
2022-03-11 18:19:33 -08:00
|
|
|
|
test('passing test', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
test.skip('skipped test', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
test('flaky test', async ({}, testInfo) => {
|
2021-08-19 18:20:53 -07:00
|
|
|
|
expect(testInfo.retry).toBe(1);
|
|
|
|
|
});
|
2022-03-11 18:19:33 -08:00
|
|
|
|
test('failing test', async ({}) => {
|
|
|
|
|
expect(1).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { retries: '1', reporter: 'line', workers: '1' }, {
|
|
|
|
|
PLAYWRIGHT_LIVE_TERMINAL: '1',
|
|
|
|
|
FORCE_COLOR: '0',
|
|
|
|
|
PWTEST_TTY_WIDTH: '30',
|
|
|
|
|
PW_TEST_DEBUG_REPORTERS: '1',
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
const text = stripAnsi(result.output);
|
|
|
|
|
expect(text).toContain(`a.test.js:6:7 › passing test`);
|
|
|
|
|
expect(text).toContain(`25% [1/4] Passed: 1 Flaky: 0 F`);
|
|
|
|
|
expect(text).not.toContain(`25% [1/4] Passed: 1 Flaky: 0 Fa`);
|
|
|
|
|
expect(text).toContain(`a.test.js:10:7 › fl (retry #1)`);
|
|
|
|
|
expect(text).toContain(`99% [4/4] (retries) Passed: 1 `);
|
|
|
|
|
expect(text).not.toContain(`99% [4/4] (retries) Passed: 1 F`);
|
2021-08-19 18:20:53 -07:00
|
|
|
|
});
|
2022-02-11 08:33:56 -08:00
|
|
|
|
|
2022-03-11 18:19:33 -08:00
|
|
|
|
test('should spare status updates in non-tty mode', async ({ runInlineTest }) => {
|
2022-02-11 08:33:56 -08:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
2022-03-11 18:19:33 -08:00
|
|
|
|
for (let i = 0; i < 300; i++) {
|
|
|
|
|
test('test' + i, () => {});
|
|
|
|
|
}
|
2022-02-11 08:33:56 -08:00
|
|
|
|
`,
|
2022-03-11 18:19:33 -08:00
|
|
|
|
}, { reporter: 'line', workers: '1' }, {
|
|
|
|
|
FORCE_COLOR: '0',
|
|
|
|
|
PW_TEST_DEBUG_REPORTERS: '1',
|
|
|
|
|
});
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
const lines = [`Running 300 tests using 1 worker`, `0% [1/300] Passed: 1 Flaky: 0 Failed: 0 Skipped: 0 (XXms)`];
|
|
|
|
|
for (let i = 1; i <= 99; i++)
|
|
|
|
|
lines.push(`${i}% [${3 * i - 1}/300] Passed: ${3 * i - 1} Flaky: 0 Failed: 0 Skipped: 0 (XXms)`);
|
|
|
|
|
lines.push('');
|
|
|
|
|
lines.push(' 300 passed');
|
|
|
|
|
expect(trimLineEnds(result.output)).toContain(lines.join('\n'));
|
2022-02-11 08:33:56 -08:00
|
|
|
|
});
|