Skip to content

Commit 49598f2

Browse files
author
YDarma
committed
stream locking
1 parent 12cc602 commit 49598f2

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('through');
8+
var EventEmitter = require('events').EventEmitter;
89

910
var canEmitExit = typeof process !== 'undefined' && process
1011
&& typeof process.on === 'function' && process.browser !== true;
@@ -43,6 +44,10 @@ module.exports = (function () {
4344
return harness.createStream(options);
4445
};
4546

47+
lazyLoad.async = function () {
48+
return getHarness().async.apply(this, arguments);
49+
};
50+
4651
lazyLoad.onFinish = function () {
4752
return getHarness().onFinish.apply(this, arguments);
4853
};
@@ -72,10 +77,15 @@ function createExitHarness(conf, wait) {
7277
var running = false;
7378
var ended = false;
7479

80+
run();
81+
7582
if (wait) {
76-
harness.run = run;
77-
} else {
78-
run();
83+
var waiter = new EventEmitter();
84+
waiter.run = function() {};
85+
harness._results.push(waiter);
86+
harness.run = function() {
87+
waiter.emit("end");
88+
}
7989
}
8090

8191
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)