Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80522 views
1
var assert = require('assert');
2
var ourProcess = require('./browser');
3
describe('test against process', function () {
4
test(process);
5
});
6
if (!process.browser) {
7
describe('test against our shim', function () {
8
test(ourProcess);
9
});
10
}
11
function test (ourProcess) {
12
describe('test arguments', function (t) {
13
it ('works', function (done) {
14
var order = 0;
15
16
17
ourProcess.nextTick(function (num) {
18
assert.equal(num, order++, 'first one works');
19
ourProcess.nextTick(function (num) {
20
assert.equal(num, order++, 'recursive one is 4th');
21
}, 3);
22
}, 0);
23
ourProcess.nextTick(function (num) {
24
assert.equal(num, order++, 'second one starts');
25
ourProcess.nextTick(function (num) {
26
assert.equal(num, order++, 'this is third');
27
ourProcess.nextTick(function (num) {
28
assert.equal(num, order++, 'this is last');
29
done();
30
}, 5);
31
}, 4);
32
}, 1);
33
ourProcess.nextTick(function (num) {
34
35
assert.equal(num, order++, '3rd schedualed happens after the error');
36
}, 2);
37
});
38
});
39
40
describe('test errors', function (t) {
41
it ('works', function (done) {
42
var order = 0;
43
process.removeAllListeners('uncaughtException');
44
process.once('uncaughtException', function(err) {
45
assert.equal(2, order++, 'error is third');
46
ourProcess.nextTick(function () {
47
assert.equal(5, order++, 'schedualed in error is last');
48
done();
49
});
50
});
51
ourProcess.nextTick(function () {
52
assert.equal(0, order++, 'first one works');
53
ourProcess.nextTick(function () {
54
assert.equal(4, order++, 'recursive one is 4th');
55
});
56
});
57
ourProcess.nextTick(function () {
58
assert.equal(1, order++, 'second one starts');
59
throw(new Error('an error is thrown'));
60
});
61
ourProcess.nextTick(function () {
62
assert.equal(3, order++, '3rd schedualed happens after the error');
63
});
64
});
65
});
66
}
67
68