-
Notifications
You must be signed in to change notification settings - Fork 40
/
server-runner.js
40 lines (35 loc) · 1.01 KB
/
server-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
39
40
/* global afterEach, browser */
'use strict';
var spawn = require('cross-spawn');
var q = require('q');
var serverProcess;
module.exports = function (js, params) {
var deferred = q.defer();
console.log('\x1b[33m%s\x1b[0m', 'Starting fake server!');
serverProcess = spawn('node', [js].concat(params));
serverProcess.stdout.on('data', function () {
deferred.resolve();
});
serverProcess.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
serverProcess.on('close', function () {
console.log('\x1b[31m%s\x1b[0m', 'Fake server aborted!! This might mean port is already in use.');
process.exit();
});
return {
promise: deferred.promise,
kill: function () {
console.log('\x1b[33m%s\x1b[0m', 'Killing fake server!');
serverProcess.kill();
}
};
};
module.exports.addSessionCookieCleaner = function () {
afterEach(function () {
browser.executeScript(function () {
/* global document */
document.cookie = 'connect.sid=';
});
});
};