Skip to content

Commit c3eab14

Browse files
committed
Make sure ci build fails if unit tests fail
1 parent 1e958b9 commit c3eab14

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

test/index.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,36 @@ import * as path from 'path';
77
import { setupTestCoreApi } from './setupTestCoreApi';
88

99
export async function run(): Promise<void> {
10-
setupTestCoreApi();
11-
12-
const options: Mocha.MochaOptions = {
13-
color: true,
14-
reporter: 'mocha-multi-reporters',
15-
reporterOptions: {
16-
reporterEnabled: 'spec, mocha-junit-reporter',
17-
mochaJunitReporterReporterOptions: {
18-
mochaFile: path.resolve(__dirname, '..', '..', 'test', 'unit-test-results.xml'),
10+
try {
11+
setupTestCoreApi();
12+
13+
const options: Mocha.MochaOptions = {
14+
color: true,
15+
reporter: 'mocha-multi-reporters',
16+
reporterOptions: {
17+
reporterEnabled: 'spec, mocha-junit-reporter',
18+
mochaJunitReporterReporterOptions: {
19+
mochaFile: path.resolve(__dirname, '..', '..', 'test', 'unit-test-results.xml'),
20+
},
1921
},
20-
},
21-
};
22+
};
2223

23-
addEnvVarsToMochaOptions(options);
24-
console.log(`Mocha options: ${JSON.stringify(options, undefined, 2)}`);
24+
addEnvVarsToMochaOptions(options);
25+
console.log(`Mocha options: ${JSON.stringify(options, undefined, 2)}`);
2526

26-
const mocha = new Mocha(options);
27+
const mocha = new Mocha(options);
2728

28-
const files: string[] = await globby('**/**.test.js', { cwd: __dirname });
29+
const files: string[] = await globby('**/**.test.js', { cwd: __dirname });
2930

30-
files.forEach((f) => mocha.addFile(path.resolve(__dirname, f)));
31+
files.forEach((f) => mocha.addFile(path.resolve(__dirname, f)));
3132

32-
const failures = await new Promise<number>((resolve) => mocha.run(resolve));
33-
if (failures > 0) {
34-
throw new Error(`${failures} tests failed.`);
33+
const failures = await new Promise<number>((resolve) => mocha.run(resolve));
34+
if (failures > 0) {
35+
throw new Error(`${failures} tests failed.`);
36+
}
37+
} catch (err) {
38+
console.error('Test run failed');
39+
process.exit(1);
3540
}
3641
}
3742

0 commit comments

Comments
 (0)