Skip to content

Commit

Permalink
Добавил базовый код для выполнения тестов
Browse files Browse the repository at this point in the history
  • Loading branch information
artbear committed Oct 7, 2018
1 parent b42bf0f commit ffa0fde
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/src/test"
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"outFiles": [
"${workspaceFolder}/out/src/test/**/*.js"
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "npm: watch"
}
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.5",
"@types/node": "^10.11.3",
"mocha": "^5.2.0",
"should": "^13.2.3",
"tslib": "^1.9.3",
"tslint": "^5.11.0",
"typescript": "^3.1.1",
Expand Down
56 changes: 56 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"use strict";

import * as fs from "fs";
import * as glob from "glob";
import * as paths from "path";

const Mocha = require("mocha");

// Linux: prevent a weird NPE when mocha on Linux requires the window size from the TTY
// Since we are not running in a tty environment, we just implementt he method statically
const tty = require("tty");
if (!tty.getWindowSize) {
tty.getWindowSize = (): number[] => {
return [80, 75];
};
}

let mocha = new Mocha({
ui: "bdd",
useColors: true,
});

function configure(mochaOpts): void {
mocha = new Mocha(mochaOpts);
}
exports.configure = configure;

function run(testsRoot, clb): any {
// Enable source map support

// Glob test files
glob("**/**.test.js", { cwd: testsRoot }, (error, files): any => {
if (error) {
return clb(error);
}
try {
// Fill into Mocha
files.forEach((f): Mocha => {
return mocha.addFile(paths.join(testsRoot, f));
});
// Run the tests
let failureCount = 0;

mocha.run()
.on("fail", (): void => {
failureCount++;
})
.on("end", (): void => {
clb(undefined, failureCount);
});
} catch (error) {
return clb(error);
}
});
}
exports.run = run;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out/src",
"outDir": "out",
"lib": [
"es6"
],
Expand Down

0 comments on commit ffa0fde

Please sign in to comment.