Skip to content

Commit 02cf5ba

Browse files
authored
test: throw if no valid outDir (electron#22412)
1 parent 36f982a commit 02cf5ba

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

docs/development/testing.md

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ by coding style rules. `npm run lint-py` will check all Python, using
3232

3333
## Unit Tests
3434

35+
If you are not using [build-tools](https://github.com/electron/build-tools),
36+
ensure that that name you have configured for your
37+
local build of Electron is one of `Testing`, `Release`, `Default`, `Debug`, or
38+
you have set `process.env.ELECTRON_OUT_DIR`. Without these set, Electron will fail
39+
to perform some pre-testing steps.
40+
3541
To run all unit tests, run `npm run test`. The unit tests are an Electron
3642
app (surprise!) that can be found in the `spec` folder. Note that it has
3743
its own `package.json` and that its dependencies are therefore not defined

script/lib/utils.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function getElectronExec () {
2727

2828
function getOutDir (options = {}) {
2929
const shouldLog = options.shouldLog || false
30+
const presetDirs = ['Testing', 'Release', 'Default', 'Debug']
3031

3132
if (options.outDir || process.env.ELECTRON_OUT_DIR) {
3233
const outDir = options.outDir || process.env.ELECTRON_OUT_DIR
@@ -41,14 +42,18 @@ function getOutDir (options = {}) {
4142
// Throw error if user passed/set nonexistent directory.
4243
throw new Error(`${outDir} directory not configured on your machine.`)
4344
} else {
44-
for (const buildType of ['Testing', 'Release', 'Default', 'Debug']) {
45+
for (const buildType of presetDirs) {
4546
const outPath = path.resolve(SRC_DIR, 'out', buildType)
4647
if (fs.existsSync(outPath)) {
4748
if (shouldLog) console.log(`OUT_DIR is: ${buildType}`)
4849
return buildType
4950
}
5051
}
5152
}
53+
54+
// If we got here, it means process.env.ELECTRON_OUT_DIR was not
55+
// set and none of the preset options could be found in /out, so throw
56+
throw new Error(`No valid out directory found; use one of ${presetDirs.join(',')} or set process.env.ELECTRON_OUT_DIR`)
5257
}
5358

5459
function getAbsoluteElectronExec () {

0 commit comments

Comments
 (0)