-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
147 lines (124 loc) · 5.15 KB
/
config.ts
File metadata and controls
147 lines (124 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* @file Full pack configuration for running tests.
* Don't import this module. Instead, use `getFullPackConfig` from `utils/config`.
*/
import {join, relative} from 'node:path';
import {
ABSOLUTE_PATH_TO_INSTALLED_E2ED_DIRECTORY,
ABSOLUTE_PATH_TO_PROJECT_ROOT_DIRECTORY,
AFTER_ERROR_IN_TEST_TIMEOUT_IN_MS,
COMPILED_USERLAND_CONFIG_DIRECTORY,
e2edEnvironment,
EXPECTED_SCREENSHOTS_DIRECTORY_PATH,
INTERNAL_REPORTS_DIRECTORY_PATH,
IS_DEBUG,
MAX_TIMEOUT_IN_MS,
PATH_TO_TEST_FILE_VARIABLE_NAME,
TESTS_DIRECTORY_PATH,
} from './constants/internal';
import {assertValueIsTrue} from './utils/asserts';
// eslint-disable-next-line import/no-internal-modules
import {assertUserlandPack} from './utils/config/assertUserlandPack';
// eslint-disable-next-line import/no-internal-modules
import {updateConfig} from './utils/config/updateConfig';
import {getPathToPack} from './utils/environment';
import {setCustomInspectOnFunction} from './utils/fn';
// eslint-disable-next-line import/no-internal-modules
import {readStartInfoSync} from './utils/fs/readStartInfoSync';
import {setReadonlyProperty} from './utils/object';
import {isUiMode} from './utils/uiMode';
import {isLocalRun} from './configurator';
import type {FullPackConfig, Mutable, UserlandPack} from './types/internal';
import {defineConfig, type PlaywrightTestConfig} from '@playwright/test';
const pathToPack = getPathToPack();
const relativePathFromInstalledE2edToRoot = relative(
ABSOLUTE_PATH_TO_INSTALLED_E2ED_DIRECTORY,
ABSOLUTE_PATH_TO_PROJECT_ROOT_DIRECTORY,
);
const tsExtension = '.ts';
assertValueIsTrue(pathToPack.endsWith(tsExtension), `pathToPack ends with "${tsExtension}"`, {
pathToPack,
});
const pathFromCompiledConfigDirectoryToCompiledPack = `${pathToPack.slice(0, -tsExtension.length)}.js`;
const absoluteCompiledUserlandPackPath = join(
ABSOLUTE_PATH_TO_PROJECT_ROOT_DIRECTORY,
COMPILED_USERLAND_CONFIG_DIRECTORY,
pathFromCompiledConfigDirectoryToCompiledPack,
);
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require
const userlandPack = require<{pack: UserlandPack}>(absoluteCompiledUserlandPackPath).pack;
const pathToTestFile = e2edEnvironment[PATH_TO_TEST_FILE_VARIABLE_NAME];
if (pathToTestFile !== undefined) {
setReadonlyProperty(userlandPack, 'testFileGlobs', [join('**', pathToTestFile)]);
}
assertUserlandPack(userlandPack);
const {
doAfterPack,
doBeforePack,
filterTestsIntoPack,
mapBackendResponseErrorToLog,
mapBackendResponseToLog,
mapLogPayloadInConsole,
mapLogPayloadInLogFile,
mapLogPayloadInReport,
} = userlandPack;
for (const fn of doAfterPack) {
setCustomInspectOnFunction(fn);
}
for (const fn of doBeforePack) {
setCustomInspectOnFunction(fn);
}
setCustomInspectOnFunction(filterTestsIntoPack);
setCustomInspectOnFunction(mapBackendResponseErrorToLog);
setCustomInspectOnFunction(mapBackendResponseToLog);
setCustomInspectOnFunction(mapLogPayloadInConsole);
setCustomInspectOnFunction(mapLogPayloadInLogFile);
setCustomInspectOnFunction(mapLogPayloadInReport);
if (IS_DEBUG || isUiMode) {
setReadonlyProperty(userlandPack, 'packTimeout', MAX_TIMEOUT_IN_MS);
setReadonlyProperty(userlandPack, 'testIdleTimeout', MAX_TIMEOUT_IN_MS);
setReadonlyProperty(userlandPack, 'testTimeout', MAX_TIMEOUT_IN_MS);
}
const useOptions: PlaywrightTestConfig['use'] = {
actionTimeout: userlandPack.selectorTimeout,
browserName: userlandPack.browserName,
// eslint-disable-next-line @typescript-eslint/naming-convention
bypassCSP: !userlandPack.enableCsp,
deviceScaleFactor: userlandPack.deviceScaleFactor,
hasTouch: userlandPack.enableTouchEventEmulation,
headless: isLocalRun ? userlandPack.enableHeadlessMode : true,
isMobile: userlandPack.enableMobileDeviceMode,
launchOptions: {args: [...userlandPack.browserFlags]},
navigationTimeout: userlandPack.navigationTimeout,
trace: 'retain-on-failure',
userAgent: userlandPack.userAgent,
viewport: {height: userlandPack.viewportHeight, width: userlandPack.viewportWidth},
...userlandPack.overriddenConfigFields?.use,
};
const playwrightConfig = defineConfig({
expect: {
timeout: userlandPack.assertionTimeout,
toHaveScreenshot: {
pathTemplate: `${ABSOLUTE_PATH_TO_PROJECT_ROOT_DIRECTORY}/${EXPECTED_SCREENSHOTS_DIRECTORY_PATH}/{arg}.png`,
},
},
fullyParallel: true,
globalTimeout: userlandPack.packTimeout,
outputDir: join(relativePathFromInstalledE2edToRoot, INTERNAL_REPORTS_DIRECTORY_PATH),
projects: [{name: userlandPack.browserName, use: useOptions}],
retries: isLocalRun ? 0 : userlandPack.maxRetriesCountInDocker - 1,
testDir: join(relativePathFromInstalledE2edToRoot, TESTS_DIRECTORY_PATH),
testIgnore: ['**/node_modules/**', '**/*.skip.ts'],
testMatch: userlandPack.testFileGlobs as Mutable<typeof userlandPack.testFileGlobs>,
timeout: userlandPack.testTimeout + AFTER_ERROR_IN_TEST_TIMEOUT_IN_MS,
workers: userlandPack.concurrency,
...userlandPack.overriddenConfigFields,
use: useOptions,
});
const config: FullPackConfig = Object.assign(playwrightConfig, userlandPack);
try {
const startInfo = readStartInfoSync();
updateConfig(config, startInfo);
} catch {}
// eslint-disable-next-line import/no-default-export
export default config;