Skip to content

Commit

Permalink
Merge pull request #170 from microsoft/octref/vscode-test
Browse files Browse the repository at this point in the history
Update vscode-test & @types/vscode usage for microsoft/vscode#71048
  • Loading branch information
aeschli authored May 28, 2019
2 parents 54de9fa + df8f14f commit 2bee60b
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 123 deletions.
15 changes: 9 additions & 6 deletions generators/app/templates/ext-command-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
}]
},
"scripts": {
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test"
"test": "node ./test/runTest.js"
},
"devDependencies": {
"typescript": "^3.3.1",
"vscode": "^1.1.28",
"eslint": "^5.13.0",
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.6",
"@types/node": "^10.12.21",
"@types/mocha": "^2.2.42"
"@types/vscode": "^1.32.0",
"eslint": "^5.13.0",
"glob": "^7.1.4",
"mocha": "^6.1.4",
"typescript": "^3.3.1",
"vscode-test": "^0.4.2"
}
}
24 changes: 0 additions & 24 deletions generators/app/templates/ext-command-js/test/extension.test.js

This file was deleted.

23 changes: 0 additions & 23 deletions generators/app/templates/ext-command-js/test/index.js

This file was deleted.

23 changes: 23 additions & 0 deletions generators/app/templates/ext-command-js/test/runTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require('path');

const { runTests } = require('vscode-test');

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionPath = path.resolve(__dirname, '../../');

// The path to test runner
// Passed to --extensionTestsPath
const testRunnerPath = path.resolve(__dirname, './suite');

// Download VS Code, unzip it and run the integration test
await runTests({ extensionPath, testRunnerPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const assert = require('assert');
const { before } = require('mocha');

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
const vscode = require('vscode');
// const myExtension = require('../extension');

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));
});
});
32 changes: 32 additions & 0 deletions generators/app/templates/ext-command-js/test/suite/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const path = require('path');
const Mocha = require('mocha');
const glob = require('glob');

function run(testsRoot, cb) {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd'
});
// Use any mocha API
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);
}
});
}

module.exports = {
run
};
13 changes: 8 additions & 5 deletions generators/app/templates/ext-command-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@
"vscode:prepublish": "<%= pkgManager %> run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "<%= pkgManager %> run compile && node ./node_modules/vscode/bin/test"
"test": "<%= pkgManager %> run compile && node ./out/test/runTest.js"
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.6",
"@types/node": "^10.12.21",
"@types/vscode": "^1.32.0",
"glob": "^7.1.4",
"mocha": "^6.1.4",
"typescript": "^3.3.1",
"vscode": "^1.1.28",
"tslint": "^5.12.1",
"@types/node": "^10.12.21",
"@types/mocha": "^2.2.42"
"vscode-test": "^0.4.2"
}
}
22 changes: 0 additions & 22 deletions generators/app/templates/ext-command-ts/src/test/extension.test.ts

This file was deleted.

23 changes: 0 additions & 23 deletions generators/app/templates/ext-command-ts/src/test/index.ts

This file was deleted.

23 changes: 23 additions & 0 deletions generators/app/templates/ext-command-ts/src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as path from 'path';

import { runTests } from 'vscode-test';

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionPath = path.resolve(__dirname, '../../');

// The path to test runner
// Passed to --extensionTestsPath
const testRunnerPath = path.resolve(__dirname, './suite');

// Download VS Code, unzip it and run the integration test
await runTests({ extensionPath, testRunnerPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +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';

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));
});
});
28 changes: 28 additions & 0 deletions generators/app/templates/ext-command-ts/src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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'
});
// Use any mocha API
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);
}
});
}
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2bee60b

Please sign in to comment.