Skip to content

Commit 19cfc8f

Browse files
committedJan 12, 2024
[Refactor] getHarness: avoid mutating opts, account for only one internal callsite for createExitHarness
1 parent 8a1cccc commit 19cfc8f

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed
 

‎index.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ module.exports = (function () {
1616
var harness;
1717

1818
function getHarness(opts) {
19-
if (!opts) { opts = {}; }
20-
opts.autoclose = !canEmitExit;
2119
// this override is here since tests fail via nyc if createHarness is moved upwards
22-
// eslint-disable-next-line no-use-before-define
23-
if (!harness) { harness = createExitHarness(opts, wait); }
20+
if (!harness) {
21+
// eslint-disable-next-line no-use-before-define
22+
harness = createExitHarness(opts || {}, wait);
23+
}
2424
return harness;
2525
}
2626

@@ -120,20 +120,24 @@ function createHarness(conf_) {
120120
return test;
121121
}
122122

123-
function createExitHarness(conf, wait) {
124-
var config = conf || {};
123+
function createExitHarness(config, wait) {
124+
var noOnly = config.noOnly;
125+
var objectMode = config.objectMode;
126+
var cStream = config.stream;
127+
var exit = config.exit;
128+
125129
var harness = createHarness({
126-
autoclose: defined(config.autoclose, false),
127-
noOnly: defined(conf.noOnly, defined(process.env.NODE_TAPE_NO_ONLY_TEST, false))
130+
autoclose: !canEmitExit,
131+
noOnly: defined(noOnly, defined(process.env.NODE_TAPE_NO_ONLY_TEST, false))
128132
});
129133
var running = false;
130134
var ended = false;
131135

132136
function run() {
133137
if (running) { return; }
134138
running = true;
135-
var stream = harness.createStream({ objectMode: config.objectMode });
136-
var es = stream.pipe(config.stream || createDefaultStream());
139+
var stream = harness.createStream({ objectMode: objectMode });
140+
var es = stream.pipe(cStream || createDefaultStream());
137141
if (canEmitExit && es) { // in node v0.4, `es` is `undefined`
138142
// TODO: use `err` arg?
139143
// eslint-disable-next-line no-unused-vars
@@ -148,7 +152,7 @@ function createExitHarness(conf, wait) {
148152
run();
149153
}
150154

151-
if (config.exit === false) { return harness; }
155+
if (exit === false) { return harness; }
152156
if (!canEmitExit || !canExit) { return harness; }
153157

154158
process.on('exit', function (code) {

0 commit comments

Comments
 (0)
Please sign in to comment.