-
Notifications
You must be signed in to change notification settings - Fork 39
/
make.js
105 lines (91 loc) · 3.6 KB
/
make.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
const fs = require('fs');
const path = require('path');
const util = require('./common-npm-packages/build-scripts/util');
const minimist = require('minimist');
const ignoredFolders = ['build-scripts', '.git', '_download', 'node_modules'];
const defaultTestSuite = 'L0';
const predefinedFlags = {
boolean: [
'build',
'test'
],
string: [
'suite'
]
};
const options = minimist(process.argv, predefinedFlags)
const testResultsPath = path.join(__dirname, 'test-results');
const mochaReporterPath = path.join(__dirname, 'common-npm-packages', 'build-scripts', 'junit-spec-reporter.js');
const coverageBaseNameJson = 'coverage-final.json';
const summaryBaseName = 'coverage-summary.json';
const printLabel = (name) => {
console.log('\n----------------------------------');
console.log(name);
console.log('----------------------------------');
}
const buildPsTestHelpers = () => {
console.log('Building Tests');
util.cd('Tests');
util.run('npm install');
util.run(path.join('node_modules', '.bin', 'tsc'));
util.cd('..');
}
if (options.build) {
buildPsTestHelpers();
console.log('\nBuilding shared npm packages');
util.cd('common-npm-packages');
fs.readdirSync('./', { encoding: 'utf-8' }).forEach(child => {
if (fs.statSync(child).isDirectory() && !ignoredFolders.includes(child)) {
printLabel(child);
util.cd(child);
util.run('npm install');
util.run('npm run build');
util.cd('..');
}
});
}
if (options.test) {
const gitkeepName = '.gitkeep';
const junitPath = path.join(testResultsPath, 'junit');
const coveragePath = path.join(testResultsPath, 'coverage');
process.env['SYSTEM_DEBUG'] = true;
console.log('Testing shared npm packages');
util.cd('common-npm-packages');
const suite = options.suite || defaultTestSuite;
let testsFailed = false;
util.cleanFolder(testResultsPath, [gitkeepName]);
const startPath = process.cwd();
fs.readdirSync(startPath, { encoding: 'utf-8' }).forEach(child => {
if (fs.statSync(child).isDirectory() && !ignoredFolders.includes(child)) {
printLabel(child);
const buildPath = path.join(startPath, child, '_build');
if (fs.existsSync(buildPath)) {
const testPath = path.join(buildPath, 'Tests', `${suite}.js`);
if (fs.existsSync(path.join(testPath))) {
try {
const suitName = `${child}-suite`;
const mochaOptions = util.createMochaOptions(mochaReporterPath, junitPath, suitName);
util.run(`nyc --all --src ${buildPath} --report-dir ${coveragePath} mocha ${mochaOptions} ${testPath}`, true);
util.renameFile(coveragePath, coverageBaseNameJson, `${child}-coverage.json`);
} catch (err) {
testsFailed = true;
}
} else {
console.log('No tests found for the package');
}
} else {
throw new Error('Package has not been built');
}
}
});
try {
util.rm(path.join(coveragePath, summaryBaseName));
util.run(`nyc merge ${coveragePath} ${path.join(testResultsPath, 'merged-coverage.json')}`, true);
util.run(`nyc report -t ${testResultsPath} --report-dir ${testResultsPath} --reporter=cobertura`, true);
} catch (e) {
console.log('Error while generating coverage report')
}
if (testsFailed) {
throw new Error('Tests failed!');
}
}