forked from watson-developer-cloud/discovery-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
casper-runner.js
executable file
·38 lines (32 loc) · 984 Bytes
/
casper-runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require('dotenv').config();
const app = require('./app');
const spawn = require('child_process').spawn;
if (!process.env.DISCOVERY_USERNAME) {
// eslint-disable-next-line no-console
console.log('Skipping integration tests because DISCOVERY_USERNAME is null');
} else {
const port = 3000;
const server = app.listen(port, () => {
// eslint-disable-next-line no-console
console.log('Server running on port: %d', port);
function kill(code) {
server.close(() => {
// eslint-disable-next-line no-process-exit
process.exit(code);
});
}
function runTests() {
const casper = spawn('npm', ['run', 'test-integration']);
casper.stdout.pipe(process.stdout);
casper.on('error', (error) => {
// eslint-disable-next-line no-console
console.log(`ERROR: ${error}`);
server.close(() => {
process.exit(1);
});
});
casper.on('close', kill);
}
runTests();
});
}