Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion wdio.chrome.conf.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { config as sharedConfig, TEMP_DIR } from './wdio.shared.conf';

const IS_CI = !!(process.env.CI || process.env.GITHUB_ACTIONS);

// Chrome arguments for CI environments
const chromeArgs: string[] = [];
if (process.env.CI || process.env.GITHUB_ACTIONS) {
if (IS_CI) {
chromeArgs.push(
'--no-sandbox',
'--disable-dev-shm-usage',
Expand All @@ -11,6 +13,10 @@ if (process.env.CI || process.env.GITHUB_ACTIONS) {
);
}

if (!IS_CI && !process.env.HEADED) {
chromeArgs.push('--headless=new', '--enable-unsafe-swiftshader');
}

export const config = {
...sharedConfig,
capabilities: [
Expand Down
37 changes: 34 additions & 3 deletions wdio.shared.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,45 @@ export const config: Options.Testrunner = {
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;
}
const response = await fetch(url);
const data = await response.arrayBuffer();
fs.writeFileSync(savePath, Buffer.from(data));
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);
},
Expand Down
Loading