Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 57788ea

Browse files
authored
Merge pull request #2311 from atom/aw/fix-npm-test
Use JavaScript scripts for npm test tasks
2 parents e581524 + b778f2d commit 57788ea

File tree

6 files changed

+88
-3
lines changed

6 files changed

+88
-3
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"repository": "https://github.com/atom/github",
77
"license": "MIT",
88
"scripts": {
9-
"test": "cross-env-shell NODE_ENV=development \"${ATOM_SCRIPT_PATH:-atom} --test test\"",
10-
"test:coverage": "cross-env ATOM_GITHUB_BABEL_ENV=coverage npm run test",
9+
"test": "node script/test",
10+
"test:coverage": "node script/test-coverage",
1111
"test:coverage:text": "nyc --reporter=text npm run test:coverage",
1212
"test:coverage:html": "nyc --reporter=html npm run test:coverage",
1313
"test:coverage:lcov": "npm run test:coverage",
14-
"test:snapshot": "cross-env-shell ATOM_GITHUB_TEST_SUITE=snapshot \"${ATOM_SCRIPT_PATH:-atom} --test test\"",
14+
"test:snapshot": "node script/test-snapshot",
1515
"codecov": "codecov",
1616
"report:coverage": "nyc report --reporter=cobertura --reporter=html --reporter=lcovonly",
1717
"lint": "eslint --max-warnings 0 test lib",

script/helpers/paths.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const path = require('path');
2+
3+
const ROOT = path.resolve(__dirname, '../..');
4+
5+
function projectPath(...parts) {
6+
return path.join(ROOT, ...parts);
7+
}
8+
9+
module.exports = {
10+
ROOT,
11+
projectPath,
12+
};

script/helpers/run-atom.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const {spawn} = require('child_process');
2+
3+
function atomProcess(env, ...args) {
4+
const atomBinPath = process.env.ATOM_SCRIPT_PATH || 'atom';
5+
const atomEnv = {...process.env, ...env};
6+
const isWindows = process.platform === 'win32';
7+
8+
return new Promise((resolve, reject) => {
9+
let settled = false;
10+
11+
const child = spawn(atomBinPath, args, {
12+
env: atomEnv,
13+
stdio: 'inherit',
14+
shell: isWindows,
15+
windowsHide: true,
16+
});
17+
18+
child.on('error', err => {
19+
if (!settled) {
20+
settled = true;
21+
reject(err);
22+
} else {
23+
// eslint-disable-next-line no-console
24+
console.error(`Unexpected subprocess error:\n${err.stack}`);
25+
}
26+
});
27+
28+
child.on('exit', (code, signal) => {
29+
if (!settled) {
30+
settled = true;
31+
resolve({code, signal});
32+
}
33+
});
34+
});
35+
}
36+
37+
async function runAtom(...args) {
38+
try {
39+
const {code, signal} = await atomProcess(...args);
40+
if (signal) {
41+
// eslint-disable-next-line no-console
42+
console.log(`Atom process killed with signal ${signal}.`);
43+
}
44+
process.exit(code !== null ? code : 1);
45+
} catch (err) {
46+
// eslint-disable-next-line no-console
47+
console.error(err.stack);
48+
process.exit(1);
49+
}
50+
}
51+
52+
module.exports = {
53+
atomProcess,
54+
runAtom,
55+
};

script/test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
3+
const {runAtom} = require('./helpers/run-atom');
4+
const {projectPath} = require('./helpers/paths');
5+
6+
runAtom({NODE_ENV: 'development'}, '--test', projectPath('test'));

script/test-coverage

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
3+
const {runAtom} = require('./helpers/run-atom');
4+
const {projectPath} = require('./helpers/paths');
5+
6+
runAtom({NODE_ENV: 'development', ATOM_GITHUB_BABEL_ENV: 'coverage'}, '--test', projectPath('test'));

script/test-snapshot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
3+
const {runAtom} = require('./helpers/run-atom');
4+
const {projectPath} = require('./helpers/paths');
5+
6+
runAtom({NODE_ENV: 'development', ATOM_GITHUB_TEST_SUITE: 'snapshot'}, '--test', projectPath('test'));

0 commit comments

Comments
 (0)