Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream locking #576

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var Test = require('./lib/test');
var createResult = require('./lib/results');
var through = require('@ljharb/through');
var EventEmitter = require('events').EventEmitter;

var canEmitExit = typeof process !== 'undefined' && process
&& typeof process.on === 'function' && process.browser !== true;
Expand Down Expand Up @@ -53,6 +54,10 @@
return harness.createStream(options);
};

lazyLoad.async = function () {
return getHarness().async.apply(this, arguments);

Check warning on line 58 in index.js

View check run for this annotation

Codecov / codecov/patch

index.js#L58

Added line #L58 was not covered by tests
};

lazyLoad.onFinish = function () {
return getHarness().onFinish.apply(this, arguments);
};
Expand Down Expand Up @@ -142,10 +147,15 @@
stream.on('end', function () { ended = true; });
}

run();

if (wait) {
Comment on lines +150 to 152
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this change mean it's breaking for anyone using wait?

harness.run = run;
} else {
run();
var waiter = new EventEmitter();
waiter.run = function () {};
harness._results.push(waiter);
harness.run = function () {
waiter.emit('end');

Check warning on line 157 in index.js

View check run for this annotation

Codecov / codecov/patch

index.js#L153-L157

Added lines #L153 - L157 were not covered by tests
};
}

if (config.exit === false) { return harness; }
Expand Down
33 changes: 33 additions & 0 deletions test/wait-run-object-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

var tap = require('tap');
var tape = require('../');

tap.test('Create stream then import async tests', function (t) {
t.plan(3);

var actualTests = function () {
tape('This one should pass', function (t1) {
t1.pass('This one should pass');
t1.end();
});
};

var simulateAsyncEsmImport = function () {
return new Promise(function (resolve) {
setTimeout(function () {
actualTests();
resolve();
});
});
};

tape.createStream({ objectMode: true }).on('data', function (res) {
t.pass(res.type);
});

tape.wait();
simulateAsyncEsmImport().then(function () {
tape.run();
});
});