-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathwdio.shared.conf.ts
More file actions
192 lines (179 loc) · 5.31 KB
/
Copy pathwdio.shared.conf.ts
File metadata and controls
192 lines (179 loc) · 5.31 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import * as path from 'path';
import * as fs from 'fs';
import type { Options, Capabilities } from '@wdio/types';
import { projectRoot } from './tests/e2eTestUtils';
const TEST_DATASETS = [
{
url: 'https://data.kitware.com/api/v1/file/6566aa81c5a2b36857ad1783/download',
name: 'CT000085.dcm',
},
{
url: 'https://data.kitware.com/api/v1/file/68e9807dbf0f869935e36481/download',
name: 'minimal.dcm',
},
{
url: 'https://data.kitware.com/api/v1/item/63527c7311dab8142820a338/download',
name: 'prostate.zip',
},
{
url: 'https://data.kitware.com/api/v1/item/6352a2b311dab8142820a33b/download',
name: 'MRA-Head_and_Neck.zip',
},
{
url: 'https://data.kitware.com/api/v1/item/635679c311dab8142820a4f4/download',
name: 'fetus.zip',
},
{
url: 'https://sourceforge.net/p/gdcm/gdcmdata/ci/master/tree/US-MONO2-8-8x-execho.dcm?format=raw',
name: 'US-MONO2-8-8x-echo.dcm',
},
];
export const WINDOW_SIZE = [1200, 800] as const;
export const TEST_PORT = 4567;
// for slow connections try:
// DOWNLOAD_TIMEOUT=60000 && npm run test:e2e:dev
export const DOWNLOAD_TIMEOUT = Number(process.env.DOWNLOAD_TIMEOUT ?? 20000);
const IS_CI = !!(process.env.CI || process.env.GITHUB_ACTIONS);
const ROOT = projectRoot();
const TMP = '.tmp/';
// TEMP_DIR is also browser downloads directory
export const TEMP_DIR = path.resolve(ROOT, TMP);
const FIXTURES_DIR = 'tests/fixtures/';
export const FIXTURES = path.resolve(ROOT, FIXTURES_DIR);
export const config: Options.Testrunner = {
baseUrl: `http://localhost:${TEST_PORT}`,
// ====================
// Runner Configuration
// ====================
runner: 'local',
//
// ==================
// Specify Test Files
// ==================
specs: ['./tests/specs/**/*.e2e.ts'],
exclude: [],
//
// ============
// Capabilities
// ============
maxInstances: IS_CI ? 1 : 6,
//
// ===================
// Test Configurations
// ===================
logLevel: 'warn',
bail: 0,
waitforTimeout: 10000,
connectionRetryTimeout: 90000,
connectionRetryCount: 3,
services: [
[
'static-server',
{
folders: [
{
mount: '/',
path: './dist',
},
{ mount: '/tmp', path: `./${TMP}` },
],
port: TEST_PORT,
},
],
[
'visual',
{
baselineFolder: path.resolve(ROOT, 'tests/baseline/'),
formatImageName:
'{tag}-{browserName}-{platformName}-{width}x{height}-{dpr}',
screenshotPath: TEMP_DIR,
autoSaveBaseline: true,
},
],
'cleanuptotal',
],
framework: 'mocha',
reporters: ['spec', 'html-nice'],
mochaOpts: {
ui: 'bdd',
timeout: 60000,
},
//
// Hooks
//
async onPrepare() {
fs.mkdirSync(TEMP_DIR, { recursive: true });
const RETRIES = 3;
const RETRY_DELAY_MS = 500;
const delay = (ms: number) =>
new Promise((resolve) => {
setTimeout(resolve, ms);
});
const downloadOnce = async (url: string, savePath: string) => {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP ${response.status} for ${url}`);
}
const data = await response.arrayBuffer();
// Write to a temp path first so a failed/partial download never leaves a
// corrupt file that the existsSync check would treat as already cached.
const tmpPath = `${savePath}.part`;
fs.writeFileSync(tmpPath, Buffer.from(data));
fs.renameSync(tmpPath, savePath);
};
const downloads = TEST_DATASETS.map(async ({ url, name }) => {
const savePath = path.join(TEMP_DIR, name);
if (fs.existsSync(savePath)) {
return;
}
for (let attempt = 1; attempt <= RETRIES; attempt += 1) {
try {
await downloadOnce(url, savePath);
return;
} catch (err) {
if (attempt === RETRIES) {
throw new Error(
`Failed to download ${name} after ${RETRIES} attempts: ${
(err as Error).message
}`
);
}
await delay(RETRY_DELAY_MS);
}
}
});
await Promise.all(downloads);
},
async before(
_capabilities:
| Capabilities.RequestedStandaloneCapabilities
| Capabilities.RequestedMultiremoteCapabilities,
_specs: string[],
browser: any
) {
await browser.setWindowSize(...WINDOW_SIZE);
// Subscribe to browser console logs and output them directly
await browser.sessionSubscribe({ events: ['log.entryAdded'] });
browser.on('log.entryAdded', (logEntry: any) => {
const message = logEntry.text || '';
console.log(`[Browser Console] [${logEntry.level}] ${message}`);
});
},
async afterCommand(commandName: string) {
// After navigation, inject console interceptor to stringify errors
if (commandName === 'navigateTo' || commandName === 'url') {
await browser.execute(() => {
if (!(console.error as any).__patched) {
const originalError = console.error;
console.error = (...args: any[]) => {
const stringArgs = args.map((arg) =>
arg instanceof Error ? `${arg.name}: ${arg.message}` : arg
);
originalError.apply(console, stringArgs);
};
(console.error as any).__patched = true;
}
});
}
},
};