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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { test, expect } from './playwright-test-fixtures';
|
|
|
|
|
|
|
|
const tests = {
|
2021-08-11 02:32:32 +03:00
|
|
|
'helper.ts': `
|
|
|
|
export const headlessTest = pwt.test.extend({ headless: false });
|
|
|
|
export const headedTest = pwt.test.extend({ headless: true });
|
|
|
|
`,
|
2023-02-01 02:59:13 +03:00
|
|
|
'a1.spec.ts': `
|
2021-08-11 02:32:32 +03:00
|
|
|
import { headlessTest, headedTest } from './helper';
|
|
|
|
headlessTest('test1', async () => {
|
2021-06-07 03:09:53 +03:00
|
|
|
console.log('test1-done');
|
|
|
|
});
|
2023-02-01 02:59:13 +03:00
|
|
|
`,
|
|
|
|
'a2.spec.ts': `
|
|
|
|
import { headlessTest, headedTest } from './helper';
|
2021-08-11 02:32:32 +03:00
|
|
|
headedTest('test2', async () => {
|
|
|
|
console.log('test2-done');
|
2021-06-07 03:09:53 +03:00
|
|
|
});
|
2023-02-01 02:59:13 +03:00
|
|
|
`,
|
|
|
|
'a3.spec.ts': `
|
|
|
|
import { headlessTest, headedTest } from './helper';
|
2021-08-11 02:32:32 +03:00
|
|
|
headlessTest('test3', async () => {
|
2021-06-07 03:09:53 +03:00
|
|
|
console.log('test3-done');
|
|
|
|
});
|
|
|
|
`,
|
2023-02-01 02:59:13 +03:00
|
|
|
'b1.spec.ts': `
|
2021-08-11 02:32:32 +03:00
|
|
|
import { headlessTest, headedTest } from './helper';
|
|
|
|
headlessTest('test4', async () => {
|
2021-06-07 03:09:53 +03:00
|
|
|
console.log('test4-done');
|
|
|
|
});
|
2023-02-01 02:59:13 +03:00
|
|
|
`,
|
|
|
|
'b2.spec.ts': `
|
|
|
|
import { headlessTest, headedTest } from './helper';
|
2021-08-11 02:32:32 +03:00
|
|
|
headedTest('test5', async () => {
|
2021-07-27 21:04:38 +03:00
|
|
|
console.log('test5-done');
|
|
|
|
});
|
2021-06-07 03:09:53 +03:00
|
|
|
`,
|
|
|
|
};
|
|
|
|
|
|
|
|
test('should respect shard=1/2', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest(tests, { shard: '1/2' });
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(3);
|
2021-07-27 21:04:38 +03:00
|
|
|
expect(result.skipped).toBe(0);
|
2021-07-30 00:03:58 +03:00
|
|
|
expect(result.output).toContain('test1-done');
|
2023-02-01 02:59:13 +03:00
|
|
|
expect(result.output).toContain('test2-done');
|
2021-07-30 00:03:58 +03:00
|
|
|
expect(result.output).toContain('test3-done');
|
2021-06-07 03:09:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should respect shard=2/2', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest(tests, { shard: '2/2' });
|
|
|
|
expect(result.exitCode).toBe(0);
|
2021-07-27 21:04:38 +03:00
|
|
|
expect(result.passed).toBe(2);
|
|
|
|
expect(result.skipped).toBe(0);
|
2023-02-01 02:59:13 +03:00
|
|
|
expect(result.output).toContain('test4-done');
|
2021-07-30 00:03:58 +03:00
|
|
|
expect(result.output).toContain('test5-done');
|
2021-06-07 03:09:53 +03:00
|
|
|
});
|
2021-07-27 19:13:04 +03:00
|
|
|
|
2022-11-30 03:02:11 +03:00
|
|
|
test('should not produce skipped tests for zero-sized shards', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest(tests, { shard: '10/10' });
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
expect(result.failed).toBe(0);
|
|
|
|
expect(result.skipped).toBe(0);
|
|
|
|
expect(result.output).not.toContain('-done');
|
|
|
|
});
|
|
|
|
|
2021-07-27 19:13:04 +03:00
|
|
|
test('should respect shard=1/2 in config', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
...tests,
|
|
|
|
'playwright.config.js': `
|
|
|
|
module.exports = { shard: { current: 1, total: 2 } };
|
|
|
|
`,
|
2021-07-30 04:27:47 +03:00
|
|
|
});
|
2021-07-27 19:13:04 +03:00
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(3);
|
2021-07-27 21:04:38 +03:00
|
|
|
expect(result.skipped).toBe(0);
|
2021-07-30 00:03:58 +03:00
|
|
|
expect(result.output).toContain('test1-done');
|
2023-02-01 02:59:13 +03:00
|
|
|
expect(result.output).toContain('test2-done');
|
2021-07-30 00:03:58 +03:00
|
|
|
expect(result.output).toContain('test3-done');
|
2021-07-27 19:13:04 +03:00
|
|
|
});
|