-
-
Notifications
You must be signed in to change notification settings - Fork 429
/
run-tests.js
71 lines (58 loc) · 2.5 KB
/
run-tests.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
67
68
69
70
71
var fs = require('fs-extra');
var path = require('path');
var rimraf = require('rimraf');
var typescript = require('typescript');
var semver = require('semver');
var execSync = require('child_process').execSync;
// We only want to run comparison tests for the latest released version
var typescriptVersion = parseFloat(semver.major(typescript.version) + '.' + semver.minor(typescript.version));
if (typescriptVersion < 2.6 || typescriptVersion > 2.6) return;
// Parse command line arguments
var saveOutputMode = process.argv.indexOf('--save-output') !== -1;
var indexOfSingleTest = process.argv.indexOf('--single-test');
var singleTestToRun = indexOfSingleTest !== -1 && process.argv[indexOfSingleTest + 1];
var passingTests = [];
var failingTests = [];
// set up new empty staging area
var stagingPath = path.resolve(__dirname, '../../.test');
rimraf.sync(stagingPath);
var start = new Date().getTime();
console.log('\n-------------------------------------------------------------------------\n');
console.log('Starting to run test suites...\n');
var testDir = __dirname;
if (singleTestToRun) {
runTestAsChildProcess(singleTestToRun);
}
else {
// loop through each test directory triggering a test run as child process
fs.readdirSync(testDir)
.filter(function (testName) {
var testPath = path.join(testDir, testName);
return fs.statSync(testPath).isDirectory();
})
.forEach(runTestAsChildProcess);
}
var end = new Date().getTime();
console.log('\n-------------------------------------------------------------------------\n');
console.log((passingTests.length + failingTests.length) + ' test suites took ' + ((end - start) / 1000) + ' seconds to run.\n');
if (passingTests.length > 0) {
console.log(passingTests.length + ' test suite(s) passed.\n\n - ' + passingTests.join('\n - ') + '\n');
}
if (failingTests.length > 0) {
console.log(failingTests.length + ' test suite(s) failed.\n\n - ' + failingTests.join('\n - ') + '\n');
process.exit(1);
}
else {
console.log('No tests failed; congratulations!');
}
// --------------------------------------------------------------
function runTestAsChildProcess(testName) {
try {
var saveOutput = saveOutputMode ? ' --save-output' : '';
var testOutput = execSync('mocha --reporter spec test/comparison-tests/create-and-execute-test.js --test-to-run ' + testName + saveOutput, { stdio: 'inherit' });
passingTests.push(testName);
}
catch (err) {
failingTests.push(testName);
}
}