2021-06-07 03:09:53 +03:00
|
|
|
/**
|
|
|
|
* Copyright Microsoft Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as path from 'path';
|
|
|
|
import { test, expect } from './playwright-test-fixtures';
|
|
|
|
|
2021-06-17 02:05:30 +03:00
|
|
|
test('should work and remove non-failures', async ({ runInlineTest }, testInfo) => {
|
2021-06-07 03:09:53 +03:00
|
|
|
const result = await runInlineTest({
|
2021-06-17 02:05:30 +03:00
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = {
|
2021-07-23 19:04:20 +03:00
|
|
|
name: 'chromium',
|
2021-06-17 02:05:30 +03:00
|
|
|
preserveOutput: 'failures-only',
|
|
|
|
testDir: 'dir',
|
|
|
|
};
|
|
|
|
`,
|
2021-06-07 03:09:53 +03:00
|
|
|
'dir/my-test.spec.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
test('test 1', async ({}, testInfo) => {
|
|
|
|
if (testInfo.retry) {
|
2021-06-17 02:05:30 +03:00
|
|
|
expect(testInfo.outputDir).toContain('my-test-test-1-chromium-retry' + testInfo.retry);
|
|
|
|
expect(testInfo.outputPath('foo', 'bar')).toContain(require('path').join('my-test-test-1-chromium-retry' + testInfo.retry, 'foo', 'bar'));
|
2021-06-07 03:09:53 +03:00
|
|
|
require('fs').writeFileSync(testInfo.outputPath('file.txt'), 'content', 'utf-8');
|
|
|
|
} else {
|
2021-06-17 02:05:30 +03:00
|
|
|
expect(testInfo.outputDir).toContain('my-test-test-1-chromium');
|
|
|
|
expect(testInfo.outputPath()).toContain('my-test-test-1-chromium');
|
|
|
|
expect(testInfo.outputPath('foo', 'bar')).toContain(require('path').join('my-test-test-1-chromium', 'foo', 'bar'));
|
2021-06-07 03:09:53 +03:00
|
|
|
require('fs').writeFileSync(testInfo.outputPath('file.txt'), 'content', 'utf-8');
|
|
|
|
}
|
|
|
|
expect(require('fs').existsSync(testInfo.outputDir)).toBe(true);
|
|
|
|
if (testInfo.retry < 2)
|
|
|
|
throw new Error('Give me retries');
|
|
|
|
});
|
|
|
|
`,
|
2021-06-17 02:05:30 +03:00
|
|
|
}, { retries: 2 });
|
2021-06-07 03:09:53 +03:00
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
|
|
|
expect(result.results[0].status).toBe('failed');
|
|
|
|
expect(result.results[0].retry).toBe(0);
|
|
|
|
// Should only fail the last retry check.
|
|
|
|
expect(result.results[0].error.message).toBe('Give me retries');
|
|
|
|
|
|
|
|
expect(result.results[1].status).toBe('failed');
|
|
|
|
expect(result.results[1].retry).toBe(1);
|
|
|
|
// Should only fail the last retry check.
|
|
|
|
expect(result.results[1].error.message).toBe('Give me retries');
|
|
|
|
|
|
|
|
expect(result.results[2].status).toBe('passed');
|
|
|
|
expect(result.results[2].retry).toBe(2);
|
|
|
|
|
2021-06-17 02:05:30 +03:00
|
|
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'my-test-test-1-chromium'))).toBe(true);
|
|
|
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'my-test-test-1-chromium-retry1'))).toBe(true);
|
2022-02-01 22:09:41 +03:00
|
|
|
// Last retry is successful, so output dir should be removed.
|
2021-06-17 02:05:30 +03:00
|
|
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'my-test-test-1-chromium-retry2'))).toBe(false);
|
2021-06-07 03:09:53 +03:00
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
test('should include repeat token', async ({ runInlineTest }) => {
|
2021-06-07 03:09:53 +03:00
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.spec.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
test('test', ({}, testInfo) => {
|
|
|
|
if (testInfo.repeatEachIndex)
|
|
|
|
expect(testInfo.outputPath('')).toContain('repeat' + testInfo.repeatEachIndex);
|
|
|
|
else
|
|
|
|
expect(testInfo.outputPath('')).not.toContain('repeat' + testInfo.repeatEachIndex);
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { 'repeat-each': 3 });
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(3);
|
|
|
|
});
|
|
|
|
|
2022-03-24 02:05:49 +03:00
|
|
|
test('should default to package.json directory', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'foo/package.json': `{ "name": "foo" }`,
|
|
|
|
'foo/bar/playwright.config.js': `
|
|
|
|
module.exports = { projects: [ {} ] };
|
|
|
|
`,
|
|
|
|
'foo/bar/baz/tests/a.spec.js': `
|
|
|
|
const { test } = pwt;
|
|
|
|
const fs = require('fs');
|
|
|
|
test('pass', ({}, testInfo) => {
|
|
|
|
expect(process.cwd()).toBe(__dirname);
|
|
|
|
fs.writeFileSync(testInfo.outputPath('foo.ts'), 'foobar');
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { 'reporter': '' }, {}, {
|
|
|
|
cwd: 'foo/bar/baz/tests',
|
|
|
|
usesCustomOutputDir: true
|
|
|
|
});
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
expect(fs.existsSync(testInfo.outputPath('test-results'))).toBe(false);
|
|
|
|
expect(fs.existsSync(testInfo.outputPath('foo', 'test-results'))).toBe(true);
|
|
|
|
expect(fs.existsSync(testInfo.outputPath('foo', 'bar', 'test-results'))).toBe(false);
|
|
|
|
expect(fs.existsSync(testInfo.outputPath('foo', 'bar', 'baz', 'tests', 'test-results'))).toBe(false);
|
|
|
|
});
|
|
|
|
|
2022-03-09 03:35:14 +03:00
|
|
|
test('should be unique for beforeAll hook from different workers', async ({ runInlineTest }, testInfo) => {
|
2021-09-01 23:41:35 +03:00
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.spec.js': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test.beforeAll(({}, testInfo) => {
|
|
|
|
console.log('\\n%%' + testInfo.outputDir);
|
|
|
|
});
|
2022-03-09 03:35:14 +03:00
|
|
|
test('fails', ({}, testInfo) => {
|
|
|
|
expect(1).toBe(2);
|
2021-09-01 23:41:35 +03:00
|
|
|
});
|
2022-03-09 03:35:14 +03:00
|
|
|
test('passes', ({}, testInfo) => {
|
2021-09-01 23:41:35 +03:00
|
|
|
});
|
|
|
|
`
|
2022-03-09 03:35:14 +03:00
|
|
|
}, { retries: '1' });
|
2021-09-01 23:41:35 +03:00
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
expect(result.output.split('\n').filter(x => x.startsWith('%%'))).toEqual([
|
2022-03-09 03:35:14 +03:00
|
|
|
`%%${testInfo.outputPath('test-results', 'a-fails')}`,
|
|
|
|
`%%${testInfo.outputPath('test-results', 'a-fails-retry1')}`,
|
|
|
|
`%%${testInfo.outputPath('test-results', 'a-passes')}`,
|
2021-09-01 23:41:35 +03:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2021-06-07 03:09:53 +03:00
|
|
|
test('should include the project name', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'helper.ts': `
|
2021-06-07 08:07:07 +03:00
|
|
|
export const test = pwt.test.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
auto: [ async ({}, run, testInfo) => {
|
2021-08-10 04:09:11 +03:00
|
|
|
testInfo.snapshotSuffix = '';
|
2021-06-07 03:09:53 +03:00
|
|
|
await run();
|
|
|
|
}, { auto: true } ]
|
|
|
|
});
|
2021-06-07 08:07:07 +03:00
|
|
|
export const test2 = pwt.test.extend({
|
2021-06-07 03:09:53 +03:00
|
|
|
auto: [ async ({}, run, testInfo) => {
|
|
|
|
testInfo.snapshotSuffix = 'suffix';
|
|
|
|
await run();
|
|
|
|
}, { auto: true } ]
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { projects: [
|
|
|
|
{},
|
|
|
|
{ name: 'foo' },
|
|
|
|
{ name: 'foo' },
|
|
|
|
{ name: 'Bar space!' },
|
|
|
|
] };
|
|
|
|
`,
|
|
|
|
'my-test.spec.js': `
|
|
|
|
const { test, test2 } = require('./helper');
|
|
|
|
test('test 1', async ({}, testInfo) => {
|
|
|
|
console.log(testInfo.outputPath('bar.txt').replace(/\\\\/g, '/'));
|
|
|
|
console.log(testInfo.snapshotPath('bar.txt').replace(/\\\\/g, '/'));
|
|
|
|
if (testInfo.retry !== 1)
|
|
|
|
throw new Error('Give me a retry');
|
|
|
|
});
|
|
|
|
test2('test 2', async ({}, testInfo) => {
|
|
|
|
console.log(testInfo.outputPath('bar.txt').replace(/\\\\/g, '/'));
|
|
|
|
console.log(testInfo.snapshotPath('bar.txt').replace(/\\\\/g, '/'));
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { retries: 1 });
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.results[0].status).toBe('failed');
|
|
|
|
expect(result.results[1].status).toBe('passed');
|
|
|
|
|
|
|
|
// test1, run with empty
|
|
|
|
expect(result.output).toContain('test-results/my-test-test-1/bar.txt');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/bar.txt');
|
|
|
|
expect(result.output).toContain('test-results/my-test-test-1-retry1/bar.txt');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/bar.txt');
|
|
|
|
|
|
|
|
// test1, run with foo #1
|
|
|
|
expect(result.output).toContain('test-results/my-test-test-1-foo1/bar.txt');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/bar-foo.txt');
|
|
|
|
expect(result.output).toContain('test-results/my-test-test-1-foo1-retry1/bar.txt');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/bar-foo.txt');
|
|
|
|
|
|
|
|
// test1, run with foo #2
|
|
|
|
expect(result.output).toContain('test-results/my-test-test-1-foo2/bar.txt');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/bar-foo.txt');
|
|
|
|
expect(result.output).toContain('test-results/my-test-test-1-foo2-retry1/bar.txt');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/bar-foo.txt');
|
|
|
|
|
|
|
|
// test1, run with bar
|
|
|
|
expect(result.output).toContain('test-results/my-test-test-1-Bar-space-/bar.txt');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/bar-Bar-space-.txt');
|
|
|
|
expect(result.output).toContain('test-results/my-test-test-1-Bar-space--retry1/bar.txt');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/bar-Bar-space-.txt');
|
|
|
|
|
|
|
|
// test2, run with empty
|
|
|
|
expect(result.output).toContain('test-results/my-test-test-2/bar.txt');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/bar-suffix.txt');
|
|
|
|
|
|
|
|
// test2, run with foo #1
|
|
|
|
expect(result.output).toContain('test-results/my-test-test-2-foo1/bar.txt');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/bar-foo-suffix.txt');
|
|
|
|
|
|
|
|
// test2, run with foo #2
|
|
|
|
expect(result.output).toContain('test-results/my-test-test-2-foo2/bar.txt');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/bar-foo-suffix.txt');
|
|
|
|
|
|
|
|
// test2, run with bar
|
|
|
|
expect(result.output).toContain('test-results/my-test-test-2-Bar-space-/bar.txt');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/bar-Bar-space--suffix.txt');
|
|
|
|
});
|
|
|
|
|
2021-10-01 19:15:44 +03:00
|
|
|
test('should include path option in snapshot', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'helper.ts': `
|
|
|
|
export const test = pwt.test.extend({
|
|
|
|
auto: [ async ({}, run, testInfo) => {
|
|
|
|
testInfo.snapshotSuffix = 'suffix';
|
|
|
|
await run();
|
|
|
|
}, { auto: true } ]
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { projects: [
|
|
|
|
{ name: 'foo' },
|
|
|
|
] };
|
|
|
|
`,
|
|
|
|
'my-test.spec.js': `
|
|
|
|
const { test } = require('./helper');
|
|
|
|
test('test with path', async ({}, testInfo) => {
|
|
|
|
console.log(testInfo.snapshotPath('test', 'path', 'bar.txt').replace(/\\\\/g, '/'));
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.results[0].status).toBe('passed');
|
|
|
|
expect(result.output).toContain('my-test.spec.js-snapshots/test/path/bar-foo-suffix.txt');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should error if snapshotPath is resolved to outside of parent', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'helper.ts': `
|
|
|
|
export const test = pwt.test.extend({
|
|
|
|
auto: [ async ({}, run, testInfo) => {
|
|
|
|
testInfo.snapshotSuffix = 'suffix';
|
|
|
|
await run();
|
|
|
|
}, { auto: true } ]
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { projects: [
|
|
|
|
{ name: 'foo' },
|
|
|
|
] };
|
|
|
|
`,
|
|
|
|
'my-test.spec.js': `
|
|
|
|
const { test } = require('./helper');
|
|
|
|
test('test with parent path', async ({}, testInfo) => {
|
|
|
|
console.log(testInfo.snapshotPath('..', 'test', 'path', 'bar.txt').replace(/\\\\/g, '/'));
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
expect(result.results[0].status).toBe('failed');
|
|
|
|
expect(result.output).toContain('The snapshotPath is not allowed outside of the parent directory. Please fix the defined path.');
|
|
|
|
const badPath = path.join('..', 'test', 'path', 'bar-foo-suffix.txt');
|
|
|
|
expect(result.output).toContain(`snapshotPath: ${badPath}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should error if outputPath is resolved to outside of parent', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'helper.ts': `
|
|
|
|
export const test = pwt.test.extend({
|
|
|
|
auto: [ async ({}, run, testInfo) => {
|
|
|
|
testInfo.snapshotSuffix = 'suffix';
|
|
|
|
await run();
|
|
|
|
}, { auto: true } ]
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { projects: [
|
|
|
|
{ name: 'foo' },
|
|
|
|
] };
|
|
|
|
`,
|
|
|
|
'my-test.spec.js': `
|
|
|
|
const { test } = require('./helper');
|
|
|
|
test('test with parent path', async ({}, testInfo) => {
|
|
|
|
console.log(testInfo.outputPath('..', 'test', 'path', 'bar-test').replace(/\\\\/g, '/'));
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
expect(result.results[0].status).toBe('failed');
|
|
|
|
expect(result.output).toContain('The outputPath is not allowed outside of the parent directory. Please fix the defined path.');
|
|
|
|
const badPath = path.join('..', 'test', 'path', 'bar-test');
|
|
|
|
expect(result.output).toContain(`outputPath: ${badPath}`);
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
test('should remove output dirs for projects run', async ({ runInlineTest }, testInfo) => {
|
2021-06-07 03:09:53 +03:00
|
|
|
const paths: string[] = [];
|
|
|
|
const files: string[] = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
|
const p = testInfo.outputPath('path' + i);
|
|
|
|
await fs.promises.mkdir(p, { recursive: true });
|
|
|
|
const f = path.join(p, 'my-file.txt');
|
|
|
|
await fs.promises.writeFile(f, 'contents', 'utf-8');
|
|
|
|
paths.push(p);
|
|
|
|
files.push(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.js': `
|
|
|
|
module.exports = { projects: [
|
|
|
|
{ outputDir: ${JSON.stringify(paths[0])} },
|
|
|
|
{ outputDir: ${JSON.stringify(paths[2])} },
|
|
|
|
] };
|
|
|
|
`,
|
|
|
|
'a.test.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
test('my test', ({}, testInfo) => {});
|
|
|
|
`
|
|
|
|
}, { output: '' });
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(2);
|
|
|
|
|
|
|
|
expect(fs.existsSync(files[0])).toBe(false);
|
|
|
|
expect(fs.existsSync(files[1])).toBe(true);
|
|
|
|
expect(fs.existsSync(files[2])).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should remove folders with preserveOutput=never', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
export default { preserveOutput: 'never' };
|
|
|
|
`,
|
|
|
|
'dir/my-test.spec.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
test('test 1', async ({}, testInfo) => {
|
|
|
|
require('fs').writeFileSync(testInfo.outputPath('file.txt'), 'content', 'utf-8');
|
|
|
|
if (testInfo.retry < 2)
|
|
|
|
throw new Error('Give me retries');
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { retries: 2 });
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.results.length).toBe(3);
|
|
|
|
|
|
|
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'dir-my-test-test-1'))).toBe(false);
|
|
|
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'dir-my-test-test-1-retry1'))).toBe(false);
|
|
|
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'dir-my-test-test-1-retry2'))).toBe(false);
|
|
|
|
});
|
|
|
|
|
2021-06-16 17:51:54 +03:00
|
|
|
test('should preserve failed results', async ({ runInlineTest }, testInfo) => {
|
2021-06-07 03:09:53 +03:00
|
|
|
const result = await runInlineTest({
|
|
|
|
'dir/my-test.spec.js': `
|
2021-06-07 08:07:07 +03:00
|
|
|
const { test } = pwt;
|
2021-06-07 03:09:53 +03:00
|
|
|
test('test 1', async ({}, testInfo) => {
|
|
|
|
require('fs').writeFileSync(testInfo.outputPath('file.txt'), 'content', 'utf-8');
|
|
|
|
if (testInfo.retry < 2)
|
|
|
|
throw new Error('Give me retries');
|
|
|
|
});
|
|
|
|
`,
|
2021-06-16 17:51:54 +03:00
|
|
|
}, { 'retries': 2 });
|
2021-06-07 03:09:53 +03:00
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.results.length).toBe(3);
|
|
|
|
|
|
|
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'dir-my-test-test-1'))).toBe(true);
|
|
|
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'dir-my-test-test-1-retry1'))).toBe(true);
|
|
|
|
});
|
2021-06-15 23:39:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
test('should accept a relative path for outputDir', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'my-test.spec.js': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('test', async ({}, testInfo) => {
|
|
|
|
expect(testInfo.outputDir).toBe(${JSON.stringify(path.join(testInfo.outputDir, './my-output-dir', 'my-test-test'))});
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
'playwright.config.js': `
|
|
|
|
module.exports = { projects: [
|
|
|
|
{ outputDir: './my-output-dir' },
|
|
|
|
] };
|
|
|
|
`,
|
2021-09-21 03:17:12 +03:00
|
|
|
}, {}, {}, { usesCustomOutputDir: true });
|
2021-06-15 23:39:07 +03:00
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
});
|
2021-08-11 07:24:35 +03:00
|
|
|
|
2021-10-08 10:20:41 +03:00
|
|
|
test('should have output dir based on rootDir (cwd)', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.js': `
|
|
|
|
const path = require('path');
|
|
|
|
module.exports = {
|
|
|
|
testDir: path.join(__dirname, 'e2e'),
|
|
|
|
outputDir: 'test-results/',
|
|
|
|
};`,
|
|
|
|
'e2e/example.spec.js': `
|
|
|
|
const { test } = pwt;
|
|
|
|
const fs = require('fs');
|
|
|
|
test('hello world', async ({ }, testInfo) => {
|
|
|
|
fs.writeFileSync(testInfo.outputPath('foo.txt'), 'hello');
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, {}, {}, { usesCustomOutputDir: true });
|
|
|
|
expect(result.exitCode).toBe(0);
|
2021-10-09 01:12:17 +03:00
|
|
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'example-hello-world', 'foo.txt'))).toBe(true);
|
2021-10-08 10:20:41 +03:00
|
|
|
});
|
|
|
|
|
2021-08-11 07:24:35 +03:00
|
|
|
|
|
|
|
test('should allow nonAscii characters in the output dir', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'my-test.spec.js': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('こんにちは世界', async ({}, testInfo) => {
|
|
|
|
console.log('\\n%%' + testInfo.outputDir);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
const outputDir = result.output.split('\n').filter(x => x.startsWith('%%'))[0].slice('%%'.length);
|
|
|
|
expect(outputDir).toBe(path.join(testInfo.outputDir, 'test-results', 'my-test-こんにちは世界'));
|
|
|
|
});
|
2021-08-24 17:33:40 +03:00
|
|
|
|
2021-12-13 21:56:03 +03:00
|
|
|
test('should allow shorten long output dirs characters in the output dir', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
2022-02-19 02:40:36 +03:00
|
|
|
'very/deep/and/long/file/name/that/i/want/to/be/trimmed/my-test.spec.js': `
|
2021-12-13 21:56:03 +03:00
|
|
|
const { test } = pwt;
|
|
|
|
test.describe('this is a really long description that would be too long for a file path', () => {
|
|
|
|
test('and this is an even longer test name that just keeps going and going and we should shorten it', async ({}, testInfo) => {
|
|
|
|
console.log('\\n%%' + testInfo.outputDir);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
const outputDir = result.output.split('\n').filter(x => x.startsWith('%%'))[0].slice('%%'.length);
|
2022-02-19 02:40:36 +03:00
|
|
|
expect(outputDir).toBe(path.join(testInfo.outputDir, 'test-results', 'very-deep-and-long-file-name-that-i-want-to-be-99202--keeps-going-and-going-and-we-should-shorten-it'));
|
2021-12-13 21:56:03 +03:00
|
|
|
});
|
|
|
|
|
2021-11-25 03:36:38 +03:00
|
|
|
test('should not mangle double dashes', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'my--file.spec.js': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('my--test', async ({}, testInfo) => {
|
|
|
|
console.log('\\n%%' + testInfo.outputDir);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
const outputDir = result.output.split('\n').filter(x => x.startsWith('%%'))[0].slice('%%'.length);
|
|
|
|
expect(outputDir).toBe(path.join(testInfo.outputDir, 'test-results', 'my--file-my--test'));
|
|
|
|
});
|
|
|
|
|
2021-08-24 17:33:40 +03:00
|
|
|
test('should allow include the describe name the output dir', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'my-test.spec.js': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test.describe('hello', () => {
|
|
|
|
test('world', async ({}, testInfo) => {
|
|
|
|
console.log('\\n%%' + testInfo.outputDir);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
const outputDir = result.output.split('\n').filter(x => x.startsWith('%%'))[0].slice('%%'.length);
|
|
|
|
expect(outputDir).toBe(path.join(testInfo.outputDir, 'test-results', 'my-test-hello-world'));
|
|
|
|
});
|