Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ internal/
!tests/cases/projects/NodeModulesSearch/**/*
!tests/baselines/reference/project/nodeModules*/**/*
.idea
yarn.lock
yarn.lock
.failed-tests
20 changes: 17 additions & 3 deletions Gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const {runTestsInParallel} = mochaParallel;
Error.stackTraceLimit = 1000;

const cmdLineOptions = minimist(process.argv.slice(2), {
boolean: ["debug", "inspect", "light", "colors", "lint", "soft"],
boolean: ["debug", "inspect", "light", "colors", "lint", "soft", "failed", "bail", "keepFailed"],
string: ["browser", "tests", "host", "reporter", "stackTraceLimit", "timeout"],
alias: {
b: "browser",
Expand All @@ -49,6 +49,7 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
c: "colors", color: "colors",
f: "files", file: "files",
w: "workers",
"keep-failed": "keepFailed"
},
default: {
soft: false,
Expand All @@ -57,9 +58,12 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
inspect: process.env.inspect || process.env["inspect-brk"] || process.env.i,
host: process.env.TYPESCRIPT_HOST || process.env.host || "node",
browser: process.env.browser || process.env.b || "IE",
bail: process.env.bail || false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is bail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exit on the first failed test. This already exists in jakefile.js

timeout: process.env.timeout || 40000,
tests: process.env.test || process.env.tests || process.env.t,
light: process.env.light || false,
failed: process.env.failed || false,
keepFailed: process.env.keepFailed || process.env["keep-failed"] || false,
reporter: process.env.reporter || process.env.r,
lint: process.env.lint || true,
files: process.env.f || process.env.file || process.env.files || "",
Expand Down Expand Up @@ -603,6 +607,9 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
const inspect = cmdLineOptions["inspect"];
const tests = cmdLineOptions["tests"];
const light = cmdLineOptions["light"];
const bail = cmdLineOptions["bail"];
const failed = cmdLineOptions["failed"];
const keepFailed = cmdLineOptions["keepFailed"];
const stackTraceLimit = cmdLineOptions["stackTraceLimit"];
const testConfigFile = "test.config";
if (fs.existsSync(testConfigFile)) {
Expand Down Expand Up @@ -637,16 +644,23 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
if (!runInParallel) {
const args = [];
args.push("-R", reporter);
args.push("-R", "scripts/mocha-file-reporter");
args.push("-O", '"reporter=' + reporter + (keepFailed ? ",keepFailed=true" : "") + '"');
if (tests) {
args.push("-g", `"${tests}"`);
}
else if (failed) {
args.push("--opts", ".failed-tests");
}
if (colors) {
args.push("--colors");
}
else {
args.push("--no-colors");
}
if (bail) {
args.push("--bail");
}
if (inspect) {
args.unshift("--inspect-brk");
}
Expand Down Expand Up @@ -675,7 +689,7 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
}
args.push(run);
setNodeEnvToDevelopment();
runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: colors === " --no-colors " }, function(err) {
runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: colors === " --no-colors ", keepFailed }, function(err) {
// last worker clean everything and runs linter in case if there were no errors
del(taskConfigsFolder).then(() => {
if (!err) {
Expand Down
10 changes: 8 additions & 2 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,8 @@ function runConsoleTests(defaultReporter, runInParallel) {
var inspect = process.env.inspect || process.env["inspect-brk"] || process.env.i;
var testTimeout = process.env.timeout || defaultTestTimeout;
var tests = process.env.test || process.env.tests || process.env.t;
var failed = process.env.failed || false;
var keepFailed = process.env.keepFailed || process.env["keep-failed"] || false;
var light = process.env.light || false;
var stackTraceLimit = process.env.stackTraceLimit;
var testConfigFile = 'test.config';
Expand Down Expand Up @@ -849,10 +851,14 @@ function runConsoleTests(defaultReporter, runInParallel) {
if (!runInParallel) {
var startTime = mark();
var args = [];
args.push("-R", reporter);
args.push("-R", "scripts/mocha-file-reporter");
args.push("-O", '"reporter=' + reporter + (keepFailed ? ",keepFailed=true" : "") + '"');
if (tests) {
args.push("-g", `"${tests}"`);
}
else if (failed) {
args.push("--opts", ".failed-tests");
}
if (colors) {
args.push("--colors");
}
Expand Down Expand Up @@ -894,7 +900,7 @@ function runConsoleTests(defaultReporter, runInParallel) {
var savedNodeEnv = process.env.NODE_ENV;
process.env.NODE_ENV = "development";
var startTime = mark();
runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: !colors }, function (err) {
runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: !colors, keepFailed }, function (err) {
process.env.NODE_ENV = savedNodeEnv;
measure(startTime);
// last worker clean everything and runs linter in case if there were no errors
Expand Down
79 changes: 79 additions & 0 deletions scripts/mocha-file-reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
var Mocha = require('mocha');
var path = require('path');
var fs = require('fs');

exports = module.exports = FileReporter;

function FileReporter(runner, options) {
if (!runner) return;
options = options || {};

var reporterOptions = this.reporterOptions = options.reporterOptions || {};
reporterOptions.file = reporterOptions.file || ".failed-tests";
reporterOptions.keepFailed = reporterOptions.keepFailed || false;
if (reporterOptions.reporter) {
var _reporter;
if (typeof reporterOptions.reporter === "function") {
_reporter = reporterOptions.reporter;
}
else if (Mocha.reporters[reporterOptions.reporter]) {
_reporter = Mocha.reporters[reporterOptions.reporter];
}
else {
try {
_reporter = require(reporterOptions.reporter);
}
catch (err) {
_reporter = require(path.resolve(process.cwd(), reporterOptions.reporter));
}
}

var newOptions = {};
for (var p in options) newOptions[p] = options[p];
newOptions.reporterOptions = reporterOptions.reporterOptions || {};
this.reporter = new _reporter(runner, newOptions);
}

var failures = this.failures = [];
var tests = this.tests = [];
runner.on('test end', function (test) {
tests.push(test);
})
runner.on('fail', function (test, err) {
failures.push(test);
});
}

FileReporter.prototype.done = function (numFailures, fn) {
FileReporter.writeFailures(this.reporterOptions.file, this.failures, this.reporterOptions.keepFailed || this.tests.length === 0, done);

function done(err) {
var reporter = this.reporter;
if (reporter && reporter.done) {
reporter.done(numFailures, fn);
}
else {
if (fn) fn(numFailures);
}

if (err) console.error(err);
}
}

FileReporter.writeFailures = function (fileName, failures, keepFailed, fn) {
if (failures.length) {
var failed = failures.map(function (test) { return escapeRegExp(test.fullTitle()); }).join("|");
fs.writeFile(fileName, "--grep " + failed, "utf8", fn);
}
else if (!keepFailed) {
fs.unlink(fileName, function () { fn(); });
}
else {
fn();
}
};

var reservedCharacterRegExp = /[^\w]/g;
function escapeRegExp(pattern) {
return pattern.replace(reservedCharacterRegExp, function (match) { return "\\" + match; });
}
72 changes: 38 additions & 34 deletions scripts/mocha-parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var tty = require("tty")
, Base = mocha.reporters.Base
, color = Base.color
, cursor = Base.cursor
, ms = require("mocha/lib/ms");
, ms = require("mocha/lib/ms")
, FileReporter = require("./mocha-file-reporter");

var isatty = tty.isatty(1) && tty.isatty(2);
var tapRangePattern = /^(\d+)\.\.(\d+)(?:$|\r\n?|\n)/;
Expand Down Expand Up @@ -46,25 +47,18 @@ function discoverTests(run, options, cb) {
}

function runTests(taskConfigsFolder, run, options, cb) {
var configFiles = fs.readdirSync(taskConfigsFolder);
var numPartitions = configFiles.length;
if (numPartitions <= 0) {
cb();
return;
}

console.log("Running tests on " + numPartitions + " threads...");

var partitions = Array(numPartitions);
var progressBars = new ProgressBars();
progressBars.enable();

var counter = numPartitions;
configFiles.forEach(runTestsInPartition);

function runTestsInPartition(file, index) {
var partition = {
file: path.join(taskConfigsFolder, file),
var partitions = fs.readdirSync(taskConfigsFolder).map(function (file, index) {
var file = path.join(taskConfigsFolder, file);
var args = [];
args.push("-t", options.testTimeout || 40000);
args.push("-R", "tap");
args.push("--no-colors");
args.push(run);
args.push("--config='" + file + "'");
return {
file: file,
cmd: "mocha " + args.join(" "),
index: index,
tests: 0,
passed: 0,
failed: 0,
Expand All @@ -75,14 +69,27 @@ function runTests(taskConfigsFolder, run, options, cb) {
catastrophicError: "",
failures: []
};
partitions[index] = partition;
});

if (partitions.length <= 0) {
cb();
return;
}

console.log("Running tests on " + partitions.length + " threads...");

var progressBars = new ProgressBars();
progressBars.enable();

var counter = partitions.length;
partitions.forEach(runTestsInPartition);

function runTestsInPartition(partition) {
// Set up the progress bar.
updateProgress(0);

// Start the background process.
var cmd = "mocha -t " + (options.testTimeout || 20000) + " -R tap --no-colors " + run + " --config='" + partition.file + "'";
var p = spawnProcess(cmd);
var p = spawnProcess(partition.cmd);
var rl = readline.createInterface({
input: p.stdout,
terminal: false
Expand Down Expand Up @@ -195,7 +202,7 @@ function runTests(taskConfigsFolder, run, options, cb) {
}

progressBars.update(
index,
partition.index,
percentComplete,
progressColor,
title
Expand All @@ -213,7 +220,7 @@ function runTests(taskConfigsFolder, run, options, cb) {

var duration = 0;
var catastrophicError = "";
for (var i = 0; i < numPartitions; i++) {
for (var i = 0; i < partitions.length; i++) {
var partition = partitions[i];
stats.passes += partition.passed;
stats.failures += partition.failed;
Expand All @@ -225,7 +232,7 @@ function runTests(taskConfigsFolder, run, options, cb) {
// {
// "light":false,
// "tasks":[
// {
// {
// "runner":"compiler",
// "files":["tests/cases/compiler/es6ImportNamedImportParsingError.ts"]
// }
Expand Down Expand Up @@ -259,15 +266,12 @@ function runTests(taskConfigsFolder, run, options, cb) {
reporter.epilogue();
}

if (catastrophicError !== "") {
return cb(new Error(catastrophicError));
}
if (stats.failures) {
return cb(new Error("Test failures reported: " + stats.failures));
}
else {
FileReporter.writeFailures(".failed-tests", failures, options.keepFailed, function (err) {
if (err) return cb(err);
if (catastrophicError !== "") return cb(new Error(catastrophicError));
if (stats.failures) return cb(new Error("Test failures reported: " + stats.failures));
return cb();
}
});
}
}

Expand Down