|
1 | 1 | import * as path from 'path'; |
2 | 2 | import * as Mocha from 'mocha'; |
3 | | -import * as glob from 'glob'; |
| 3 | +import * as glob from 'glob-promise'; |
4 | 4 | import { ensureCli } from './ensureCli'; |
5 | 5 | import { env } from 'vscode'; |
6 | 6 |
|
@@ -57,44 +57,39 @@ export async function runTestsInDirectory(testsRoot: string, useCli = false): Pr |
57 | 57 |
|
58 | 58 | await ensureCli(useCli); |
59 | 59 |
|
60 | | - return new Promise((resolve, reject) => { |
61 | | - console.log(`Adding test cases and helpers from ${testsRoot}`); |
62 | | - glob('**/**.js', { cwd: testsRoot }, (err, files) => { |
63 | | - if (err) { |
64 | | - return reject(err); |
65 | | - } |
| 60 | + console.log(`Adding test cases and helpers from ${testsRoot}`); |
| 61 | + |
| 62 | + const files = await glob('**/**.js', { cwd: testsRoot }); |
| 63 | + |
| 64 | + // Add test files to the test suite |
| 65 | + files |
| 66 | + .filter(f => f.endsWith('.test.js')) |
| 67 | + .forEach(f => { |
| 68 | + console.log(`Adding test file ${f}`); |
| 69 | + mocha.addFile(path.resolve(testsRoot, f)); |
| 70 | + }); |
66 | 71 |
|
67 | | - try { |
68 | | - // Add test files to the test suite |
69 | | - files |
70 | | - .filter(f => f.endsWith('.test.js')) |
71 | | - .forEach(f => { |
72 | | - console.log(`Adding test file ${f}`); |
73 | | - mocha.addFile(path.resolve(testsRoot, f)); |
74 | | - }); |
75 | 72 |
|
76 | | - // Add helpers. Helper files add global setup and teardown blocks |
77 | | - // for a test run. |
78 | | - files |
79 | | - .filter(f => f.endsWith('.helper.js')) |
80 | | - .forEach(f => { |
81 | | - console.log(`Executing helper ${f}`); |
82 | | - // eslint-disable-next-line @typescript-eslint/no-var-requires |
83 | | - const helper = require(path.resolve(testsRoot, f)).default; |
84 | | - helper(mocha); |
85 | | - }); |
| 73 | + // Add helpers. Helper files add global setup and teardown blocks |
| 74 | + // for a test run. |
| 75 | + files |
| 76 | + .filter(f => f.endsWith('.helper.js')) |
| 77 | + .forEach(f => { |
| 78 | + console.log(`Executing helper ${f}`); |
| 79 | + // eslint-disable-next-line @typescript-eslint/no-var-requires |
| 80 | + const helper = require(path.resolve(testsRoot, f)).default; |
| 81 | + helper(mocha); |
| 82 | + }); |
86 | 83 |
|
87 | | - // Run the mocha test |
88 | | - mocha.run(failures => { |
89 | | - if (failures > 0) { |
90 | | - reject(new Error(`${failures} tests failed.`)); |
91 | | - } else { |
92 | | - resolve(); |
93 | | - } |
94 | | - }); |
95 | | - } catch (err) { |
96 | | - reject(err); |
| 84 | + return new Promise((resolve, reject) => { |
| 85 | + // Run the mocha test |
| 86 | + mocha.run(failures => { |
| 87 | + if (failures > 0) { |
| 88 | + reject(new Error(`${failures} tests failed.`)); |
| 89 | + return; |
97 | 90 | } |
| 91 | + |
| 92 | + resolve(); |
98 | 93 | }); |
99 | 94 | }); |
100 | 95 | } |
0 commit comments