Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
Use vscode-test rather than vscode module for extension testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Jun 28, 2019
1 parent a565a2a commit d4f8ffc
Show file tree
Hide file tree
Showing 10 changed files with 816 additions and 1,781 deletions.
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.vscode/**
.vscode-test/**
fixtures/**
test/**
out/test/**
src/**
.gitignore
Expand Down
2,485 changes: 736 additions & 1,749 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
"onLanguage:rust",
"workspaceContains:Cargo.toml"
],
"main": "./out/extension.js",
"main": "./out/src/extension.js",
"scripts": {
"vscode:prepublish": "npm run check:version && npm run lint && npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"lint": "tslint --config ./tslint.json './src/**/*.ts'",
"test": "npm run compile && node ./node_modules/vscode/bin/test",
"test": "node ./out/test/runTest.js",
"prettier": "prettier **/*.ts",
"check:version": "node cmd/check-version.js",
"installDevExtension": "npm install && ./node_modules/.bin/vsce package -o ./out/rls-vscode-dev.vsix && code --install-extension ./out/rls-vscode-dev.vsix"
Expand All @@ -53,15 +53,18 @@
"vscode-languageclient": "^4.3.0"
},
"devDependencies": {
"@types/mocha": "^2.2.43",
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.6",
"@types/node": "~10.1.0",
"@types/vscode": "^1.31.0",
"glob": "^7.1.4",
"mocha": "^6.1.4",
"prettier": "^1.16.4",
"tslint": "^5.14.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.0.0",
"vsce": "^1.63.0",
"vscode": "^1.1.30"
"vscode-test": "^0.4.3"
},
"contributes": {
"languages": [
Expand Down
24 changes: 0 additions & 24 deletions src/test/index.ts

This file was deleted.

36 changes: 36 additions & 0 deletions test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
//
// This file is providing the test runner to use when running extension tests.
// By default the test runner in use is Mocha based.
//
// You can provide your own test runner if you want to override it by exporting
// a function run(testsRoot: string, clb: (error: Error, failures?: number) => void): void
// that the extension host can call to run the tests. The test runner is expected to use console.log
// to report the results back to the caller. When the tests are finished, return
// a possible error to the callback or null if none.

// tslint:disable-next-line: no-submodule-imports
// import * as testRunner from 'vscode/lib/testrunner';

import * as path from 'path';
import { runTests } from 'vscode-test';

(async () => {
const extensionPath = path.resolve(__dirname, '../../');
const testRunnerPath = path.resolve(__dirname, './suite');

await runTests({
extensionPath,
testRunnerPath,
});
})();

// // You can directly control Mocha options by configuring the test runner below
// // See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options
// // for more info
// testRunner.configure({
// ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
// useColors: true, // colored output from test results
// });
// module.exports = run;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as vscode from 'vscode';
// tslint:disable-next-line: no-duplicate-imports
import { Uri } from 'vscode';

const fixtureDir = path.resolve(path.join(__dirname, '..', '..', 'fixtures'));
const fixtureDir = path.resolve(path.join(__dirname, '..', '..', '..', 'fixtures'));

suite('Extension Tests', () => {
test('cargo tasks are auto-detected', async () => {
Expand Down
32 changes: 32 additions & 0 deletions test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as glob from 'glob';
import * as Mocha from 'mocha';
import * as path from 'path';

export function run(
testsRoot: string,
// tslint:disable-next-line: no-any
cb: (error: any, failures?: number) => void,
): void {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
}).useColors(true);

glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return cb(err);
}

// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));

try {
// Run the mocha test
mocha.run(failures => {
cb(null, failures);
});
} catch (err) {
cb(err);
}
});
}
2 changes: 1 addition & 1 deletion src/test/rustup.test.ts → test/suite/rustup.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'assert';
import * as child_process from 'child_process';

import * as rustup from '../rustup';
import * as rustup from '../../src/rustup';

// We need to ensure that rustup works and is installed
const rustupVersion = child_process.execSync('rustup --version').toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';

import * as wslpath from '../../utils/wslpath';
import * as wslpath from '../../../src/utils/wslpath';

function mkConverterCheck(converter: (arg: string) => string) {
return (from: string, to: string) => assert.equal(converter(from), to);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"rootDir": "src",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src", "test"],
"exclude": [
"node_modules",
".vscode-test"
Expand Down

0 comments on commit d4f8ffc

Please sign in to comment.