Skip to content

Commit ef242e4

Browse files
authored
Update VSIX tests to be compliant with latest glob dependency (#1248)
* update tests * refactor
1 parent 241c87f commit ef242e4

File tree

6 files changed

+39
-67
lines changed

6 files changed

+39
-67
lines changed

servers/Azure.Mcp.Server/vscode/src/test/suite/allTests.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,22 @@
33

44
import * as path from 'path';
55
import * as Mocha from 'mocha';
6-
import * as glob from 'glob';
6+
import { glob } from 'glob';
77

88
export function run(): Promise<void> {
99
const opts: Mocha.MochaOptions = {
1010
ui: 'tdd',
1111
color: true,
1212
timeout: process.env.TEST_TIMEOUT ?? "10s"
1313
};
14-
14+
1515
const mocha = new Mocha(opts);
1616

1717
const testsRoot = path.resolve(__dirname, '..');
1818

1919
return new Promise((c, e) => {
20-
glob('suite/**/**.test.js', { cwd: testsRoot }, (err, files) => {
21-
if (err) {
22-
return e(err);
23-
}
24-
25-
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
20+
glob('suite/**/**.test.js', { cwd: testsRoot }).then((files: string[]) => {
21+
files.forEach((f: string) => mocha.addFile(path.resolve(testsRoot, f)));
2622

2723
try {
2824
mocha.run(failures => {
@@ -36,6 +32,6 @@ export function run(): Promise<void> {
3632
console.error(err);
3733
e(err);
3834
}
39-
});
35+
}).catch(e);
4036
});
4137
}

servers/Azure.Mcp.Server/vscode/src/test/suite/unitTests.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as path from 'path';
55
import * as Mocha from 'mocha';
6-
import * as glob from 'glob';
6+
import { glob } from 'glob';
77

88
export function run(): Promise<void> {
99
const opts: Mocha.MochaOptions = {
@@ -14,21 +14,16 @@ export function run(): Promise<void> {
1414
};
1515

1616
const mocha = new Mocha(opts);
17-
1817
const testsRoot = path.resolve(__dirname, '..');
1918

2019
return new Promise((c, e) => {
2120
// Find both legacy and new-style unit tests
22-
glob('suite/unit/**/**.test.js', { cwd: testsRoot }, (err, suiteFiles) => {
23-
if (err) {
24-
return e(err);
25-
}
26-
glob('*.unit.test.js', { cwd: testsRoot }, (err2, unitFiles) => {
27-
if (err2) {
28-
return e(err2);
29-
}
30-
const files = [...suiteFiles, ...unitFiles];
31-
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
21+
Promise.all([
22+
glob('suite/unit/**/**.test.js', { cwd: testsRoot }),
23+
glob('*.unit.test.js', { cwd: testsRoot })
24+
]).then(([suiteFiles, unitFiles]: [string[], string[]]) => {
25+
const files = [...suiteFiles, ...unitFiles];
26+
files.forEach((f: string) => mocha.addFile(path.resolve(testsRoot, f)));
3227
try {
3328
mocha.run(failures => {
3429
if (failures > 0) {
@@ -41,7 +36,6 @@ export function run(): Promise<void> {
4136
console.error(err);
4237
e(err);
4338
}
44-
});
45-
});
39+
}).catch(e);
4640
});
4741
}

servers/Fabric.Mcp.Server/vscode/src/test/suite/allTests.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,22 @@
33

44
import * as path from 'path';
55
import * as Mocha from 'mocha';
6-
import * as glob from 'glob';
6+
import { glob } from 'glob';
77

88
export function run(): Promise<void> {
99
const opts: Mocha.MochaOptions = {
1010
ui: 'tdd',
1111
color: true,
1212
timeout: process.env.TEST_TIMEOUT ?? "10s"
1313
};
14-
14+
1515
const mocha = new Mocha(opts);
1616

1717
const testsRoot = path.resolve(__dirname, '..');
1818

1919
return new Promise((c, e) => {
20-
glob('suite/**/**.test.js', { cwd: testsRoot }, (err, files) => {
21-
if (err) {
22-
return e(err);
23-
}
24-
25-
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
20+
glob('suite/**/**.test.js', { cwd: testsRoot }).then((files: string[]) => {
21+
files.forEach((f: string) => mocha.addFile(path.resolve(testsRoot, f)));
2622

2723
try {
2824
mocha.run(failures => {
@@ -36,6 +32,6 @@ export function run(): Promise<void> {
3632
console.error(err);
3733
e(err);
3834
}
39-
});
35+
}).catch(e);
4036
});
4137
}

servers/Fabric.Mcp.Server/vscode/src/test/suite/unitTests.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as path from 'path';
55
import * as Mocha from 'mocha';
6-
import * as glob from 'glob';
6+
import { glob } from 'glob';
77

88
export function run(): Promise<void> {
99
const opts: Mocha.MochaOptions = {
@@ -19,16 +19,12 @@ export function run(): Promise<void> {
1919

2020
return new Promise((c, e) => {
2121
// Find both legacy and new-style unit tests
22-
glob('suite/unit/**/**.test.js', { cwd: testsRoot }, (err, suiteFiles) => {
23-
if (err) {
24-
return e(err);
25-
}
26-
glob('*.unit.test.js', { cwd: testsRoot }, (err2, unitFiles) => {
27-
if (err2) {
28-
return e(err2);
29-
}
30-
const files = [...suiteFiles, ...unitFiles];
31-
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
22+
Promise.all([
23+
glob('suite/unit/**/**.test.js', { cwd: testsRoot }),
24+
glob('*.unit.test.js', { cwd: testsRoot })
25+
]).then(([suiteFiles, unitFiles]: [string[], string[]]) => {
26+
const files = [...suiteFiles, ...unitFiles];
27+
files.forEach((f: string) => mocha.addFile(path.resolve(testsRoot, f)));
3228
try {
3329
mocha.run(failures => {
3430
if (failures > 0) {
@@ -41,7 +37,6 @@ export function run(): Promise<void> {
4137
console.error(err);
4238
e(err);
4339
}
44-
});
45-
});
40+
}).catch(e);
4641
});
4742
}

servers/Template.Mcp.Server/vscode/src/test/suite/allTests.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,22 @@
33

44
import * as path from 'path';
55
import * as Mocha from 'mocha';
6-
import * as glob from 'glob';
6+
import { glob } from 'glob';
77

88
export function run(): Promise<void> {
99
const opts: Mocha.MochaOptions = {
1010
ui: 'tdd',
1111
color: true,
1212
timeout: process.env.TEST_TIMEOUT ?? "10s"
1313
};
14-
14+
1515
const mocha = new Mocha(opts);
1616

1717
const testsRoot = path.resolve(__dirname, '..');
1818

1919
return new Promise((c, e) => {
20-
glob('suite/**/**.test.js', { cwd: testsRoot }, (err, files) => {
21-
if (err) {
22-
return e(err);
23-
}
24-
25-
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
20+
glob('suite/**/**.test.js', { cwd: testsRoot }).then((files: string[]) => {
21+
files.forEach((f: string) => mocha.addFile(path.resolve(testsRoot, f)));
2622

2723
try {
2824
mocha.run(failures => {
@@ -36,6 +32,6 @@ export function run(): Promise<void> {
3632
console.error(err);
3733
e(err);
3834
}
39-
});
35+
}).catch(e);
4036
});
4137
}

servers/Template.Mcp.Server/vscode/src/test/suite/unitTests.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as path from 'path';
55
import * as Mocha from 'mocha';
6-
import * as glob from 'glob';
6+
import { glob } from 'glob';
77

88
export function run(): Promise<void> {
99
const opts: Mocha.MochaOptions = {
@@ -19,16 +19,12 @@ export function run(): Promise<void> {
1919

2020
return new Promise((c, e) => {
2121
// Find both legacy and new-style unit tests
22-
glob('suite/unit/**/**.test.js', { cwd: testsRoot }, (err, suiteFiles) => {
23-
if (err) {
24-
return e(err);
25-
}
26-
glob('*.unit.test.js', { cwd: testsRoot }, (err2, unitFiles) => {
27-
if (err2) {
28-
return e(err2);
29-
}
30-
const files = [...suiteFiles, ...unitFiles];
31-
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
22+
Promise.all([
23+
glob('suite/unit/**/**.test.js', { cwd: testsRoot }),
24+
glob('*.unit.test.js', { cwd: testsRoot })
25+
]).then(([suiteFiles, unitFiles]: [string[], string[]]) => {
26+
const files = [...suiteFiles, ...unitFiles];
27+
files.forEach((f: string) => mocha.addFile(path.resolve(testsRoot, f)));
3228
try {
3329
mocha.run(failures => {
3430
if (failures > 0) {
@@ -41,7 +37,6 @@ export function run(): Promise<void> {
4137
console.error(err);
4238
e(err);
4339
}
44-
});
45-
});
40+
}).catch(e);
4641
});
4742
}

0 commit comments

Comments
 (0)