feat(test runner): allow serial suites inside parallel (#14530)

Also works for `fullyParallel` mode.
This commit is contained in:
Dmitry Gozman 2022-05-31 15:24:20 -07:00 committed by GitHub
parent 2bcdf68ef5
commit a7500c18d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 9 deletions

View file

@ -668,9 +668,12 @@ function createTestGroups(rootSuite: Suite, workers: number): TestGroup[] {
}
let insideParallel = false;
let insideSerial = false;
let hasAllHooks = false;
for (let parent: Suite | undefined = test.parent; parent; parent = parent.parent) {
insideParallel = insideParallel || parent._parallelMode === 'parallel';
insideSerial = insideSerial || parent._parallelMode === 'serial';
// Serial cancels out any enclosing parallel.
insideParallel = insideParallel || (!insideSerial && parent._parallelMode === 'parallel');
hasAllHooks = hasAllHooks || parent._hooks.some(hook => hook.type === 'beforeAll' || hook.type === 'afterAll');
}

View file

@ -126,8 +126,6 @@ export class TestTypeImpl {
for (let parent: Suite | undefined = suite; parent; parent = parent.parent) {
if (parent._parallelMode === 'serial' && child._parallelMode === 'parallel')
throw errorWithLocation(location, 'describe.parallel cannot be nested inside describe.serial');
if (parent._parallelMode === 'parallel' && child._parallelMode === 'serial')
throw errorWithLocation(location, 'describe.serial cannot be nested inside describe.parallel');
}
setCurrentlyLoadingFileSuite(child);
@ -152,8 +150,6 @@ export class TestTypeImpl {
for (let parent: Suite | undefined = suite.parent; parent; parent = parent.parent) {
if (parent._parallelMode === 'serial' && suite._parallelMode === 'parallel')
throw errorWithLocation(location, 'describe.parallel cannot be nested inside describe.serial');
if (parent._parallelMode === 'parallel' && suite._parallelMode === 'serial')
throw errorWithLocation(location, 'describe.serial cannot be nested inside describe.parallel');
}
}

View file

@ -323,16 +323,55 @@ test('test.describe.serial should work with test.fail and retries', async ({ run
]);
});
test('test.describe.serial should throw inside test.describe.parallel', async ({ runInlineTest }) => {
test('test.describe.serial should work inside test.describe.parallel', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.ts': `
const { test } = pwt;
test.describe.parallel('parallel suite', () => {
test.describe.serial('serial suite', () => {
test('one', async ({}) => {
await new Promise(f => setTimeout(f, 1000));
console.log('\\n%%one');
});
test('two', async ({}) => {
await new Promise(f => setTimeout(f, 500));
console.log('\\n%%two');
});
});
});
`,
});
expect(result.exitCode).toBe(1);
expect(result.output).toContain('a.test.ts:7:23: describe.serial cannot be nested inside describe.parallel');
}, { workers: 2 });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(2);
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
'%%one',
'%%two',
]);
});
test('test.describe.serial should work with fullyParallel', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { fullyParallel: true };
`,
'a.test.ts': `
const { test } = pwt;
test.describe.serial('serial suite', () => {
test('one', async ({}) => {
await new Promise(f => setTimeout(f, 1000));
console.log('\\n%%one');
});
test('two', async ({}) => {
await new Promise(f => setTimeout(f, 500));
console.log('\\n%%two');
});
});
`,
}, { workers: 2 });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(2);
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
'%%one',
'%%two',
]);
});