Skip to content

Commit

Permalink
fix: use execa instead of child_process.spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
scurker committed Mar 18, 2019
1 parent 4c9afff commit 461ce83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
5 changes: 4 additions & 1 deletion .circleci/config.yml
Expand Up @@ -62,6 +62,7 @@ jobs:
<<: *defaults
steps:
- checkout
- <<: *restore_dependency_cache
- run: npm run test:examples

# Release a "next" version
Expand Down Expand Up @@ -99,7 +100,9 @@ workflows:
requires:
- dependencies
- lint
- test_examples
- test_examples:
requires:
- test
# Hold for approval
- hold:
type: approval
Expand Down
40 changes: 13 additions & 27 deletions doc/examples/test-examples.js
@@ -1,36 +1,22 @@
const { readdirSync, statSync } = require('fs');
const { join } = require('path');
const { spawn } = require('child_process');
const execa = require('execa');
const exampleDirs = readdirSync(__dirname)
.map(dir => join(__dirname, dir))
.filter(dir => statSync(dir).isDirectory());

async function runner(dir) {
let child = spawn('npm install && npm test', {
cwd: dir,
shell: true,
stdio: 'inherit'
});

return new Promise((resolve, reject) => {
child.on('close', code => {
if (code === 0) {
resolve();
} else {
reject();
}
});
});
const config = { cwd: dir, stdio: 'inherit' };
await execa.shell('npm install', config);
return execa.shell('npm test', config);
}

(async () => {
await Promise.all(exampleDirs.map(runner))
.then(() => {
// Return successful exit
process.exit();
})
.catch(err => {
console.log(err);
process.exit(1);
});
})();
Promise.all(exampleDirs.map(runner))
.then(() => {
// Return successful exit
process.exit();
})
.catch(err => {
console.error(err);
process.exit(1);
});

0 comments on commit 461ce83

Please sign in to comment.