GeezerVison is showing github.com — test_runner: pass harness object as option to root test · nodejs/node@1e88045
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/harness.js +39-37Lines changed: 39 additions & 37 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -35,7 +35,42 @@ let globalRoot; | 35 | 35 | testResources.set(reporterScope.asyncId(), reporterScope); | 36 | 36 |
| 37 | 37 | function createTestTree(options = kEmptyObject) { | 38 | | - globalRoot = setup(new Test({ __proto__: null, ...options, name: '<root>' })); | | 38 | + const globalOptions = parseCommandLine(); | | 39 | + const harness = { | | 40 | + __proto__: null, | | 41 | + allowTestsToRun: false, | | 42 | + bootstrapPromise: resolvedPromise, | | 43 | + watching: false, | | 44 | + config: globalOptions, | | 45 | + coverage: null, | | 46 | + resetCounters() { | | 47 | + harness.counters = { | | 48 | + __proto__: null, | | 49 | + all: 0, | | 50 | + failed: 0, | | 51 | + passed: 0, | | 52 | + cancelled: 0, | | 53 | + skipped: 0, | | 54 | + todo: 0, | | 55 | + topLevel: 0, | | 56 | + suites: 0, | | 57 | + }; | | 58 | + }, | | 59 | + counters: null, | | 60 | + shouldColorizeTestFiles: shouldColorizeTestFiles(globalOptions.destinations), | | 61 | + teardown: null, | | 62 | + snapshotManager: null, | | 63 | + }; | | 64 | + | | 65 | + harness.resetCounters(); | | 66 | + globalRoot = new Test({ | | 67 | + __proto__: null, | | 68 | + ...options, | | 69 | + harness, | | 70 | + name: '<root>', | | 71 | + }); | | 72 | + setupProcessState(globalRoot, globalOptions, harness); | | 73 | + globalRoot.startTime = hrtime(); | 39 | 74 | return globalRoot; | 40 | 75 | } | 41 | 76 |
| @@ -127,15 +162,7 @@ function collectCoverage(rootTest, coverage) { | 127 | 162 | return summary; | 128 | 163 | } | 129 | 164 |
| 130 | | -function setup(root) { | 131 | | - if (root.startTime !== null) { | 132 | | - return root; | 133 | | - } | 134 | | - | 135 | | - // Parse the command line options before the hook is enabled. We don't want | 136 | | - // global input validation errors to end up in the uncaughtException handler. | 137 | | - const globalOptions = parseCommandLine(); | 138 | | - | | 165 | +function setupProcessState(root, globalOptions) { | 139 | 166 | const hook = createHook({ | 140 | 167 | __proto__: null, | 141 | 168 | init(asyncId, type, triggerAsyncId, resource) { | @@ -195,33 +222,8 @@ function setup(root) { | 195 | 222 | process.on('SIGTERM', terminationHandler); | 196 | 223 | } | 197 | 224 |
| 198 | | - root.harness = { | 199 | | - __proto__: null, | 200 | | - allowTestsToRun: false, | 201 | | - bootstrapPromise: resolvedPromise, | 202 | | - watching: false, | 203 | | - coverage: FunctionPrototypeBind(collectCoverage, null, root, coverage), | 204 | | - resetCounters() { | 205 | | - root.harness.counters = { | 206 | | - __proto__: null, | 207 | | - all: 0, | 208 | | - failed: 0, | 209 | | - passed: 0, | 210 | | - cancelled: 0, | 211 | | - skipped: 0, | 212 | | - todo: 0, | 213 | | - topLevel: 0, | 214 | | - suites: 0, | 215 | | - }; | 216 | | - }, | 217 | | - counters: null, | 218 | | - shouldColorizeTestFiles: shouldColorizeTestFiles(globalOptions.destinations), | 219 | | - teardown: exitHandler, | 220 | | - snapshotManager: null, | 221 | | - }; | 222 | | - root.harness.resetCounters(); | 223 | | - root.startTime = hrtime(); | 224 | | - return root; | | 225 | + root.harness.coverage = FunctionPrototypeBind(collectCoverage, null, root, coverage); | | 226 | + root.harness.teardown = exitHandler; | 225 | 227 | } | 226 | 228 |
| 227 | 229 | function lazyBootstrapRoot() { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -395,6 +395,7 @@ class Test extends AsyncResource { | 395 | 395 | this.timeout = kDefaultTimeout; | 396 | 396 | this.entryFile = entryFile; | 397 | 397 | this.root = this; | | 398 | + this.harness = options.harness; | 398 | 399 | this.hooks = { | 399 | 400 | __proto__: null, | 400 | 401 | before: [], | @@ -416,6 +417,7 @@ class Test extends AsyncResource { | 416 | 417 | this.timeout = parent.timeout; | 417 | 418 | this.entryFile = parent.entryFile; | 418 | 419 | this.root = parent.root; | | 420 | + this.harness = null; | 419 | 421 | this.hooks = { | 420 | 422 | __proto__: null, | 421 | 423 | before: [], | @@ -480,7 +482,6 @@ class Test extends AsyncResource { | 480 | 482 | ); | 481 | 483 |
| 482 | 484 | this.fn = fn; | 483 | | - this.harness = null; // Configured on the root test by the test harness. | 484 | 485 | this.mock = null; | 485 | 486 | this.plan = null; | 486 | 487 | this.expectedAssertions = plan; | |
|