-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathsandbox-loader.js
73 lines (68 loc) · 2.44 KB
/
sandbox-loader.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
'use strict';
const fs = require('fs');
const ncp = require('ncp');
const spawn = require('child_process').spawn;
const spawnSync = require('child_process').spawnSync;
const whichCase = process.argv[2] || 'NULL';
const option = process.argv[3] || 'ngc';
const path = require('path');
const availableCases = getAvailableCases(path.resolve(__dirname, 'tests'));
if (whichCase === 'total') {
for (let i = 0; i < availableCases.length; i++) {
console.log('Start', '[' + availableCases[i] + ']', 'case:');
let testCase = spawnSync('node', ['sandbox-loader.js', availableCases[i]]);
console.log(testCase.stderr.toString('utf8'));
console.log(testCase.stdout.toString('utf8'));
}
process.exit(0);
}
if (availableCases.indexOf(whichCase) === -1) {
console.log('[' + whichCase + ']', 'case is not available');
process.exit(1);
}
const clean = spawn('npm', ['run', 'clean']);
clean.on('close', function (code) {
if (code === 0) {
ncp(path.resolve(__dirname, 'tests', whichCase), 'sandbox', function (error) {
if (error) {
console.log(error);
process.exit(1);
}
fs.writeFileSync('./sandbox/tsconfig.json', fs.readFileSync('tsconfig.json'));
console.log('Test case', '[' + whichCase + ']', 'LOADED');
let commandOptions = ['run', 'sandbox:ngc'];
if (option !== 'ngc' && option === 'ngtools') {
console.log('AoT:', 'True');
console.log('With: @ngtools/webpack');
commandOptions = ['run', 'sandbox:ngtools']
} else if (option === 'jit') {
console.log('AoT:', 'False');
commandOptions = ['run', 'sandbox:jit']
} else {
console.log('AoT:', 'True');
console.log('With: ngc');
}
console.log('Test case', '[' + whichCase + ']', 'BUILDING');
const sandbox = spawn('npm', commandOptions);
sandbox.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
sandbox.on('close', (code) => {
if (code === 0) {
console.log('Test case', '[' + whichCase + ']', 'PASS');
} else {
console.log('Test case', '[' + whichCase + ']', 'FAILED');
}
});
})
}
});
function getAvailableCases(testsPath) {
const files = fs.readdirSync(testsPath, {});
const isDirectory = function(testPath) {
const filePath = path.resolve(testsPath, testPath);
const fileStat = fs.lstatSync(filePath);
return fileStat.isDirectory();
};
return files.filter(isDirectory);
}