This commit is contained in:
Pine Wu
2019-05-23 16:00:20 -07:00
parent cb83f3909e
commit 794212ec5c
7 changed files with 99 additions and 48 deletions

View File

@ -21,7 +21,7 @@
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/testRunner"
"--extensionTestsPath=${workspaceFolder}/out/test/suite"
],
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
"preLaunchTask": "npm: watch"

View File

@ -27,12 +27,15 @@
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"lint": "tslint -p ./",
"watch": "tsc -watch -p ./"
"watch": "tsc -watch -p ./",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.6",
"@types/node": "^8.10.25",
"@types/vscode": "^1.32.0",
"glob": "^7.1.4",
"mocha": "^6.1.4",
"source-map-support": "^0.5.12",
"tslint": "^5.16.0",

View File

@ -3,10 +3,10 @@ import * as Mocha from 'mocha';
export function run(testsRoot: string, cb: (error: any, failures?: number) => void): void {
let mocha = new Mocha({
ui: 'tdd',
reporter: 'nyan'
ui: 'tdd'
});
mocha.useColors(true)
mocha.reporter('spec');
mocha.useColors(true);
const files = [path.resolve(__dirname, '../../out/test/suite/extension.test.js')];
@ -26,12 +26,14 @@ export function run(testsRoot: string, cb: (error: any, failures?: number) => vo
return true;
};
mocha.run(failures => {
cb(null, failures);
}).on('test end', () => {
process.stdout.write = processStdoutWrite;
console.log('\n' + stdOutMessages + '\n');
})
mocha
.run(failures => {
cb(null, failures);
})
.on('test end', () => {
process.stdout.write = processStdoutWrite;
console.log('\n' + stdOutMessages + '\n');
});
} catch (err) {
cb(err);
}

View File

@ -1,25 +1,25 @@
import * as path from 'path'
import * as path from 'path';
import { runTests } from 'vscode-test'
import { runTests } from 'vscode-test';
async function go() {
try {
const extensionPath = path.resolve(__dirname, '../../')
const testRunnerPath = path.resolve(__dirname, './testRunner.js')
const testWorkspace = path.resolve(__dirname, '../../test/suite/fixture')
try {
const extensionPath = path.resolve(__dirname, '../../');
const testRunnerPath = path.resolve(__dirname, './suite');
const testWorkspace = path.resolve(__dirname, '../../test/suite/fixture');
/**
* Basic usage
*/
await runTests({
extensionPath,
testRunnerPath,
testWorkspace
})
} catch (err) {
console.error('Failed to run tests')
process.exit(1)
}
await runTests({
// The folder containing the Extension Manifest package.json
extensionPath,
// The path to test runner
testRunnerPath,
// The workspace to open on starting up VS Code
testWorkspace
});
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}
go()
go();

View File

@ -1,28 +1,18 @@
import * as assert from 'assert';
import { before } from 'mocha';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../extension';
// Defines a Mocha test suite to group tests of similar kind together
suite('Extension Tests', function() {
// Defines a Mocha unit test
test('Something 1', function() {
vscode.window.showInformationMessage('test')
suite('Extension Test Suite', () => {
before(() => {
vscode.window.showInformationMessage('Start all tests.');
});
test('Sample test', () => {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
});
// test('Something 1', function() { assert.equal(1, 2); });
// test('Something 1', function() { assert.equal(1, 1); });
// test('Something 1', function() { assert.equal(1, 2); });
// test('Something 1', function() { assert.equal(1, 2); });
// test('Something 1', function() { assert.equal(1, 2); });
// test('Something 1', function() { assert.equal(1, 1); });
// test('Something 1', function() { assert.equal(1, 2); });
// test('Something 1', function() { assert.equal(1, 2); });
// test('Something 1', function() { assert.equal(1, 1); });
// test('Something 1', function() { assert.equal(1, 2); });
// test('Something 1', function() { assert.equal(1, 2); });
});

View File

@ -0,0 +1,32 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';
export function run(testsRoot: string, cb: (error: any, failures?: number) => void): void {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
timeout: 10000
});
mocha.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);
}
});
}

View File

@ -18,11 +18,35 @@
esutils "^2.0.2"
js-tokens "^4.0.0"
"@types/events@*":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==
"@types/glob@^7.1.1":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
integrity sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==
dependencies:
"@types/events" "*"
"@types/minimatch" "*"
"@types/node" "*"
"@types/minimatch@*":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==
"@types/mocha@^5.2.6":
version "5.2.6"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.6.tgz#b8622d50557dd155e9f2f634b7d68fd38de5e94b"
integrity sha512-1axi39YdtBI7z957vdqXI4Ac25e7YihYQtJa+Clnxg1zTJEaIRbndt71O3sP4GAMgiAm0pY26/b9BrY4MR/PMw==
"@types/node@*":
version "12.0.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.0.2.tgz#3452a24edf9fea138b48fad4a0a028a683da1e40"
integrity sha512-5tabW/i+9mhrfEOUcLDu2xBPsHJ+X5Orqy9FKpale3SjDA17j5AEpYq5vfy3oAeAHGcvANRCO3NV3d2D6q3NiA==
"@types/node@^8.10.25":
version "8.10.48"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.48.tgz#e385073561643a9ba6199a1985ffc03530f90781"
@ -320,7 +344,7 @@ glob@7.1.3:
once "^1.3.0"
path-is-absolute "^1.0.0"
glob@^7.1.1:
glob@^7.1.1, glob@^7.1.4:
version "7.1.4"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255"
integrity sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==