Skip to content

Commit e4a04d0

Browse files
author
Amit Joshi
committed
Add common integration tests and update workflows
- Introduced new integration tests for Server API autocomplete functionality. - Added a new task for running common integration tests in tasks.json. - Updated PullRequest.yml to include a job for running common integration tests. - Enhanced gulpfile.mjs to support common integration tests. - Created runTest.ts and index.ts for managing and executing integration tests.
1 parent 6c82cbd commit e4a04d0

File tree

7 files changed

+120
-3
lines changed

7 files changed

+120
-3
lines changed

.github/workflows/PullRequest.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ jobs:
6969
with:
7070
run: |
7171
npm run test-desktop-int
72+
73+
- name: Run Common integration tests
74+
uses: coactions/setup-xvfb@v1
75+
with:
76+
run: |
77+
npm run test-common-int

.vscode/tasks.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
"problemMatcher": [],
3030
"label": "Run Integration Tests: VS Code Web"
3131
},
32+
{
33+
"type": "npm",
34+
"script": "test-common-int",
35+
"group": "test",
36+
"problemMatcher": [],
37+
"label": "Run Integration Tests: Common"
38+
},
3239
{
3340
"type": "npm",
3441
"script": "test",

gulpfile.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ function compileIntegrationTests() {
216216
// since "dom" overlaps with "webworker" we need to overwrite the lib property.
217217
// This is a known ts issue (bot being able to have both webworker and dom): https://github.com/microsoft/TypeScript/issues/20595
218218
lib: ["es2019", "dom", "dom.iterable", "es2020"],
219+
// Skip checking .d.ts files from dependencies that may require newer TS features
220+
skipLibCheck: true,
219221
});
220222
return gulp.src(["src/**/*.ts"]).pipe(tsProject()).pipe(gulp.dest("out"));
221223
}
@@ -257,6 +259,17 @@ const testDesktopIntegration = gulp.series(copyTestNugetPackages, compileIntegra
257259
// tests that require vscode-electron (which requires a display or xvfb)
258260
const testDesktopInt = gulp.series(testDesktopIntegration);
259261

262+
/**
263+
* Tests the common integration tests after transpiling the source files to /out
264+
*/
265+
const testCommonIntegration = gulp.series(compileIntegrationTests, async () => {
266+
const testRunner = require("./out/common/test/runTest");
267+
await testRunner.main();
268+
});
269+
270+
// tests that require vscode-electron (which requires a display or xvfb)
271+
const testCommonInt = gulp.series(testCommonIntegration);
272+
260273
async function packageVsix() {
261274
fs.ensureDirSync(packagedir);
262275
await vsce.createVSIX({
@@ -421,6 +434,7 @@ export {
421434
testInt,
422435
testWebInt,
423436
testDesktopInt,
437+
testCommonInt,
424438
packageVsix as package,
425439
dist as ci,
426440
dist,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"test-integration": "node node_modules/gulp/bin/gulp.js testInt",
2626
"test-web-integration": "node node_modules/gulp/bin/gulp.js testWebInt",
2727
"test-desktop-int": "node node_modules/gulp/bin/gulp.js testDesktopInt",
28-
"coverage": "nyc npm run test"
28+
"coverage": "nyc npm run test",
29+
"test-common-int": "node node_modules/gulp/bin/gulp.js testCommonInt"
2930
},
3031
"nyc": {
3132
"extends": "@istanbuljs/nyc-config-typescript",

src/common/intellisense/test/ServerApiAutocomplete.test.ts renamed to src/common/test/integration/ServerApiAutocomplete.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as assert from 'assert';
77
import * as vscode from 'vscode';
8-
import { ServerApiCompletionProvider, ServerApiDefinitions } from '../ServerApiCompletionProvider';
8+
import { ServerApiCompletionProvider, ServerApiDefinitions } from '../../intellisense';
99

1010
/**
1111
* Test suite for Server API autocomplete functionality
@@ -233,7 +233,7 @@ suite('Server API Autocomplete Tests', () => {
233233
language: 'javascript'
234234
});
235235

236-
const position = new vscode.Position(0, 33);
236+
const position = new vscode.Position(0, document.lineAt(0).range.end.character);
237237
const completions = provider.provideCompletionItems(document, position);
238238

239239
assert.ok(Array.isArray(completions));
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*/
5+
6+
import * as path from "path";
7+
import Mocha from "mocha";
8+
import glob from "glob";
9+
import * as vscode from "vscode";
10+
11+
async function addTests(): Promise<void> {
12+
// Ensure the dev-mode extension is activated
13+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14+
await vscode.extensions
15+
.getExtension("microsoft-IsvExpTools.powerplatform-vscode")!
16+
.activate();
17+
18+
// Create the mocha test
19+
const mocha = new Mocha({
20+
ui: "tdd",
21+
color: true,
22+
});
23+
24+
const testsRoot = path.resolve(__dirname, "..");
25+
26+
return new Promise((resolve, reject) => {
27+
glob("**/**.test.js", { cwd: testsRoot }, (err, files) => {
28+
if (err) {
29+
return reject(err);
30+
}
31+
32+
// Add files to the test suite
33+
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
34+
35+
try {
36+
// Run the mocha test
37+
mocha.run((failures) => {
38+
if (failures > 0) {
39+
reject(new Error(`${failures} tests failed.`));
40+
} else {
41+
resolve();
42+
}
43+
});
44+
} catch (err) {
45+
console.error(err);
46+
reject(err);
47+
}
48+
});
49+
});
50+
}
51+
52+
export async function run(): Promise<void> {
53+
await addTests();
54+
}

src/common/test/runTest.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*/
5+
6+
import * as path from "path";
7+
8+
import { runTests } from "@vscode/test-electron";
9+
10+
async function main() {
11+
try {
12+
// The folder containing the Extension Manifest package.json
13+
// Passed to `--extensionDevelopmentPath`
14+
const extensionDevelopmentPath = path.resolve(__dirname, "../../../../");
15+
16+
// The path to test runner
17+
// Passed to --extensionTestsPath
18+
const extensionTestsPath = path.resolve(
19+
__dirname,
20+
"./integration/index"
21+
);
22+
23+
// Download VS Code, unzip it and run the integration test
24+
await runTests({
25+
version: 'insiders',
26+
extensionDevelopmentPath,
27+
extensionTestsPath
28+
});
29+
} catch (err) {
30+
console.error("Failed to run tests");
31+
process.exit(1);
32+
}
33+
}
34+
35+
exports.main = main;

0 commit comments

Comments
 (0)