Skip to content

Commit cb87b29

Browse files
YDarmaljharb
authored andcommitted
stream locking
1 parent 201e650 commit cb87b29

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var createDefaultStream = require('./lib/default_stream');
55
var Test = require('./lib/test');
66
var createResult = require('./lib/results');
77
var through = require('@ljharb/through');
8+
var EventEmitter = require('events').EventEmitter;
89

910
var canEmitExit = typeof process !== 'undefined' && process
1011
&& typeof process.on === 'function' && process.browser !== true;
@@ -53,6 +54,10 @@ module.exports = (function () {
5354
return harness.createStream(options);
5455
};
5556

57+
lazyLoad.async = function () {
58+
return getHarness().async.apply(this, arguments);
59+
};
60+
5661
lazyLoad.onFinish = function () {
5762
return getHarness().onFinish.apply(this, arguments);
5863
};
@@ -142,10 +147,15 @@ function createExitHarness(conf, wait) {
142147
stream.on('end', function () { ended = true; });
143148
}
144149

150+
run();
151+
145152
if (wait) {
146-
harness.run = run;
147-
} else {
148-
run();
153+
var waiter = new EventEmitter();
154+
waiter.run = function () {};
155+
harness._results.push(waiter);
156+
harness.run = function () {
157+
waiter.emit('end');
158+
};
149159
}
150160

151161
if (config.exit === false) { return harness; }

test/wait-run-object-stream.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
var tap = require('tap');
4+
var tape = require('../');
5+
6+
tap.test('Create stream then import async tests', function (t) {
7+
t.plan(3);
8+
9+
var actualTests = function () {
10+
tape('This one should pass', function (t1) {
11+
t1.pass('This one should pass');
12+
t1.end();
13+
});
14+
};
15+
16+
var simulateAsyncEsmImport = function () {
17+
return new Promise(function (resolve) {
18+
setTimeout(function () {
19+
actualTests();
20+
resolve();
21+
});
22+
});
23+
};
24+
25+
tape.createStream({ objectMode: true }).on('data', function (res) {
26+
t.pass(res.type);
27+
});
28+
29+
tape.wait();
30+
simulateAsyncEsmImport().then(function () {
31+
tape.run();
32+
});
33+
});

0 commit comments

Comments
 (0)