Skip to content

Commit eeeedd3

Browse files
committed
Simplify tests and fix teardown
- Use the vscode-test command line instead of a separate script in order to run the tests. - Add proper teardown to some test suites that didn't have it Switching over to the vscode-test cli changed the order in which the tests are executed. Since some tests didn't have proper teardown, the following tests in the suite started failing. By adding the proper teardown (and in one case changing the expected result) I got them passing again. Signed-off-by: David Thompson <davthomp@redhat.com> Reduce expected number of calls to get tests passing It used to be 2 because a document from a previous test was left open, which triggered the update twice (once during the direct invocation, and once during the faked document changed notification). Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 2bea998 commit eeeedd3

File tree

13 files changed

+67
-145
lines changed

13 files changed

+67
-145
lines changed

.vscode-test.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { defineConfig } from '@vscode/test-cli';
22

33
export default defineConfig({
4-
files: 'out/smoke-test/**/*.test.js',
5-
workspaceFolder: './smoke-test/',
4+
files: 'out/test/**/*.test.js',
5+
workspaceFolder: '.',
6+
mocha: {
7+
ui: 'bdd',
8+
timeout: 10_000,
9+
},
610
});

.vscode-test.smoketest.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from '@vscode/test-cli';
2+
3+
export default defineConfig({
4+
files: 'out/smoke-test/**/*.test.js',
5+
workspaceFolder: './smoke-test/',
6+
mocha: {
7+
ui: 'bdd'
8+
}
9+
});

.vscode/launch.json

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@
1616
"VSCODE_REDHAT_TELEMETRY_DEBUG":"true"
1717
}
1818
},
19-
{
20-
"name": "Extension Tests",
21-
"type": "extensionHost",
22-
"request": "launch",
23-
"runtimeExecutable": "${execPath}",
24-
"preLaunchTask": "compile test",
25-
"args": [
26-
"--disable-extension=ms-kubernetes-tools.vscode-kubernetes-tools",
27-
"--extensionDevelopmentPath=${workspaceFolder}",
28-
"--extensionTestsPath=${workspaceFolder}/out/test",
29-
"${workspaceRoot}/test/testFixture"
30-
],
31-
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
32-
"env": {
33-
"DEBUG_VSCODE_YAML":"true"
34-
}
35-
},
3619
{
3720
"name": "Launch Web Extension",
3821
"type": "extensionHost",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@
278278
"compile": "webpack --mode none",
279279
"format": "prettier --write .",
280280
"lint": "eslint -c .eslintrc.js --ext .ts src test",
281-
"test": "npm run test-compile && sh scripts/e2e.sh",
281+
"test": "npm run test-compile && npx vscode-test",
282282
"ui-test": "npm run test-compile && extest setup-and-run out/test/ui-test/allTestsSuite.js -c 1.76.2",
283283
"vscode:prepublish": "webpack --mode production && npm run copy-l10n",
284284
"copy-l10n": "cp -r node_modules/yaml-language-server/l10n dist/l10n",
285285
"watch": "webpack --mode development --watch --info-verbosity verbose",
286286
"test-compile": "npm run clean && tsc -p ./ && webpack --mode development && npm run copy-l10n",
287-
"smoke-test": "npm run test-compile && vscode-test smoke-test/*",
287+
"smoke-test": "npm run test-compile && vscode-test --config .vscode-test.smoketest.mjs",
288288
"compile-smoke-test-web": "webpack --config smoke-test/webpack.config",
289289
"smoke-test-web": "npm run compile-smoke-test-web && vscode-test-web --extensionDevelopmentPath=. --extensionTestsPath=./out/smoke-test/smoke-test-runner.js ./smoke-test",
290290
"run-in-chromium": "npm run compile && vscode-test-web --browserType=chromium --extensionDevelopmentPath=. ."

scripts/e2e.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

smoke-test/smoke-test-runner.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
require('mocha/mocha');
22

33
export function run(): Promise<void> {
4+
return new Promise((c, e) => {
5+
mocha.setup({
6+
ui: 'bdd',
7+
reporter: undefined,
8+
});
49

5-
return new Promise((c, e) => {
6-
mocha.setup({
7-
ui: 'tdd',
8-
reporter: undefined
9-
});
10+
// bundles all files in the current directory matching `*.test`
11+
const importAll = (r: __WebpackModuleApi.RequireContext) => r.keys().forEach(r);
12+
importAll(require.context('.', true, /\.test$/));
1013

11-
// bundles all files in the current directory matching `*.test`
12-
const importAll = (r: __WebpackModuleApi.RequireContext) => r.keys().forEach(r);
13-
importAll(require.context('.', true, /\.test$/));
14-
15-
try {
16-
// Run the mocha test
17-
mocha.run(failures => {
18-
if (failures > 0) {
19-
e(new Error(`${failures} tests failed.`));
20-
} else {
21-
c();
22-
}
23-
});
24-
} catch (err) {
25-
console.error(err);
26-
e(err);
27-
}
28-
});
29-
}
14+
try {
15+
// Run the mocha test
16+
mocha.run((failures) => {
17+
if (failures > 0) {
18+
e(new Error(`${failures} tests failed.`));
19+
} else {
20+
c();
21+
}
22+
});
23+
} catch (err) {
24+
console.error(err);
25+
e(err);
26+
}
27+
});
28+
}

smoke-test/smoke.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { assert } from 'chai';
22
import * as vscode from 'vscode';
33
import { URI } from 'vscode-uri';
44

5-
suite('Smoke test suite', function () {
5+
describe('Smoke test suite', function () {
66
this.timeout(10_000);
77

88
// diagnostics take some time to appear; the language server must be started and respond to file open event
@@ -12,12 +12,14 @@ suite('Smoke test suite', function () {
1212

1313
let schemaInstanceUri: URI;
1414

15-
this.beforeAll(async function () {
15+
before(async function () {
1616
const workspaceUri = vscode.workspace.workspaceFolders[0].uri;
17-
schemaInstanceUri = workspaceUri.with({ path: workspaceUri.path + (workspaceUri.path.endsWith('/') ? '' : '/') + SCHEMA_INSTANCE_NAME });
17+
schemaInstanceUri = workspaceUri.with({
18+
path: workspaceUri.path + (workspaceUri.path.endsWith('/') ? '' : '/') + SCHEMA_INSTANCE_NAME,
19+
});
1820
});
1921

20-
test('instance has right diagnostics', async function () {
22+
it('has right diagnostics when schema is referenced through a comment', async function () {
2123
const textDocument = await vscode.workspace.openTextDocument(schemaInstanceUri);
2224
await vscode.window.showTextDocument(textDocument);
2325
await new Promise((resolve) => setTimeout(resolve, DIAGNOSTICS_DELAY));

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*--------------------------------------------------------------------------------------------*/
77
'use strict';
88

9-
import { workspace, ExtensionContext, extensions, window, commands, Uri, l10n } from 'vscode';
9+
import { workspace, ExtensionContext, extensions, window, commands, Uri } from 'vscode';
1010
import {
1111
CommonLanguageClient,
1212
LanguageClientOptions,

test/completion.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ describe('Completion should work in multiple different scenarios', () => {
1616
await resetSettings('schemaStore.enable', true);
1717
});
1818

19+
after(async () => {
20+
vscode.window.tabGroups.close(vscode.window.tabGroups.activeTabGroup);
21+
});
22+
1923
it('completion works with local schema', async () => {
2024
await activate(docUri);
2125
const schemaPath = path.join(__dirname, '..', '..', 'test', 'testFixture', 'schemas', 'basic_completion_schema.json');

test/index.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)