Skip to content

Commit

Permalink
WIP: Improve test runner switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
kiskoza committed May 6, 2024
1 parent 38d373d commit 2b2f8ee
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"engines": {
"node": ">=14"
},
"atomTestRunner": "runners/jasmine2-test-runner",
"license": "MIT",
"electronVersion": "12.2.3",
"resolutions": {
Expand Down
78 changes: 52 additions & 26 deletions src/main-process/atom-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1747,39 +1747,65 @@ module.exports = class AtomApplication extends EventEmitter {
}

resolveTestRunnerPath(testPath) {
let packageRoot;
if (FindParentDir == null) {
FindParentDir = require('find-parent-dir');
FindParentDir ||= require('find-parent-dir');

let packageRoot = FindParentDir.sync(testPath, 'package.json');

if (!packageRoot) {
process.stderr.write('Error: Could not find root directory');
process.exit(1);
}

if ((packageRoot = FindParentDir.sync(testPath, 'package.json'))) {
const packageMetadata = require(path.join(packageRoot, 'package.json'));
if (packageMetadata.atomTestRunner) {
let testRunnerPath;
if (Resolve == null) {
Resolve = require('resolve');
}
if (
(testRunnerPath = Resolve.sync(packageMetadata.atomTestRunner, {
basedir: packageRoot,
extensions: Object.keys(require.extensions)
}))
) {
return testRunnerPath;
} else {
process.stderr.write(
`Error: Could not resolve test runner path '${
packageMetadata.atomTestRunner
}'`
);
process.exit(1);
}
const packageMetadata = require(path.join(packageRoot, 'package.json'));
let atomTestRunner = packageMetadata.atomTestRunner;

if (!atomTestRunner) {
process.stdout.write('atomTestRunner was not defined, using the deprecated runners/jasmine1-test-runner.');
atomTestRunner = 'runners/jasmine1-test-runner';
}

let testRunnerPath;
Resolve ||= require('resolve');

// First try to run with local runners (e.g: `./test/runner.js`) or packages (e.g.: `atom-mocha-test-runner`)
try {
testRunnerPath = Resolve.sync(atomTestRunner, {
basedir: packageRoot,
extensions: Object.keys(require.extensions)
});

if (testRunnerPath) {
return testRunnerPath;
}
} catch {
// Nothing to do, try the next strategy
}

return this.resolveLegacyTestRunnerPath();
// Then try to use one of the runners defined in Pulsar
try {
testRunnerPath = Resolve.sync(`./spec/${atomTestRunner}`, {
basedir: this.devResourcePath,
extensions: Object.keys(require.extensions)
});

if (testRunnerPath) {
return testRunnerPath;
}
} catch {
// Nothing to do, try the next strategy
}

// TODO: packages might require __dirname ?

process.stderr.write(
`Error: Could not resolve test runner path '${
packageMetadata.atomTestRunner
}'`
);
process.exit(1);
}

// TODO: remove?
resolveLegacyTestRunnerPath() {
try {
return require.resolve(
Expand Down
1 change: 0 additions & 1 deletion src/main-process/atom-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ module.exports = class AtomWindow extends EventEmitter {
disableBlinkFeatures: 'Auxclick',
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
webviewTag: true,

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

0 comments on commit 2b2f8ee

Please sign in to comment.