This repository was archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtest.js
64 lines (53 loc) · 1.7 KB
/
test.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
/*jslint node: true */
'use strict';
/**
* Spawns the karma test command.
* @name test
*/
function test(command, argv) {
const logger = require('@blackbaud/skyux-logger');
const Server = require('karma').Server;
const path = require('path');
const glob = require('glob');
const tsLinter = require('./utils/ts-linter');
const configResolver = require('./utils/config-resolver');
argv = argv || process.argv;
argv.command = command;
const karmaConfigUtil = require('karma').config;
const karmaConfigPath = configResolver.resolve(command, argv);
const karmaConfig = karmaConfigUtil.parseConfig(karmaConfigPath);
const specsPath = path.resolve(process.cwd(), 'src/app/**/*.spec.ts');
const specsGlob = glob.sync(specsPath);
let lintResult;
const onRunStart = () => {
lintResult = tsLinter.lintSync();
};
const onRunComplete = () => {
if (lintResult && lintResult.exitCode > 0) {
// Pull the logger out of the execution stream to let it print
// after karma's coverage reporter.
setTimeout(() => {
logger.error('Process failed due to linting errors:');
lintResult.errors.forEach(error => logger.error(error));
}, 10);
}
};
const onExit = (exitCode) => {
if (exitCode === 0) {
if (lintResult) {
exitCode = lintResult.exitCode;
}
}
logger.info(`Karma has exited with ${exitCode}.`);
process.exit(exitCode);
};
if (specsGlob.length === 0) {
logger.info('No spec files located. Skipping test command.');
return onExit(0);
}
const server = new Server(karmaConfig, onExit);
server.on('run_start', onRunStart);
server.on('run_complete', onRunComplete);
server.start();
}
module.exports = test;