-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
66 lines (55 loc) · 1.73 KB
/
test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
// Bootstrap settings and set mode correctly
require('./settings').setMode('test');
var cli = require('cli'),
settings = require('./settings'),
url = require('url');
spawn = require('child_process').spawn;
testing = require('./testing/runner'),
colors = require('colors');
var server;
var test = function() {
//run the tests
testing.run(function(r) {
r.print();
console.log('');
console.log('');
var results = r.results();
console.log('Summary:');
console.log(' Fail: '.red + results.fail);
console.log(' Pass: '.green + results.pass);
console.log(' Unknown: '.yellow + results.unknown);
console.log('');
//kill the server
server.kill();
//manually kill the process
process.exit();
});
}
cli.parse({
showserver: ['s', 'Show server output', 'boolean']
});
cli.main(function(args, opts) {
console.log('Hipsell Server - Test Framework');
console.log('');
//run the test server
var uri = url.parse(settings.serverUri);
server = spawn('node', ['main.js', '--mode=test', '--dbname=test', '--noemail', '--port=' + uri.port, '--host=0.0.0.0']);
server.stderr.on('data', function(data) {
if (opts.showserver)
process.stdout.write(data.toString().grey.inverse);
});
server.stdout.on('data', function(data) {
if (opts.showserver)
process.stdout.write(data.toString().grey);
//run the tests when the server is ready
if (data.toString().match(/Server Ready/)) test();
});
server.on('exit', function() {
console.log('');
console.log('Unexpected Test Server Exit'.red.inverse);
if (!opts.showserver) console.log('Run with -s to show server output'.red.inverse);
console.log('');
process.exit();
});
});