getting unit tests and webpack up and running
This commit is contained in:
Родитель
e351effdf6
Коммит
2461758fa6
|
@ -51,7 +51,7 @@
|
|||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"--extensionTestsPath=${workspaceFolder}/out/test"
|
||||
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
|
||||
],
|
||||
"stopOnEntry": false,
|
||||
"sourceMaps": true,
|
||||
|
@ -75,7 +75,7 @@
|
|||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"--extensionTestsPath=${workspaceFolder}/dist/test"
|
||||
"--extensionTestsPath=${workspaceFolder}/dist/test/suite/index"
|
||||
],
|
||||
"stopOnEntry": false,
|
||||
"sourceMaps": true,
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
* everything else will be in private modules in extension.bundle.js.
|
||||
*/
|
||||
|
||||
// Export activate/deactivate for main.js
|
||||
export { activateInternal, deactivateInternal } from './src/extension';
|
||||
|
||||
// Exports for tests
|
||||
// The tests are not packaged with the webpack bundle and therefore only have access to code exported from this file.
|
||||
//
|
||||
// The tests should import '../extension.bundle.ts'. At design-time they live in tests/ and so will pick up this file (extension.bundle.ts).
|
||||
// At runtime the tests live in dist/tests and will therefore pick up the main webpack bundle at dist/extension.bundle.js.
|
||||
export { ext } from './src/extensionVariables';
|
||||
export * from 'vscode-azureextensionui';
|
||||
// Export activate/deactivate for main.js
|
||||
export { activateInternal, deactivateInternal } from './src/extension';
|
||||
export { ext } from './src/extensionVariables';
|
||||
export { AzureAccountTreeItem } from './src/AzureAccountTreeItem';
|
27
gulpfile.ts
27
gulpfile.ts
|
@ -6,18 +6,29 @@
|
|||
// tslint:disable:no-unsafe-any
|
||||
|
||||
import * as cp from "child_process";
|
||||
import * as fse from 'fs-extra';
|
||||
import * as gulp from "gulp";
|
||||
import * as path from "path";
|
||||
import { gulp_installAzureAccount, gulp_webpack } from "vscode-azureextensiondev";
|
||||
|
||||
const env = process.env;
|
||||
//const env = process.env;
|
||||
|
||||
function test(): cp.ChildProcess {
|
||||
env.DEBUGTELEMETRY = "1";
|
||||
env.CODE_TESTS_PATH = path.join(__dirname, "dist/test");
|
||||
return cp.spawn("node", ["./node_modules/vscode/bin/test"], { stdio: "inherit", env });
|
||||
// function test(): cp.ChildProcess {
|
||||
// env.DEBUGTELEMETRY = "1";
|
||||
// env.CODE_TESTS_PATH = path.join(__dirname, "dist/test");
|
||||
// return cp.spawn("node", ["./node_modules/vscode/bin/test"], { stdio: "inherit", env });
|
||||
// }
|
||||
|
||||
async function prepareForWebpack(): Promise<void> {
|
||||
const mainJsPath: string = path.join(__dirname, 'main.js');
|
||||
let contents: string = (await fse.readFile(mainJsPath)).toString();
|
||||
contents = contents
|
||||
.replace('out/src/extension', 'dist/extension.bundle')
|
||||
.replace(', true /* ignoreBundle */', '');
|
||||
await fse.writeFile(mainJsPath, contents);
|
||||
}
|
||||
|
||||
exports["webpack-dev"] = () => gulp_webpack("development");
|
||||
exports["webpack-prod"] = () => gulp_webpack("production");
|
||||
exports.test = gulp.series(gulp_installAzureAccount, test);
|
||||
exports['webpack-dev'] = gulp.series(prepareForWebpack, () => gulp_webpack('development'));
|
||||
exports['webpack-prod'] = gulp.series(prepareForWebpack, () => gulp_webpack('production'));
|
||||
exports.preTest = gulp_installAzureAccount;
|
||||
//exports.test = gulp.series(gulp_installAzureAccount, test);
|
12
main.js
12
main.js
|
@ -18,16 +18,18 @@ Object.defineProperty(exports, "__esModule", {
|
|||
value: true
|
||||
});
|
||||
|
||||
const ignoreBundle = !/^(false|0)?$/i.test(process.env.AZCODE_SEARCH_IGNORE_BUNDLE || '');
|
||||
const extensionPath = ignoreBundle ? "./out/src/extension" : "./dist/extension.bundle";
|
||||
const extension = require(extensionPath);
|
||||
//const ignoreBundle = !/^(false|0)?$/i.test(process.env.AZCODE_SEARCH_IGNORE_BUNDLE || '');
|
||||
//const extensionPath = ignoreBundle ? "./dist/extension.bundle" : "./dist/extension.bundle";
|
||||
//const extension = require(extensionPath);
|
||||
|
||||
const extension = require('./dist/extension.bundle');
|
||||
|
||||
async function activate(ctx) {
|
||||
return await extension.activateInternal(ctx, perfStats);
|
||||
return await extension.activateInternal(ctx, perfStats, true);
|
||||
}
|
||||
|
||||
async function deactivate(ctx) {
|
||||
return await extension.deactivateInternal();
|
||||
return await extension.deactivateInternal(ctx, perfStats);
|
||||
}
|
||||
|
||||
exports.activate = activate;
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
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 extensionDevelopmentPath = path.resolve(__dirname, '../../');
|
||||
|
||||
// The path to test runner
|
||||
// Passed to --extensionTestsPath
|
||||
const extensionTestsPath = path.resolve(__dirname, './suite/index');
|
||||
|
||||
// Download VS Code, unzip it and run the integration test
|
||||
await runTests({ extensionDevelopmentPath, extensionTestsPath });
|
||||
} catch (err) {
|
||||
console.error('Failed to run tests');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
|
@ -1,15 +0,0 @@
|
|||
import * as assert from 'assert';
|
||||
|
||||
// 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', () => {
|
||||
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));
|
||||
});
|
||||
});
|
|
@ -1,38 +0,0 @@
|
|||
import * as path from 'path';
|
||||
import * as Mocha from 'mocha';
|
||||
import * as glob from 'glob';
|
||||
|
||||
export function run(): Promise<void> {
|
||||
// Create the mocha test
|
||||
const mocha = new Mocha({
|
||||
ui: 'tdd',
|
||||
color: true
|
||||
});
|
||||
|
||||
const testsRoot = path.resolve(__dirname, '..');
|
||||
|
||||
return new Promise((c, e) => {
|
||||
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
||||
if (err) {
|
||||
return e(err);
|
||||
}
|
||||
|
||||
// Add files to the test suite
|
||||
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
|
||||
|
||||
try {
|
||||
// Run the mocha test
|
||||
mocha.run(failures => {
|
||||
if (failures > 0) {
|
||||
e(new Error(`${failures} tests failed.`));
|
||||
} else {
|
||||
c();
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
e(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
Загрузка…
Ссылка в новой задаче