forked from FrontendMasters/testing-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kent C. Dodds
committed
Feb 17, 2017
1 parent
60b5228
commit 8f69bc6
Showing
3 changed files
with
37 additions
and
21 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
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,26 +1,41 @@ | ||
const spawn = require('spawn-command-with-kill') | ||
|
||
console.log('spawning') | ||
const mongodChild = spawn('npm start mongo --silent', {stdio: 'inherit'}) | ||
const stopMongo = 'npm start mongo.stop' | ||
console.log(`stopping mongod with "${stopMongo}" (in case it is running)`) | ||
const stopMongoChild = spawn(stopMongo, {stdio: 'ignore'}) | ||
|
||
process.on('exit', cleanUp) | ||
process.on('SIGINT', cleanUp) | ||
process.on('uncaughtException', cleanUp) | ||
stopMongoChild.on('exit', () => { | ||
const startMongo = 'npm start mongo' | ||
console.log(`starting mongod with "${startMongo}"`) | ||
const mongodChild = spawn(startMongo, {stdio: 'ignore'}) | ||
let killed = false | ||
|
||
setTimeout(spawnGenerate, 3000) | ||
process.on('exit', cleanUp) | ||
process.on('SIGINT', cleanUp) | ||
process.on('uncaughtException', cleanUp) | ||
|
||
setTimeout(spawnGenerate, 3000) | ||
|
||
function spawnGenerate() { | ||
const babelNode = './node_modules/.bin/babel-node' | ||
const generateCommand = `cd api && ${babelNode} scripts/generate` | ||
console.log(`generating and inserting data with "${generateCommand}"`) | ||
const generateChild = spawn(generateCommand, { | ||
stdio: 'inherit', | ||
}) | ||
generateChild.on('exit', cleanUp) | ||
} | ||
|
||
function cleanUp() { | ||
if (!killed) { | ||
killed = true | ||
console.log('killing mongod process') | ||
mongodChild.kill() | ||
setTimeout(() => { | ||
// wait for mongo to die | ||
}, 1000) | ||
} | ||
} | ||
}) | ||
|
||
function spawnGenerate() { | ||
const babelNode = './node_modules/.bin/babel-node' | ||
const generateChild = spawn(`cd api && ${babelNode} scripts/generate`, { | ||
stdio: 'inherit', | ||
}) | ||
generateChild.on('exit', cleanUp) | ||
} | ||
|
||
function cleanUp() { | ||
console.log('killing mongod process') | ||
mongodChild.kill() | ||
setTimeout(() => { | ||
// wait for mongo to die | ||
}, 1000) | ||
} |