Skip to content

Commit 50994f0

Browse files
committed
add better error handling for headed tests
1 parent 7673d48 commit 50994f0

File tree

3 files changed

+136
-65
lines changed

3 files changed

+136
-65
lines changed

core/package-lock.json

Lines changed: 112 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@types/node": "^14.6.0",
5555
"@typescript-eslint/eslint-plugin": "^6.7.2",
5656
"@typescript-eslint/parser": "^6.7.2",
57+
"chalk": "^5.3.0",
5758
"clean-css-cli": "^5.6.1",
5859
"domino": "^2.1.6",
5960
"eslint": "^7.32.0",

core/scripts/docker.mjs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import { execa } from 'execa';
22
import * as fs from 'fs';
33
import { resolve } from 'path';
4+
import chalk from 'chalk';
45

56
const removeNewline = (string) => {
67
return string.replace(/(\r\n|\n|\r)/gm, "");
78
}
89

9-
const display = removeNewline(fs.readFileSync('docker-display.txt', { encoding: 'utf-8' }));
10-
const displayVolume = removeNewline(fs.readFileSync('docker-display-volume.txt', { encoding: 'utf-8' }));
10+
const readConfigFile = (file) => {
11+
if (fs.existsSync(file)) {
12+
return fs.readFileSync(file, { encoding: 'utf-8' });
13+
}
14+
15+
return '';
16+
}
17+
18+
// These files are optional, so we don't want to error if they don't exist
19+
const display = removeNewline(readConfigFile('docker-display.txt'));
20+
const displayVolume = removeNewline(readConfigFile('docker-display-volume.txt'));
1121

1222
// Using --mount requires an absolute path which is what this gives us.
1323
const pwd = resolve('./');
@@ -26,4 +36,15 @@ if (process.env.CI) {
2636
args.splice(1, 0, '-e CI=true');
2737
}
2838

39+
/**
40+
* While these config files are optional to run the tests, they are required to run
41+
* the tests in headed mode. Add a warning if dev tries to run headed tests without
42+
* the correct config files.
43+
*/
44+
const requestHeaded = process.argv.find(arg => arg.includes('headed'));
45+
const hasHeadedConfigFiles = display && displayVolume;
46+
if (requestHeaded && !hasHeadedConfigFiles) {
47+
console.warn(chalk.yellow.bold('\n⚠️ You are running tests in headed mode, but one or more of your headed config files was not found.\nPlease ensure that both docker-display.txt and docker-display-volume.txt have been created in the correct location.\n'));
48+
}
49+
2950
execa('docker', args, { shell: true, stdio: 'inherit' });

0 commit comments

Comments
 (0)