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

Commit

Permalink
Merge pull request #2311 from atom/aw/fix-npm-test
Browse files Browse the repository at this point in the history
Use JavaScript scripts for npm test tasks
  • Loading branch information
smashwilson committed Oct 17, 2019
2 parents e581524 + b778f2d commit 57788ea
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -6,12 +6,12 @@
"repository": "https://github.com/atom/github",
"license": "MIT",
"scripts": {
"test": "cross-env-shell NODE_ENV=development \"${ATOM_SCRIPT_PATH:-atom} --test test\"",
"test:coverage": "cross-env ATOM_GITHUB_BABEL_ENV=coverage npm run test",
"test": "node script/test",
"test:coverage": "node script/test-coverage",
"test:coverage:text": "nyc --reporter=text npm run test:coverage",
"test:coverage:html": "nyc --reporter=html npm run test:coverage",
"test:coverage:lcov": "npm run test:coverage",
"test:snapshot": "cross-env-shell ATOM_GITHUB_TEST_SUITE=snapshot \"${ATOM_SCRIPT_PATH:-atom} --test test\"",
"test:snapshot": "node script/test-snapshot",
"codecov": "codecov",
"report:coverage": "nyc report --reporter=cobertura --reporter=html --reporter=lcovonly",
"lint": "eslint --max-warnings 0 test lib",
Expand Down
12 changes: 12 additions & 0 deletions script/helpers/paths.js
@@ -0,0 +1,12 @@
const path = require('path');

const ROOT = path.resolve(__dirname, '../..');

function projectPath(...parts) {
return path.join(ROOT, ...parts);
}

module.exports = {
ROOT,
projectPath,
};
55 changes: 55 additions & 0 deletions script/helpers/run-atom.js
@@ -0,0 +1,55 @@
const {spawn} = require('child_process');

function atomProcess(env, ...args) {
const atomBinPath = process.env.ATOM_SCRIPT_PATH || 'atom';
const atomEnv = {...process.env, ...env};
const isWindows = process.platform === 'win32';

return new Promise((resolve, reject) => {
let settled = false;

const child = spawn(atomBinPath, args, {
env: atomEnv,
stdio: 'inherit',
shell: isWindows,
windowsHide: true,
});

child.on('error', err => {
if (!settled) {
settled = true;
reject(err);
} else {
// eslint-disable-next-line no-console
console.error(`Unexpected subprocess error:\n${err.stack}`);
}
});

child.on('exit', (code, signal) => {
if (!settled) {
settled = true;
resolve({code, signal});
}
});
});
}

async function runAtom(...args) {
try {
const {code, signal} = await atomProcess(...args);
if (signal) {
// eslint-disable-next-line no-console
console.log(`Atom process killed with signal ${signal}.`);
}
process.exit(code !== null ? code : 1);
} catch (err) {
// eslint-disable-next-line no-console
console.error(err.stack);
process.exit(1);
}
}

module.exports = {
atomProcess,
runAtom,
};
6 changes: 6 additions & 0 deletions script/test
@@ -0,0 +1,6 @@
#!/usr/bin/env node

const {runAtom} = require('./helpers/run-atom');
const {projectPath} = require('./helpers/paths');

runAtom({NODE_ENV: 'development'}, '--test', projectPath('test'));
6 changes: 6 additions & 0 deletions script/test-coverage
@@ -0,0 +1,6 @@
#!/usr/bin/env node

const {runAtom} = require('./helpers/run-atom');
const {projectPath} = require('./helpers/paths');

runAtom({NODE_ENV: 'development', ATOM_GITHUB_BABEL_ENV: 'coverage'}, '--test', projectPath('test'));
6 changes: 6 additions & 0 deletions script/test-snapshot
@@ -0,0 +1,6 @@
#!/usr/bin/env node

const {runAtom} = require('./helpers/run-atom');
const {projectPath} = require('./helpers/paths');

runAtom({NODE_ENV: 'development', ATOM_GITHUB_TEST_SUITE: 'snapshot'}, '--test', projectPath('test'));

0 comments on commit 57788ea

Please sign in to comment.