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

Commit 468d1fd

Browse files
committed
Use JS scripts for npm test-related tasks
1 parent e581524 commit 468d1fd

File tree

6 files changed

+87
-3
lines changed

6 files changed

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

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)