some more
This commit is contained in:
parent
16536beed6
commit
d7b52fbed7
|
|
@ -137,14 +137,26 @@ function validateConfig(file: string, config: Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('globalSetup' in config && config.globalSetup !== undefined) {
|
if ('globalSetup' in config && config.globalSetup !== undefined) {
|
||||||
if (typeof config.globalSetup !== 'string')
|
if (Array.isArray(config.globalSetup)) {
|
||||||
|
config.globalSetup.forEach((item, index) => {
|
||||||
|
if (typeof item !== 'string')
|
||||||
|
throw errorWithFile(file, `config.globalSetup[${index}] must be a string`);
|
||||||
|
});
|
||||||
|
} else if (typeof config.globalSetup !== 'string') {
|
||||||
throw errorWithFile(file, `config.globalSetup must be a string`);
|
throw errorWithFile(file, `config.globalSetup must be a string`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ('globalTeardown' in config && config.globalTeardown !== undefined) {
|
if ('globalTeardown' in config && config.globalTeardown !== undefined) {
|
||||||
if (typeof config.globalTeardown !== 'string')
|
if (Array.isArray(config.globalTeardown)) {
|
||||||
|
config.globalTeardown.forEach((item, index) => {
|
||||||
|
if (typeof item !== 'string')
|
||||||
|
throw errorWithFile(file, `config.globalTeardown[${index}] must be a string`);
|
||||||
|
});
|
||||||
|
} else if (typeof config.globalTeardown !== 'string') {
|
||||||
throw errorWithFile(file, `config.globalTeardown must be a string`);
|
throw errorWithFile(file, `config.globalTeardown must be a string`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ('globalTimeout' in config && config.globalTimeout !== undefined) {
|
if ('globalTimeout' in config && config.globalTimeout !== undefined) {
|
||||||
if (typeof config.globalTimeout !== 'number' || config.globalTimeout < 0)
|
if (typeof config.globalTimeout !== 'number' || config.globalTimeout < 0)
|
||||||
|
|
|
||||||
|
|
@ -99,9 +99,8 @@ export function createGlobalSetupTasks(config: FullConfigInternal) {
|
||||||
tasks.push(createRemoveOutputDirsTask());
|
tasks.push(createRemoveOutputDirsTask());
|
||||||
tasks.push(...createPluginSetupTasks(config));
|
tasks.push(...createPluginSetupTasks(config));
|
||||||
if (config.globalSetups.length || config.globalTeardowns.length) {
|
if (config.globalSetups.length || config.globalTeardowns.length) {
|
||||||
const length = Math.max(config.globalSetups.length, config.globalTeardowns.length);
|
for (let i = 0; i < Math.max(config.globalSetups.length, config.globalTeardowns.length); i++)
|
||||||
for (let i = 0; i < length; i++)
|
tasks.push(createGlobalSetupTask(i, config));
|
||||||
tasks.push(createGlobalSetupTask(i, length));
|
|
||||||
}
|
}
|
||||||
return tasks;
|
return tasks;
|
||||||
}
|
}
|
||||||
|
|
@ -164,14 +163,19 @@ function createPluginBeginTask(plugin: TestRunnerPluginRegistration): Task<TestR
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function createGlobalSetupTask(index: number, length: number): Task<TestRun> {
|
function createGlobalSetupTask(index: number, config: FullConfigInternal): Task<TestRun> {
|
||||||
let globalSetupResult: any;
|
let globalSetupResult: any;
|
||||||
let globalSetupFinished = false;
|
let globalSetupFinished = false;
|
||||||
let teardownHook: any;
|
let teardownHook: any;
|
||||||
|
|
||||||
let title = 'global setup';
|
let title = 'global setup';
|
||||||
if (length > 1)
|
if (config.globalSetups.length > 1 || config.globalSetups.length > 1) {
|
||||||
title += ` (${index + 1}/${length})`;
|
const files = [
|
||||||
|
config.globalSetups[index],
|
||||||
|
config.globalTeardowns[index],
|
||||||
|
].filter(Boolean).join(', ');
|
||||||
|
title += ` (${files})`;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
|
|
|
||||||
|
|
@ -386,3 +386,44 @@ test('teardown after error', async ({ runInlineTest }) => {
|
||||||
'teardown 1',
|
'teardown 1',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function expectInOrder(output: string, tokens: string[]) {
|
||||||
|
for (const token of tokens)
|
||||||
|
expect(output).toContain(token);
|
||||||
|
|
||||||
|
const positions = tokens.map(token => `${output.indexOf(token).toString().padStart(3, '0')} ${token}`);
|
||||||
|
expect(positions, 'order is correct').toEqual(positions.toSorted());
|
||||||
|
}
|
||||||
|
|
||||||
|
test('globalSetup should support multiple', async ({ runInlineTest }) => {
|
||||||
|
const { passed, output } = await runInlineTest({
|
||||||
|
'playwright.config.ts': `
|
||||||
|
module.exports = {
|
||||||
|
globalSetup: ['./globalSetup1.ts','./globalSetup2.ts','./globalSetup3.ts'],
|
||||||
|
globalTeardown: ['./globalTeardown1.ts', './globalTeardown2.ts'],
|
||||||
|
};
|
||||||
|
`,
|
||||||
|
'globalSetup1.ts': `module.exports = () => console.log('globalSetup1');`,
|
||||||
|
'globalSetup2.ts': `module.exports = () => console.log('globalSetup2');`,
|
||||||
|
'globalSetup3.ts': `module.exports = () => console.log('globalSetup3');`,
|
||||||
|
'globalTeardown1.ts': `module.exports = () => console.log('globalTeardown1');`,
|
||||||
|
'globalTeardown2.ts': `module.exports = () => console.log('globalTeardown2');`,
|
||||||
|
|
||||||
|
'a.test.js': `
|
||||||
|
import { test } from '@playwright/test';
|
||||||
|
test('a', () => console.log('test a'));
|
||||||
|
test('b', () => console.log('test b'));
|
||||||
|
`,
|
||||||
|
}, { reporter: 'line' });
|
||||||
|
|
||||||
|
expect(passed).toBe(2);
|
||||||
|
expectInOrder(output, [
|
||||||
|
'globalSetup1',
|
||||||
|
'globalSetup2',
|
||||||
|
'globalSetup3',
|
||||||
|
'test a',
|
||||||
|
'test b',
|
||||||
|
'globalTeardown2',
|
||||||
|
'globalTeardown1',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue