Skip to content

Commit 05b40da

Browse files
committed
Use --inspect-brk for test debugging
1 parent b94c513 commit 05b40da

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

Gulpfile.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ Error.stackTraceLimit = 1000;
3939

4040
const cmdLineOptions = minimist(process.argv.slice(2), {
4141
boolean: ["debug", "inspect", "light", "colors", "lint", "soft"],
42-
string: ["browser", "tests", "host", "reporter", "stackTraceLimit"],
42+
string: ["browser", "tests", "host", "reporter", "stackTraceLimit", "timeout"],
4343
alias: {
4444
b: "browser",
45-
d: "debug",
46-
t: "tests",
47-
test: "tests",
45+
d: "debug", "debug-brk": "debug",
46+
i: "inspect", "inspect-brk": "inspect",
47+
t: "tests", test: "tests",
4848
r: "reporter",
49-
color: "colors",
50-
f: "files",
51-
file: "files",
49+
c: "colors", color: "colors",
50+
f: "files", file: "files",
5251
w: "workers",
5352
},
5453
default: {
5554
soft: false,
5655
colors: process.env.colors || process.env.color || true,
57-
debug: process.env.debug || process.env.d,
58-
inspect: process.env.inspect,
56+
debug: process.env.debug || process.env["debug-brk"] || process.env.d,
57+
inspect: process.env.inspect || process.env["inspect-brk"] || process.env.i,
5958
host: process.env.TYPESCRIPT_HOST || process.env.host || "node",
6059
browser: process.env.browser || process.env.b || "IE",
60+
timeout: process.env.timeout || 40000,
6161
tests: process.env.test || process.env.tests || process.env.t,
6262
light: process.env.light || false,
6363
reporter: process.env.reporter || process.env.r,
@@ -594,11 +594,11 @@ function restoreSavedNodeEnv() {
594594
process.env.NODE_ENV = savedNodeEnv;
595595
}
596596

597-
let testTimeout = 40000;
598597
function runConsoleTests(defaultReporter: string, runInParallel: boolean, done: (e?: any) => void) {
599598
const lintFlag = cmdLineOptions["lint"];
600599
cleanTestDirs((err) => {
601600
if (err) { console.error(err); failWithStatus(err, 1); }
601+
let testTimeout = cmdLineOptions["timeout"];
602602
const debug = cmdLineOptions["debug"];
603603
const inspect = cmdLineOptions["inspect"];
604604
const tests = cmdLineOptions["tests"];
@@ -637,12 +637,6 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
637637
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
638638
if (!runInParallel) {
639639
const args = [];
640-
if (inspect) {
641-
args.push("--inspect");
642-
}
643-
if (inspect || debug) {
644-
args.push("--debug-brk");
645-
}
646640
args.push("-R", reporter);
647641
if (tests) {
648642
args.push("-g", `"${tests}"`);
@@ -653,7 +647,15 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
653647
else {
654648
args.push("--no-colors");
655649
}
656-
args.push("-t", testTimeout);
650+
if (inspect) {
651+
args.unshift("--inspect-brk");
652+
}
653+
else if (debug) {
654+
args.unshift("--debug-brk");
655+
}
656+
else {
657+
args.push("-t", testTimeout);
658+
}
657659
args.push(run);
658660
setNodeEnvToDevelopment();
659661
exec(mocha, args, lintThenFinish, function(e, status) {
@@ -838,6 +840,7 @@ gulp.task("runtests-browser", "Runs the tests using the built run.js file like '
838840
});
839841

840842
gulp.task("generate-code-coverage", "Generates code coverage data via istanbul", ["tests"], (done) => {
843+
const testTimeout = cmdLineOptions["timeout"];
841844
exec("istanbul", ["cover", "node_modules/mocha/bin/_mocha", "--", "-R", "min", "-t", testTimeout.toString(), run], done, done);
842845
});
843846

Jakefile.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var LKGDirectory = "lib/";
2525
var copyright = "CopyrightNotice.txt";
2626
var thirdParty = "ThirdPartyNoticeText.txt";
2727

28+
var defaultTestTimeout = 40000;
29+
2830
// add node_modules to path so we don't need global modules, prefer the modules by adding them first
2931
var nodeModulesPathPrefix = path.resolve("./node_modules/.bin/") + path.delimiter;
3032
if (process.env.path !== undefined) {
@@ -800,8 +802,8 @@ function runConsoleTests(defaultReporter, runInParallel) {
800802
cleanTestDirs();
801803
}
802804

803-
var debug = process.env.debug || process.env.d;
804-
var inspect = process.env.inspect;
805+
var debug = process.env.debug || process.env["debug-brk"] || process.env.d;
806+
var inspect = process.env.inspect || process.env["inspect-brk"] || process.env.i;
805807
var testTimeout = process.env.timeout || defaultTestTimeout;
806808
var tests = process.env.test || process.env.tests || process.env.t;
807809
var light = process.env.light || false;
@@ -842,12 +844,6 @@ function runConsoleTests(defaultReporter, runInParallel) {
842844
if (!runInParallel) {
843845
var startTime = mark();
844846
var args = [];
845-
if (inspect) {
846-
args.push("--inspect");
847-
}
848-
if (inspect || debug) {
849-
args.push("--debug-brk");
850-
}
851847
args.push("-R", reporter);
852848
if (tests) {
853849
args.push("-g", `"${tests}"`);
@@ -861,7 +857,15 @@ function runConsoleTests(defaultReporter, runInParallel) {
861857
if (bail) {
862858
args.push("--bail");
863859
}
864-
args.push("-t", testTimeout);
860+
if (inspect) {
861+
args.unshift("--inspect-brk");
862+
}
863+
else if (debug) {
864+
args.unshift("--debug-brk");
865+
}
866+
else {
867+
args.push("-t", testTimeout);
868+
}
865869
args.push(run);
866870

867871
var cmd = "mocha " + args.join(" ");
@@ -926,7 +930,6 @@ function runConsoleTests(defaultReporter, runInParallel) {
926930
}
927931
}
928932

929-
var defaultTestTimeout = 22000;
930933
desc("Runs all the tests in parallel using the built run.js file. Optional arguments are: t[ests]=category1|category2|... d[ebug]=true.");
931934
task("runtests-parallel", ["build-rules", "tests", builtLocalDirectory], function () {
932935
runConsoleTests('min', /*runInParallel*/ true);
@@ -939,6 +942,7 @@ task("runtests", ["build-rules", "tests", builtLocalDirectory], function() {
939942

940943
desc("Generates code coverage data via instanbul");
941944
task("generate-code-coverage", ["tests", builtLocalDirectory], function () {
945+
var testTimeout = process.env.timeout || defaultTestTimeout;
942946
var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run;
943947
console.log(cmd);
944948
exec(cmd);

0 commit comments

Comments
 (0)