Skip to content

Commit

Permalink
stream locking
Browse files Browse the repository at this point in the history
  • Loading branch information
YDarma committed May 27, 2022
1 parent 12cc602 commit 49598f2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
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 createDefaultStream = require('./lib/default_stream');
var Test = require('./lib/test');
var createResult = require('./lib/results');
var through = require('through');
var EventEmitter = require('events').EventEmitter;

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

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

lazyLoad.onFinish = function () {
return getHarness().onFinish.apply(this, arguments);
};
Expand Down Expand Up @@ -72,10 +77,15 @@ function createExitHarness(conf, wait) {
var running = false;
var ended = false;

run();

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

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();
});
});

0 comments on commit 49598f2

Please sign in to comment.