2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-12-23 16:02:12 -08:00
|
|
|
require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
2014-09-04 20:02:04 +04:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const implementations = [
|
2015-05-19 13:00:06 +02:00
|
|
|
function(fn) {
|
2014-09-04 20:02:04 +04:00
|
|
|
Promise.resolve().then(fn);
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let expected = 0;
|
|
|
|
let done = 0;
|
2014-09-04 20:02:04 +04:00
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
process.on('exit', function() {
|
2014-09-04 20:02:04 +04:00
|
|
|
assert.equal(done, expected);
|
|
|
|
});
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
function test(scheduleMicrotask) {
|
2017-01-08 13:19:00 +00:00
|
|
|
let nextTickCalled = false;
|
2014-09-04 20:02:04 +04:00
|
|
|
expected++;
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
scheduleMicrotask(function() {
|
|
|
|
process.nextTick(function() {
|
2014-09-04 20:02:04 +04:00
|
|
|
nextTickCalled = true;
|
|
|
|
});
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
setTimeout(function() {
|
2014-09-04 20:02:04 +04:00
|
|
|
assert(nextTickCalled);
|
|
|
|
done++;
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// first tick case
|
|
|
|
implementations.forEach(test);
|
|
|
|
|
|
|
|
// tick callback case
|
2015-05-19 13:00:06 +02:00
|
|
|
setTimeout(function() {
|
|
|
|
implementations.forEach(function(impl) {
|
2014-09-04 20:02:04 +04:00
|
|
|
process.nextTick(test.bind(null, impl));
|
|
|
|
});
|
|
|
|
}, 0);
|