Skip to content

Commit ec3355d

Browse files
committed
maint: updated glob API and removed strict
1 parent 9e78b74 commit ec3355d

File tree

3 files changed

+49
-45
lines changed

3 files changed

+49
-45
lines changed

src/lib/glob-paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class GlobPaths {
5151
const globIncPaths: string[] = [];
5252
for (const i of globPathsVars) {
5353
// use '/' to match only directories and not files
54-
globIncPaths.push(...glob.sync(i + '/', { strict: false }));
54+
globIncPaths.push(...glob.sync(i + '/'));
5555
}
5656
return globIncPaths;
5757
// if we failed again then our globs are somehow wrong. Abort

test/integration/index.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import path from 'path';
22
import Mocha from 'mocha';
3-
import glob from 'glob';
3+
import { glob } from 'glob';
44

5-
export function run(): Promise<void> {
5+
export async function run(): Promise<void> {
66
// Create the mocha test
77
const mocha = new Mocha({
88
ui: 'tdd',
@@ -11,28 +11,30 @@ export function run(): Promise<void> {
1111

1212
const testsRoot = __dirname;
1313

14-
return new Promise((c, e) => {
15-
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
16-
if (err) {
17-
return e(err);
18-
}
14+
// Use glob promise API to find files
15+
const files = await glob('**/**.test.js', { cwd: testsRoot });
1916

20-
// Add files to the test suite
21-
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
17+
// Add files to the test suite
18+
files.forEach((f: string) => {
19+
mocha.addFile(path.join(testsRoot, f));
20+
});
21+
22+
// Run the mocha test
23+
mocha.timeout(300000);
24+
const runner = mocha.run();
2225

23-
try {
24-
// Run the mocha test
25-
mocha.timeout(900000);
26-
mocha.run(failures => {
27-
if (failures > 0) {
28-
e(new Error(`${failures} tests failed.`));
29-
} else {
30-
c();
31-
}
32-
});
33-
} catch (err) {
34-
e(err);
35-
}
26+
// Wait for the test runner to complete
27+
const failures = await new Promise<number>((resolve, reject) => {
28+
runner.on('end', () => {
29+
resolve(runner.failures);
30+
});
31+
runner.on('fail', (test: Mocha.Test, err: Error) => {
32+
reject(err);
3633
});
3734
});
35+
36+
// Throw an error if there were any test failures
37+
if (failures > 0) {
38+
throw new Error(`${failures} tests failed.`);
39+
}
3840
}

test/unitTest/index.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import path from 'path';
22
import Mocha from 'mocha';
3-
import glob from 'glob';
3+
import { glob } from 'glob';
44

5-
export function run(): Promise<void> {
5+
export async function run(): Promise<void> {
66
// Create the mocha test
77
const mocha = new Mocha({
88
ui: 'tdd',
@@ -11,28 +11,30 @@ export function run(): Promise<void> {
1111

1212
const testsRoot = __dirname;
1313

14-
return new Promise((c, e) => {
15-
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
16-
if (err) {
17-
return e(err);
18-
}
14+
// Use glob promise API to find files
15+
const files = await glob('**/**.test.js', { cwd: testsRoot });
1916

20-
// Add files to the test suite
21-
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
17+
// Add files to the test suite
18+
files.forEach((f: string) => {
19+
mocha.addFile(path.join(testsRoot, f));
20+
});
21+
22+
// Run the mocha test
23+
mocha.timeout(300000);
24+
const runner = mocha.run();
2225

23-
try {
24-
// Run the mocha test
25-
mocha.timeout(300000);
26-
mocha.run(failures => {
27-
if (failures > 0) {
28-
e(new Error(`${failures} tests failed.`));
29-
} else {
30-
c();
31-
}
32-
});
33-
} catch (err) {
34-
e(err);
35-
}
26+
// Wait for the test runner to complete
27+
const failures = await new Promise<number>((resolve, reject) => {
28+
runner.on('end', () => {
29+
resolve(runner.failures);
30+
});
31+
runner.on('fail', (test: Mocha.Test, err: Error) => {
32+
reject(err);
3633
});
3734
});
35+
36+
// Throw an error if there were any test failures
37+
if (failures > 0) {
38+
throw new Error(`${failures} tests failed.`);
39+
}
3840
}

0 commit comments

Comments
 (0)