2021-06-07 03:09:53 +03: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-02-01 04:14:59 +03:00
|
|
|
|
import { test, expect, stripAnsi } from './playwright-test-fixtures';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
|
2022-03-23 13:48:05 +03:00
|
|
|
|
const DOES_NOT_SUPPORT_UTF8_IN_TERMINAL = process.platform === 'win32' && process.env.TERM_PROGRAM !== 'vscode' && !process.env.WT_SESSION;
|
|
|
|
|
const POSITIVE_STATUS_MARK = DOES_NOT_SUPPORT_UTF8_IN_TERMINAL ? 'ok' : '✓ ';
|
|
|
|
|
const NEGATIVE_STATUS_MARK = DOES_NOT_SUPPORT_UTF8_IN_TERMINAL ? 'x ' : '✘ ';
|
|
|
|
|
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('render each test with project name', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { projects: [
|
|
|
|
|
{ name: 'foo' },
|
|
|
|
|
{ name: 'bar' },
|
|
|
|
|
] };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
2021-06-07 08:07:07 +03:00
|
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
|
test('fails', async ({}) => {
|
|
|
|
|
expect(1).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
test('passes', async ({}) => {
|
|
|
|
|
expect(0).toBe(0);
|
|
|
|
|
});
|
2021-08-12 02:44:19 +03:00
|
|
|
|
test.skip('skipped', async () => {
|
|
|
|
|
});
|
2021-06-07 03:09:53 +03:00
|
|
|
|
`,
|
2022-07-25 23:22:25 +03:00
|
|
|
|
}, { reporter: 'list', workers: '1' });
|
2022-02-01 04:14:59 +03:00
|
|
|
|
const text = stripAnsi(result.output);
|
2022-03-23 13:48:05 +03:00
|
|
|
|
|
2022-07-25 23:22:25 +03:00
|
|
|
|
expect(text).toContain(`${NEGATIVE_STATUS_MARK} 1 [foo] › a.test.ts:6:7 › fails`);
|
|
|
|
|
expect(text).toContain(`${POSITIVE_STATUS_MARK} 2 [foo] › a.test.ts:9:7 › passes`);
|
|
|
|
|
expect(text).toContain(`- 3 [foo] › a.test.ts:12:12 › skipped`);
|
|
|
|
|
expect(text).toContain(`${NEGATIVE_STATUS_MARK} 4 [bar] › a.test.ts:6:7 › fails`);
|
|
|
|
|
expect(text).toContain(`${POSITIVE_STATUS_MARK} 5 [bar] › a.test.ts:9:7 › passes`);
|
|
|
|
|
expect(text).toContain(`- 6 [bar] › a.test.ts:12:12 › skipped`);
|
2021-06-07 03:09:53 +03:00
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
});
|
2021-08-18 02:41:36 +03:00
|
|
|
|
|
|
|
|
|
test('render steps', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.ts': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('passes', async ({}) => {
|
|
|
|
|
await test.step('outer 1.0', async () => {
|
|
|
|
|
await test.step('inner 1.1', async () => {});
|
2022-10-25 01:54:53 +03:00
|
|
|
|
await test.step('inner 1.2', async () => {});
|
2021-08-18 02:41:36 +03:00
|
|
|
|
});
|
|
|
|
|
await test.step('outer 2.0', async () => {
|
|
|
|
|
await test.step('inner 2.1', async () => {});
|
2022-10-25 01:54:53 +03:00
|
|
|
|
await test.step('inner 2.2', async () => {});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'list' }, { PW_TEST_DEBUG_REPORTERS: '1', PW_TEST_DEBUG_REPORTERS_PRINT_STEPS: '1', PWTEST_TTY_WIDTH: '80' });
|
|
|
|
|
const text = stripAnsi(result.output);
|
|
|
|
|
const lines = text.split('\n').filter(l => l.match(/^\d :/)).map(l => l.replace(/\d+ms/, 'Xms'));
|
|
|
|
|
lines.pop(); // Remove last item that contains [v] and time in ms.
|
|
|
|
|
expect(lines).toEqual([
|
|
|
|
|
'0 : 1 a.test.ts:6:7 › passes',
|
|
|
|
|
'1 : 1.1 passes › outer 1.0',
|
|
|
|
|
'2 : 1.2 passes › outer 1.0 › inner 1.1',
|
|
|
|
|
'2 : 1.2 passes › outer 1.0 › inner 1.1 (Xms)',
|
|
|
|
|
'3 : 1.3 passes › outer 1.0 › inner 1.2',
|
|
|
|
|
'3 : 1.3 passes › outer 1.0 › inner 1.2 (Xms)',
|
|
|
|
|
'1 : 1.1 passes › outer 1.0 (Xms)',
|
|
|
|
|
'4 : 1.4 passes › outer 2.0',
|
|
|
|
|
'5 : 1.5 passes › outer 2.0 › inner 2.1',
|
|
|
|
|
'5 : 1.5 passes › outer 2.0 › inner 2.1 (Xms)',
|
|
|
|
|
'6 : 1.6 passes › outer 2.0 › inner 2.2',
|
|
|
|
|
'6 : 1.6 passes › outer 2.0 › inner 2.2 (Xms)',
|
|
|
|
|
'4 : 1.4 passes › outer 2.0 (Xms)',
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('render steps inlint', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.ts': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('passes', async ({}) => {
|
|
|
|
|
await test.step('outer 1.0', async () => {
|
|
|
|
|
await test.step('inner 1.1', async () => {});
|
|
|
|
|
await test.step('inner 1.2', async () => {});
|
|
|
|
|
});
|
|
|
|
|
await test.step('outer 2.0', async () => {
|
2021-08-18 02:41:36 +03:00
|
|
|
|
await test.step('inner 2.1', async () => {});
|
2022-10-25 01:54:53 +03:00
|
|
|
|
await test.step('inner 2.2', async () => {});
|
2021-08-18 02:41:36 +03:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
`,
|
2022-07-14 01:11:56 +03:00
|
|
|
|
}, { reporter: 'list' }, { PW_TEST_DEBUG_REPORTERS: '1', PWTEST_TTY_WIDTH: '80' });
|
2022-02-01 04:14:59 +03:00
|
|
|
|
const text = stripAnsi(result.output);
|
2022-10-25 01:54:53 +03:00
|
|
|
|
const lines = text.split('\n').filter(l => l.match(/^\d :/)).map(l => l.replace(/\d+ms/, 'Xms'));
|
2021-08-18 02:41:36 +03:00
|
|
|
|
lines.pop(); // Remove last item that contains [v] and time in ms.
|
|
|
|
|
expect(lines).toEqual([
|
2022-07-25 23:22:25 +03:00
|
|
|
|
'0 : 1 a.test.ts:6:7 › passes',
|
2022-10-25 01:54:53 +03:00
|
|
|
|
'0 : 1 a.test.ts:7:20 › passes › outer 1.0',
|
|
|
|
|
'0 : 1 a.test.ts:8:22 › passes › outer 1.0 › inner 1.1',
|
|
|
|
|
'0 : 1 a.test.ts:7:20 › passes › outer 1.0',
|
|
|
|
|
'0 : 1 a.test.ts:9:22 › passes › outer 1.0 › inner 1.2',
|
|
|
|
|
'0 : 1 a.test.ts:7:20 › passes › outer 1.0',
|
|
|
|
|
'0 : 1 a.test.ts:6:7 › passes',
|
|
|
|
|
'0 : 1 a.test.ts:11:20 › passes › outer 2.0',
|
|
|
|
|
'0 : 1 a.test.ts:12:22 › passes › outer 2.0 › inner 2.1',
|
|
|
|
|
'0 : 1 a.test.ts:11:20 › passes › outer 2.0',
|
|
|
|
|
'0 : 1 a.test.ts:13:22 › passes › outer 2.0 › inner 2.2',
|
|
|
|
|
'0 : 1 a.test.ts:11:20 › passes › outer 2.0',
|
2022-07-25 23:22:25 +03:00
|
|
|
|
'0 : 1 a.test.ts:6:7 › passes',
|
2021-08-18 02:41:36 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
2021-09-08 03:42:17 +03:00
|
|
|
|
|
2022-09-15 01:25:24 +03:00
|
|
|
|
test('very long console line should not mess terminal', async ({ runInlineTest }) => {
|
|
|
|
|
const TTY_WIDTH = 80;
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.ts': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('passes', async ({}) => {
|
|
|
|
|
console.log('a'.repeat(80) + 'b'.repeat(20));
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'list' }, { PWTEST_TTY_WIDTH: TTY_WIDTH + '' });
|
|
|
|
|
|
|
|
|
|
const renderedText = simpleAnsiRenderer(result.output, TTY_WIDTH);
|
|
|
|
|
if (process.platform === 'win32')
|
|
|
|
|
expect(renderedText).toContain(' ok 1 a.test.ts:6:7 › passes');
|
|
|
|
|
else
|
|
|
|
|
expect(renderedText).toContain(' ✓ 1 a.test.ts:6:7 › passes');
|
|
|
|
|
expect(renderedText).not.toContain(' 1 a.test.ts:6:7 › passes');
|
|
|
|
|
expect(renderedText).toContain('a'.repeat(80) + '\n' + 'b'.repeat(20));
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-18 08:07:04 +03:00
|
|
|
|
test('render retries', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.ts': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('flaky', async ({}, testInfo) => {
|
|
|
|
|
expect(testInfo.retry).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
`,
|
2022-07-14 01:11:56 +03:00
|
|
|
|
}, { reporter: 'list', retries: '1' }, { PW_TEST_DEBUG_REPORTERS: '1', PWTEST_TTY_WIDTH: '80' });
|
2022-02-01 04:14:59 +03:00
|
|
|
|
const text = stripAnsi(result.output);
|
2021-12-18 08:07:04 +03:00
|
|
|
|
const lines = text.split('\n').filter(l => l.startsWith('0 :') || l.startsWith('1 :')).map(l => l.replace(/[\dm]+s/, 'XXms'));
|
2022-03-23 13:48:05 +03:00
|
|
|
|
|
2021-12-18 08:07:04 +03:00
|
|
|
|
expect(lines).toEqual([
|
2022-10-25 01:54:53 +03:00
|
|
|
|
`0 : 1 a.test.ts:6:7 › flaky`,
|
2022-07-25 23:22:25 +03:00
|
|
|
|
`0 : ${NEGATIVE_STATUS_MARK} 1 a.test.ts:6:7 › flaky (XXms)`,
|
2022-10-25 01:54:53 +03:00
|
|
|
|
`1 : 2 a.test.ts:6:7 › flaky (retry #1)`,
|
2022-07-25 23:22:25 +03:00
|
|
|
|
`1 : ${POSITIVE_STATUS_MARK} 2 a.test.ts:6:7 › flaky (retry #1) (XXms)`,
|
2021-12-18 08:07:04 +03:00
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2021-09-08 03:42:17 +03:00
|
|
|
|
test('should truncate long test names', async ({ runInlineTest }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { projects: [
|
|
|
|
|
{ name: 'foo' },
|
|
|
|
|
] };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.ts': `
|
|
|
|
|
const { test } = pwt;
|
2022-06-23 03:03:54 +03:00
|
|
|
|
test('failure in very long name', async ({}) => {
|
2021-09-08 03:42:17 +03:00
|
|
|
|
expect(1).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
test('passes', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
test('passes 2 long name', async () => {
|
|
|
|
|
});
|
2021-12-18 00:08:02 +03:00
|
|
|
|
test.skip('skipped very long name', async () => {
|
2021-09-08 03:42:17 +03:00
|
|
|
|
});
|
|
|
|
|
`,
|
2022-07-14 01:11:56 +03:00
|
|
|
|
}, { reporter: 'list', retries: 0 }, { PWTEST_TTY_WIDTH: 50 });
|
2021-09-08 03:42:17 +03:00
|
|
|
|
expect(result.exitCode).toBe(1);
|
2022-07-01 06:24:00 +03:00
|
|
|
|
|
|
|
|
|
const lines = stripAnsi(result.output).split('\n').slice(3, 11);
|
|
|
|
|
expect(lines.every(line => line.length <= 50)).toBe(true);
|
|
|
|
|
|
2022-07-25 23:22:25 +03:00
|
|
|
|
expect(lines[0]).toBe(` 1 … a.test.ts:6:7 › failure in very long name`);
|
2022-07-01 06:24:00 +03:00
|
|
|
|
|
2022-07-25 23:22:25 +03:00
|
|
|
|
expect(lines[1]).toContain(`${NEGATIVE_STATUS_MARK} 1 …`);
|
|
|
|
|
expect(lines[1]).toContain(`:6:7 › failure in very long name (`);
|
2022-07-01 06:24:00 +03:00
|
|
|
|
expect(lines[1].length).toBe(50);
|
|
|
|
|
|
2022-07-25 23:22:25 +03:00
|
|
|
|
expect(lines[2]).toBe(` 2 [foo] › a.test.ts:9:7 › passes`);
|
2022-07-01 06:24:00 +03:00
|
|
|
|
|
2022-07-25 23:22:25 +03:00
|
|
|
|
expect(lines[3]).toContain(`${POSITIVE_STATUS_MARK} 2 [foo] › a.test.ts:9:7 › passes (`);
|
2022-07-01 06:24:00 +03:00
|
|
|
|
|
2022-07-25 23:22:25 +03:00
|
|
|
|
expect(lines[4]).toBe(` 3 [foo] › a.test.ts:11:7 › passes 2 long name`);
|
2022-07-01 06:24:00 +03:00
|
|
|
|
|
2022-07-25 23:22:25 +03:00
|
|
|
|
expect(lines[5]).toContain(`${POSITIVE_STATUS_MARK} 3 …`);
|
|
|
|
|
expect(lines[5]).toContain(`test.ts:11:7 › passes 2 long name (`);
|
2022-07-01 06:24:00 +03:00
|
|
|
|
expect(lines[5].length).toBe(50);
|
|
|
|
|
|
2022-07-25 23:22:25 +03:00
|
|
|
|
expect(lines[6]).toBe(` 4 …› a.test.ts:13:12 › skipped very long name`);
|
2022-07-01 06:24:00 +03:00
|
|
|
|
|
2022-07-25 23:22:25 +03:00
|
|
|
|
expect(lines[7]).toBe(` - 4 …› a.test.ts:13:12 › skipped very long name`);
|
2021-09-08 03:42:17 +03:00
|
|
|
|
});
|
2022-09-15 01:25:24 +03:00
|
|
|
|
|
|
|
|
|
function simpleAnsiRenderer(text, ttyWidth) {
|
|
|
|
|
let lineNumber = 0;
|
|
|
|
|
let columnNumber = 0;
|
2022-10-25 01:54:53 +03:00
|
|
|
|
const screenLines: string[][] = [];
|
2022-09-15 01:25:24 +03:00
|
|
|
|
const ensureScreenSize = () => {
|
|
|
|
|
if (lineNumber < 0)
|
|
|
|
|
throw new Error('Bad terminal navigation!');
|
|
|
|
|
while (lineNumber >= screenLines.length)
|
|
|
|
|
screenLines.push(new Array(ttyWidth).fill(''));
|
|
|
|
|
};
|
|
|
|
|
const print = ch => {
|
|
|
|
|
ensureScreenSize();
|
|
|
|
|
if (ch === '\n') {
|
|
|
|
|
columnNumber = 0;
|
|
|
|
|
++lineNumber;
|
|
|
|
|
} else {
|
|
|
|
|
screenLines[lineNumber][columnNumber++] = ch;
|
|
|
|
|
if (columnNumber === ttyWidth) {
|
|
|
|
|
columnNumber = 0;
|
|
|
|
|
++lineNumber;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ensureScreenSize();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let index = 0;
|
|
|
|
|
|
|
|
|
|
const ansiCodes = [...text.matchAll(/\u001B\[(\d*)(.)/g)];
|
|
|
|
|
for (const ansiCode of ansiCodes) {
|
|
|
|
|
const [matchText, codeValue, codeType] = ansiCode;
|
|
|
|
|
const code = (codeValue + codeType).toUpperCase();
|
|
|
|
|
while (index < ansiCode.index)
|
|
|
|
|
print(text[index++]);
|
|
|
|
|
if (codeType.toUpperCase() === 'E') {
|
|
|
|
|
// Go X lines down
|
|
|
|
|
lineNumber += +codeValue;
|
|
|
|
|
ensureScreenSize();
|
|
|
|
|
} else if (codeType.toUpperCase() === 'A') {
|
|
|
|
|
// Go X lines up
|
|
|
|
|
lineNumber -= +codeValue;
|
|
|
|
|
ensureScreenSize();
|
|
|
|
|
} else if (code === '2K') {
|
|
|
|
|
// Erase full line
|
|
|
|
|
ensureScreenSize();
|
|
|
|
|
screenLines[lineNumber] = new Array(ttyWidth).fill('');
|
|
|
|
|
} else if (code === '0G') {
|
|
|
|
|
// Go to start
|
|
|
|
|
columnNumber = 0;
|
|
|
|
|
} else {
|
|
|
|
|
// Unsupported ANSI code (e.g. all colors).
|
|
|
|
|
}
|
|
|
|
|
index += matchText.length;
|
|
|
|
|
}
|
|
|
|
|
while (index < text.length)
|
|
|
|
|
print(text[index++]);
|
|
|
|
|
|
|
|
|
|
return screenLines.map(line => line.join('')).join('\n');
|
|
|
|
|
}
|
|
|
|
|
|