-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathruntests.js
executable file
·113 lines (96 loc) · 3.11 KB
/
runtests.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
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
105
106
107
108
109
110
111
112
113
#!/usr/bin/env node
// ----------------------------------------------------------------------------
// See LICENSE.md file
// ----------------------------------------------------------------------------
const fs = require('fs');
const path = require('path');
const { exec, execSync } = require('child_process');
const colors = require('colors/safe');
const rimraf = require('rimraf');
const isFolder = dir => fs.lstatSync(dir).isDirectory();
const getTests = function (srcPath) {
if (process.argv.length > 2) {
return [{
path: path.join(__dirname, process.argv[2]),
name: process.argv[2]
}];
}
var getFolders = dir => fs.readdirSync(dir)
.map(name => path.join(path.resolve(dir), name)).filter(isFolder);
var tests = getFolders(srcPath);
tests.forEach((value, index, array) => array[index] = {
path: value,
name: path.basename(value)
});
return tests;
};
var totals = {
fail: 0,
success: 0
};
var tests = getTests(process.cwd());
var testFinished = false;
var currentTest;
function applyChanges(txt) {
var pathsep = path.sep;
txt = txt.replace(/\$\{UTILS_RUN\.JS\}/g, `node ..${pathsep}utils${pathsep}run.js`);
txt = txt.replace(/\$\{UTILS_BASELINE\.JS\}/g, `node ..${pathsep}utils${pathsep}baseline.js`);
return txt;
}
function runTest(test) {
var batchFile = path.join(test.path, 'run.batch');
if (!fs.existsSync(batchFile)) {
runNextTest();
return; // this folder is not a test folder;
}
var txt = (fs.readFileSync(batchFile) + '');
txt = applyChanges(txt);
console.log(colors.bold('running'), txt);
rimraf.sync(test.path);
try {
execSync(`git checkout ${test.path} && cd ${test.path} && ${txt}`, {stdio:[0,1,2]});
totals.success++;
console.log(' -', colors.bold('pass'), currentTest.name);
} catch(err) {
totals.fail++;
console.log(' -', colors.bold('failed'), currentTest.name);
console.error(err.message);
process.exit(1);
}
runNextTest();
}
function runNextTest() {
if (tests.length > 0) {
currentTest = tests.pop();
runTest(currentTest);
} else {
testFinished = true;
}
}
console.log(' -', 'this will take a while...\n');
var prc = exec('docker pull azureiot/iotz 2>&1', function(error) {
if (error) {
if ((error + '').indexOf('Client.Timeout exceeded while awaiting headers') > 0) {
console.error(colors.bold('Restarting Docker may help to solve this issue'));
} else {
console.error(colors.bold('have you installed Docker?'));
if ((error + '').indexOf('Service Unavailable') > 0) {
console.error('You might have a problem with your network connection as well.\n');
}
}
process.exit(1);
}
runNextTest();
var globInterval = setInterval(function() {
if (testFinished) {
clearInterval(globInterval);
console.log(colors.bold('\nTest run is finished.\n'));
console.log(' -', colors.red ('total failed'), totals.fail);
console.log(' -', colors.bold('total pass'), totals.success);
console.log(' -', colors.bold('total'), totals.success + totals.fail);
}
});
});
prc.stdout.on('data', function (data) {
process.stdout.write(data);
});