GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test_runner: pass harness object as option to root test · nodejs/node@1e88045

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/test_runner
    • harness.js
    • test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/test_runner/harness.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/harness.js
+39-37Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,42 @@ let globalRoot;
3535
testResources.set(reporterScope.asyncId(), reporterScope);
3636

3737
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();
3974
return globalRoot;
4075
}
4176

@@ -127,15 +162,7 @@ function collectCoverage(rootTest, coverage) {
127162
return summary;
128163
}
129164

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) {
139166
const hook = createHook({
140167
__proto__: null,
141168
init(asyncId, type, triggerAsyncId, resource) {
@@ -195,33 +222,8 @@ function setup(root) {
195222
process.on('SIGTERM', terminationHandler);
196223
}
197224

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;
225227
}
226228

227229
function lazyBootstrapRoot() {
Collapse file

‎lib/internal/test_runner/test.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ class Test extends AsyncResource {
395395
this.timeout = kDefaultTimeout;
396396
this.entryFile = entryFile;
397397
this.root = this;
398+
this.harness = options.harness;
398399
this.hooks = {
399400
__proto__: null,
400401
before: [],
@@ -416,6 +417,7 @@ class Test extends AsyncResource {
416417
this.timeout = parent.timeout;
417418
this.entryFile = parent.entryFile;
418419
this.root = parent.root;
420+
this.harness = null;
419421
this.hooks = {
420422
__proto__: null,
421423
before: [],
@@ -480,7 +482,6 @@ class Test extends AsyncResource {
480482
);
481483

482484
this.fn = fn;
483-
this.harness = null; // Configured on the root test by the test harness.
484485
this.mock = null;
485486
this.plan = null;
486487
this.expectedAssertions = plan;

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.