2021-04-02 02:35:26 +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-03-12 02:12:25 +03:00
|
|
|
import { config as loadEnv } from 'dotenv';
|
2023-08-09 04:46:32 +03:00
|
|
|
loadEnv({ path: path.join(__dirname, '..', '..', '.env'), override: true });
|
2022-03-12 02:12:25 +03:00
|
|
|
|
2023-08-10 03:23:34 +03:00
|
|
|
import { type Config, type PlaywrightTestOptions, type PlaywrightWorkerOptions, type ReporterDescription } from '@playwright/test';
|
2021-04-02 02:35:26 +03:00
|
|
|
import * as path from 'path';
|
2022-04-07 00:57:14 +03:00
|
|
|
import type { TestModeWorkerOptions } from '../config/testModeFixtures';
|
2022-09-15 01:05:18 +03:00
|
|
|
import type { TestModeName } from '../config/testMode';
|
2022-04-07 00:57:14 +03:00
|
|
|
import type { CoverageWorkerOptions } from '../config/coverageFixtures';
|
2021-10-27 18:28:53 +03:00
|
|
|
|
|
|
|
type BrowserName = 'chromium' | 'firefox' | 'webkit';
|
2021-04-02 02:35:26 +03:00
|
|
|
|
|
|
|
const getExecutablePath = (browserName: BrowserName) => {
|
|
|
|
if (browserName === 'chromium' && process.env.CRPATH)
|
|
|
|
return process.env.CRPATH;
|
|
|
|
if (browserName === 'firefox' && process.env.FFPATH)
|
|
|
|
return process.env.FFPATH;
|
|
|
|
if (browserName === 'webkit' && process.env.WKPATH)
|
|
|
|
return process.env.WKPATH;
|
|
|
|
};
|
|
|
|
|
2023-07-26 02:47:04 +03:00
|
|
|
const mode = (process.env.PWTEST_MODE ?? 'default') as TestModeName;
|
2022-05-10 19:03:47 +03:00
|
|
|
const headed = process.argv.includes('--headed');
|
2021-05-29 03:03:18 +03:00
|
|
|
const channel = process.env.PWTEST_CHANNEL as any;
|
|
|
|
const video = !!process.env.PWTEST_VIDEO;
|
2021-08-20 05:09:19 +03:00
|
|
|
const trace = !!process.env.PWTEST_TRACE;
|
2021-05-11 16:40:06 +03:00
|
|
|
|
2021-05-08 01:25:55 +03:00
|
|
|
const outputDir = path.join(__dirname, '..', '..', 'test-results');
|
|
|
|
const testDir = path.join(__dirname, '..');
|
2023-05-17 19:10:31 +03:00
|
|
|
const reporters = () => {
|
|
|
|
const result: ReporterDescription[] = process.env.CI ? [
|
|
|
|
['dot'],
|
|
|
|
['json', { outputFile: path.join(outputDir, 'report.json') }],
|
2023-07-29 01:49:31 +03:00
|
|
|
['blob'],
|
2023-05-17 19:10:31 +03:00
|
|
|
] : [
|
|
|
|
['html', { open: 'on-failure' }]
|
|
|
|
];
|
|
|
|
return result;
|
|
|
|
};
|
2023-07-26 02:47:04 +03:00
|
|
|
|
2023-07-27 00:32:48 +03:00
|
|
|
const os: 'linux' | 'windows' = (process.env.PLAYWRIGHT_SERVICE_OS as 'linux' | 'windows') || 'linux';
|
2023-07-27 04:36:33 +03:00
|
|
|
const runId = process.env.PLAYWRIGHT_SERVICE_RUN_ID || new Date().toISOString(); // name the test run
|
2023-07-26 02:47:04 +03:00
|
|
|
|
|
|
|
let connectOptions: any;
|
2023-08-04 18:38:07 +03:00
|
|
|
let webServer: any;
|
|
|
|
|
|
|
|
if (mode === 'service') {
|
2023-07-26 02:47:04 +03:00
|
|
|
connectOptions = { wsEndpoint: 'ws://localhost:3333/' };
|
2023-08-04 18:38:07 +03:00
|
|
|
webServer = {
|
|
|
|
command: 'npx playwright run-server --port=3333',
|
|
|
|
url: 'http://localhost:3333',
|
|
|
|
reuseExistingServer: !process.env.CI,
|
|
|
|
};
|
|
|
|
}
|
2023-07-26 02:47:04 +03:00
|
|
|
if (mode === 'service2') {
|
2023-07-31 21:24:04 +03:00
|
|
|
process.env.PW_VERSION_OVERRIDE = '1.37';
|
2023-07-26 02:47:04 +03:00
|
|
|
connectOptions = {
|
2023-08-10 23:43:16 +03:00
|
|
|
wsEndpoint: `${process.env.PLAYWRIGHT_SERVICE_URL}?cap=${JSON.stringify({ os, runId })}`,
|
2023-07-26 02:47:04 +03:00
|
|
|
timeout: 3 * 60 * 1000,
|
2023-07-27 03:29:31 +03:00
|
|
|
exposeNetwork: '<loopback>',
|
2023-08-10 23:43:16 +03:00
|
|
|
headers: {
|
|
|
|
'x-mpt-access-key': process.env.PLAYWRIGHT_SERVICE_ACCESS_KEY!
|
|
|
|
}
|
2023-07-26 02:47:04 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
const config: Config<CoverageWorkerOptions & PlaywrightWorkerOptions & PlaywrightTestOptions & TestModeWorkerOptions> = {
|
2021-05-08 01:25:55 +03:00
|
|
|
testDir,
|
|
|
|
outputDir,
|
2021-11-17 22:56:24 +03:00
|
|
|
expect: {
|
|
|
|
timeout: 10000,
|
|
|
|
},
|
2023-07-26 02:47:04 +03:00
|
|
|
maxFailures: 200,
|
2021-08-20 05:09:19 +03:00
|
|
|
timeout: video ? 60000 : 30000,
|
2021-05-08 01:25:55 +03:00
|
|
|
globalTimeout: 5400000,
|
2022-06-24 01:55:12 +03:00
|
|
|
workers: process.env.CI ? 2 : undefined,
|
2022-03-02 05:12:21 +03:00
|
|
|
fullyParallel: !process.env.CI,
|
2021-05-08 01:25:55 +03:00
|
|
|
forbidOnly: !!process.env.CI,
|
|
|
|
retries: process.env.CI ? 3 : 0,
|
2023-05-17 19:10:31 +03:00
|
|
|
reporter: reporters(),
|
2021-05-08 01:25:55 +03:00
|
|
|
projects: [],
|
2022-12-14 03:03:53 +03:00
|
|
|
use: {
|
2023-07-26 02:47:04 +03:00
|
|
|
connectOptions,
|
2022-12-14 03:03:53 +03:00
|
|
|
},
|
2023-08-04 18:38:07 +03:00
|
|
|
webServer,
|
2022-02-11 03:36:23 +03:00
|
|
|
};
|
|
|
|
|
2021-05-09 03:45:04 +03:00
|
|
|
const browserNames = ['chromium', 'webkit', 'firefox'] as BrowserName[];
|
|
|
|
for (const browserName of browserNames) {
|
2021-04-02 02:35:26 +03:00
|
|
|
const executablePath = getExecutablePath(browserName);
|
2021-06-05 04:43:54 +03:00
|
|
|
if (executablePath && !process.env.TEST_WORKER_INDEX)
|
2021-04-05 19:19:39 +03:00
|
|
|
console.error(`Using executable at ${executablePath}`);
|
2021-10-26 23:45:53 +03:00
|
|
|
const devtools = process.env.DEVTOOLS === '1';
|
2021-05-09 03:45:04 +03:00
|
|
|
const testIgnore: RegExp[] = browserNames.filter(b => b !== browserName).map(b => new RegExp(b));
|
2022-03-26 09:09:02 +03:00
|
|
|
for (const folder of ['library', 'page']) {
|
|
|
|
config.projects.push({
|
|
|
|
name: browserName,
|
|
|
|
testDir: path.join(testDir, folder),
|
|
|
|
testIgnore,
|
2022-11-11 04:23:57 +03:00
|
|
|
snapshotPathTemplate: '{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{ext}',
|
2022-03-26 09:09:02 +03:00
|
|
|
use: {
|
|
|
|
mode,
|
|
|
|
browserName,
|
|
|
|
headless: !headed,
|
|
|
|
channel,
|
|
|
|
video: video ? 'on' : undefined,
|
|
|
|
launchOptions: {
|
|
|
|
executablePath,
|
|
|
|
devtools
|
|
|
|
},
|
|
|
|
trace: trace ? 'on' : undefined,
|
|
|
|
coverageName: browserName,
|
2021-10-26 23:45:53 +03:00
|
|
|
},
|
2022-03-26 09:09:02 +03:00
|
|
|
metadata: {
|
|
|
|
platform: process.platform,
|
|
|
|
docker: !!process.env.INSIDE_DOCKER,
|
|
|
|
headful: !!headed,
|
|
|
|
browserName,
|
|
|
|
channel,
|
|
|
|
mode,
|
|
|
|
video: !!video,
|
|
|
|
trace: !!trace,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-04-02 02:35:26 +03:00
|
|
|
}
|
2021-05-08 01:25:55 +03:00
|
|
|
|
|
|
|
export default config;
|