Skip to content

Commit 301d7c9

Browse files
committed
Add folder
1 parent 7ec0b91 commit 301d7c9

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

src/test/runTests.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as path from 'path';
2+
3+
import { runTests } from '@vscode/test-electron';
4+
5+
async function main() {
6+
try {
7+
// The folder containing the Extension Manifest package.json
8+
// Passed to `--extensionDevelopmentPath`
9+
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
10+
11+
// The path to the extension test script
12+
// Passed to --extensionTestsPath
13+
const extensionTestsPath = path.resolve(__dirname, './suite/index');
14+
15+
// Download VS Code, unzip it and run the integration test
16+
await runTests({ extensionDevelopmentPath, extensionTestsPath });
17+
} catch (err) {
18+
console.error('Failed to run tests');
19+
process.exit(1);
20+
}
21+
}
22+
23+
main();

src/test/suite/extension.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as assert from 'assert';
2+
3+
// You can import and use all API from the 'vscode' module
4+
// as well as import your extension to test it
5+
import * as vscode from 'vscode';
6+
// import * as myExtension from '../../extension';
7+
8+
suite('Extension Test Suite', () => {
9+
test('Extension is present', async () => {
10+
assert.ok(vscode.extensions.getExtension("dantleech.vscode-phpactor"));
11+
});
12+
test('Extension activates', async () => {
13+
await vscode.extensions.getExtension("dantleech.vscode-phpactor")?.activate();
14+
});
15+
});

src/test/suite/index.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
;import * as path from 'path';
2+
import Mocha from 'mocha';
3+
import glob from 'glob';
4+
5+
export function run(): Promise<void> {
6+
// Create the mocha test
7+
const mocha = new Mocha({
8+
ui: 'tdd'
9+
});
10+
11+
const testsRoot = path.resolve(__dirname, '..');
12+
13+
return new Promise((c, e) => {
14+
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
15+
if (err) {
16+
return e(err);
17+
}
18+
19+
// Add files to the test suite
20+
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
21+
22+
try {
23+
// Run the mocha test
24+
mocha.run(failures => {
25+
if (failures > 0) {
26+
e(new Error(`${failures} tests failed.`));
27+
} else {
28+
c();
29+
}
30+
});
31+
} catch (err) {
32+
console.error(err);
33+
e(err);
34+
}
35+
});
36+
});
37+
}

0 commit comments

Comments
 (0)