From 24fdb5201d63eda9e0203bb34398baf69e91acab Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 14 Mar 2018 07:05:32 -0700 Subject: [PATCH] Pass stack trace limit to parallel workers, and always convert to number (#22527) * Pass stackTraceLimit to parallel workers Specifying it breaks some output, both in parallel and normal runners. I'll look at that in another commit, probably another PR, depending on how simple the problem is. * Always convert stackTraceLimit to a number Sometimes it's not a number, even though the type claims it is. --- src/harness/parallel/host.ts | 2 +- src/harness/runner.ts | 5 ++++- src/harness/unittests/session.ts | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/harness/parallel/host.ts b/src/harness/parallel/host.ts index 49e7aaa6bd3..1e7891e4cc3 100644 --- a/src/harness/parallel/host.ts +++ b/src/harness/parallel/host.ts @@ -144,7 +144,7 @@ namespace Harness.Parallel.Host { let closedWorkers = 0; for (let i = 0; i < workerCount; i++) { // TODO: Just send the config over the IPC channel or in the command line arguments - const config: TestConfig = { light: lightMode, listenForWork: true, runUnitTests }; + const config: TestConfig = { light: lightMode, listenForWork: true, runUnitTests, stackTraceLimit }; const configPath = ts.combinePaths(taskConfigsFolder, `task-config${i}.json`); IO.writeFile(configPath, JSON.stringify(config)); const child = fork(__filename, [`--config="${configPath}"`]); diff --git a/src/harness/runner.ts b/src/harness/runner.ts index 76d65090f02..48c3ba31277 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -88,6 +88,7 @@ let testConfigContent = let taskConfigsFolder: string; let workerCount: number; let runUnitTests: boolean | undefined; +let stackTraceLimit: number | "full" | undefined; let noColors = false; interface TestConfig { @@ -132,9 +133,11 @@ function handleTestConfig() { if (testConfig.stackTraceLimit === "full") { (Error).stackTraceLimit = Infinity; + stackTraceLimit = testConfig.stackTraceLimit; } else if ((+testConfig.stackTraceLimit | 0) > 0) { - (Error).stackTraceLimit = testConfig.stackTraceLimit; + (Error).stackTraceLimit = +testConfig.stackTraceLimit | 0; + stackTraceLimit = +testConfig.stackTraceLimit | 0; } if (testConfig.listenForWork) { return true; diff --git a/src/harness/unittests/session.ts b/src/harness/unittests/session.ts index 7ba8019e2bd..9f4a2683ee2 100644 --- a/src/harness/unittests/session.ts +++ b/src/harness/unittests/session.ts @@ -421,13 +421,17 @@ namespace ts.server { // Disable sourcemap support for the duration of the test, as sourcemapping the errors generated during this test is slow and not something we care to test let oldPrepare: AnyFunction; + let oldStackTraceLimit: number; before(() => { + oldStackTraceLimit = (Error as any).stackTraceLimit; oldPrepare = (Error as any).prepareStackTrace; delete (Error as any).prepareStackTrace; + (Error as any).stackTraceLimit = 10; }); after(() => { (Error as any).prepareStackTrace = oldPrepare; + (Error as any).stackTraceLimit = oldStackTraceLimit; }); const command = "testhandler";