-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use execa instead of child_process.spawn
- Loading branch information
Showing
2 changed files
with
17 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |