Skip to content

Commit d67ed90

Browse files
committed
WIP: Improve test runner switcher
1 parent b63c5e1 commit d67ed90

File tree

3 files changed

+53
-27
lines changed

3 files changed

+53
-27
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"engines": {
2323
"node": ">=14"
2424
},
25+
"atomTestRunner": "runners/jasmine2-test-runner",
2526
"license": "MIT",
2627
"electronVersion": "12.2.3",
2728
"resolutions": {

src/main-process/atom-application.js

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,39 +1747,65 @@ module.exports = class AtomApplication extends EventEmitter {
17471747
}
17481748

17491749
resolveTestRunnerPath(testPath) {
1750-
let packageRoot;
1751-
if (FindParentDir == null) {
1752-
FindParentDir = require('find-parent-dir');
1750+
FindParentDir ||= require('find-parent-dir');
1751+
1752+
let packageRoot = FindParentDir.sync(testPath, 'package.json');
1753+
1754+
if (!packageRoot) {
1755+
process.stderr.write('Error: Could not find root directory');
1756+
process.exit(1);
17531757
}
17541758

1755-
if ((packageRoot = FindParentDir.sync(testPath, 'package.json'))) {
1756-
const packageMetadata = require(path.join(packageRoot, 'package.json'));
1757-
if (packageMetadata.atomTestRunner) {
1758-
let testRunnerPath;
1759-
if (Resolve == null) {
1760-
Resolve = require('resolve');
1761-
}
1762-
if (
1763-
(testRunnerPath = Resolve.sync(packageMetadata.atomTestRunner, {
1764-
basedir: packageRoot,
1765-
extensions: Object.keys(require.extensions)
1766-
}))
1767-
) {
1768-
return testRunnerPath;
1769-
} else {
1770-
process.stderr.write(
1771-
`Error: Could not resolve test runner path '${
1772-
packageMetadata.atomTestRunner
1773-
}'`
1774-
);
1775-
process.exit(1);
1776-
}
1759+
const packageMetadata = require(path.join(packageRoot, 'package.json'));
1760+
let atomTestRunner = packageMetadata.atomTestRunner;
1761+
1762+
if (!atomTestRunner) {
1763+
process.stdout.write('atomTestRunner was not defined, using the deprecated runners/jasmine1-test-runner.');
1764+
atomTestRunner = 'runners/jasmine1-test-runner';
1765+
}
1766+
1767+
let testRunnerPath;
1768+
Resolve ||= require('resolve');
1769+
1770+
// First try to run with local runners (e.g: `./test/runner.js`) or packages (e.g.: `atom-mocha-test-runner`)
1771+
try {
1772+
testRunnerPath = Resolve.sync(atomTestRunner, {
1773+
basedir: packageRoot,
1774+
extensions: Object.keys(require.extensions)
1775+
});
1776+
1777+
if (testRunnerPath) {
1778+
return testRunnerPath;
17771779
}
1780+
} catch {
1781+
// Nothing to do, try the next strategy
17781782
}
17791783

1780-
return this.resolveLegacyTestRunnerPath();
1784+
// Then try to use one of the runners defined in Pulsar
1785+
try {
1786+
testRunnerPath = Resolve.sync(`./spec/${atomTestRunner}`, {
1787+
basedir: this.devResourcePath,
1788+
extensions: Object.keys(require.extensions)
1789+
});
1790+
1791+
if (testRunnerPath) {
1792+
return testRunnerPath;
1793+
}
1794+
} catch {
1795+
// Nothing to do, try the next strategy
1796+
}
1797+
1798+
// TODO: packages might require __dirname ?
1799+
1800+
process.stderr.write(
1801+
`Error: Could not resolve test runner path '${
1802+
packageMetadata.atomTestRunner
1803+
}'`
1804+
);
1805+
process.exit(1);
17811806
}
17821807

1808+
// TODO: remove?
17831809
resolveLegacyTestRunnerPath() {
17841810
try {
17851811
return require.resolve(

src/main-process/atom-window.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ module.exports = class AtomWindow extends EventEmitter {
6060
disableBlinkFeatures: 'Auxclick',
6161
nodeIntegration: true,
6262
contextIsolation: false,
63-
enableRemoteModule: true,
6463
webviewTag: true,
6564

6665
// TodoElectronIssue: remote module is deprecated https://www.electronjs.org/docs/breaking-changes#default-changed-enableremotemodule-defaults-to-false

0 commit comments

Comments
 (0)