forked from mozilla/persona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
executable file
·104 lines (91 loc) · 3.06 KB
/
test
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env node
// a script to RUN TESTS. You can specify WHAT TESTS to run by
// populating an environment variable 'WHAT_TESTS'. Values include:
// * 'front' - frontend unit tests run headlessly (requires phantomjs to be installed)
// * 'back' - backend unit tests with a zero-dependency json db
// * 'back_mysql - backend unit tests against mysql (requires mysql installed)
// * 'all' - of it
const
spawn = require('child_process').spawn,
exec = require('child_process').exec,
rimraf = require('rimraf'),
path = require('path');
// if running tests for backend coverage, remove any prior run's data.
if (process.env.PERSONA_WITH_COVER) {
rimraf.sync(path.join(__dirname, "..", ".coverage_data"));
}
// WHAT TESTS are we running?
var whatTests = [];
if (!process.env['WHAT_TESTS']) {
whatTests = [ 'all' ];
} else {
whatTests.push(process.env['WHAT_TESTS']);
}
if (whatTests[0] == 'all') whatTests = [ 'back_mysql', 'back', 'front' ];
var ec = 0;
var frontend_test_filter = process.env['FRONTEND_TEST_FILTER'] ?
' (filter: ' + process.env['FRONTEND_TEST_FILTER'] + ')' :
'';
function reportCoverage(ec) {
var pathToCover = path.join(__dirname, "..", "node_modules", ".bin", "cover");
var pathToReport = path.join(__dirname, "..", "cover_html");
rimraf.sync(pathToReport);
pathToReport = ['`open file://', pathToReport, '/index.html`'].join('');
exec(pathToCover + ' combine', function(err, stdout, stderr) {
if (err) throw err;
exec(pathToCover + ' report html', function(err, stdout, stderr) {
if (err) throw err;
console.log("\n**\n** Coverage report is available at",
pathToReport, '\n**\n');
process.exit(ec);
});
});
}
function run() {
if (!whatTests.length) {
if (process.env.PERSONA_WITH_COVER) {
return reportCoverage(ec);
}
process.exit(ec);
}
var testName = whatTests.shift();
const availConf = {
front: {
what: "Front end unit tests under PhantomJS" + frontend_test_filter,
node_env: 'test_json',
script: 'test_frontend'
},
back: {
what: "API level unit tests using a JSON database",
node_env: 'test_json',
script: 'test_backend'
},
back_mysql: {
what: "API level unit tests using MySQL",
node_env: 'test_mysql',
script: 'test_backend'
},
selenium: {
what: "Selenium tests against sauce labs",
node_env: 'test_json',
script: 'test_selenium'
}
};
var conf = availConf[testName];
if (!conf) {
console.log('I don\'t know how to run this test: "' + testName + '"');
console.log('valid choices include:', Object.keys(availConf).join(', '));
ec = 1;
return run();
}
console.log(">>> Now Running:", conf.what);
process.env['NODE_ENV'] = conf.node_env;
var kid = spawn(path.join(__dirname, conf.script));
kid.stdout.on('data', function(d) { process.stdout.write(d); });
kid.stderr.on('data', function(d) { process.stderr.write(d); });
kid.on('exit', function(code) {
if (code) ec = code;
run();
});
}
run();