-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: split up and refactor test-domain
Split up test-domain into multiple, more focused test files and use more modern JS inside of them. PR-URL: #13614 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
- Loading branch information
1 parent
ba62b0e
commit 806f03e
Showing
12 changed files
with
263 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const domain = require('domain'); | ||
|
||
const d = new domain.Domain(); | ||
|
||
d.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.message, 'foobar'); | ||
assert.strictEqual(err.domain, d); | ||
assert.strictEqual(err.domainEmitter, undefined); | ||
assert.strictEqual(err.domainBound, undefined); | ||
assert.strictEqual(err.domainThrown, true); | ||
})); | ||
|
||
setTimeout(d.bind(() => { throw new Error('foobar'); }), 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const domain = require('domain'); | ||
const EventEmitter = require('events'); | ||
|
||
const d = new domain.Domain(); | ||
let implicit; | ||
|
||
d.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.message, 'foobar'); | ||
assert.strictEqual(err.domain, d); | ||
assert.strictEqual(err.domainEmitter, implicit); | ||
assert.strictEqual(err.domainBound, undefined); | ||
assert.strictEqual(err.domainThrown, false); | ||
})); | ||
|
||
// Implicit addition of the EventEmitter by being created within a domain-bound | ||
// context. | ||
d.run(common.mustCall(() => { | ||
implicit = new EventEmitter(); | ||
})); | ||
|
||
setTimeout(common.mustCall(() => { | ||
// escape from the domain, but implicit is still bound to it. | ||
implicit.emit('error', new Error('foobar')); | ||
}), 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const domain = require('domain'); | ||
const EventEmitter = require('events'); | ||
|
||
const d = new domain.Domain(); | ||
const e = new EventEmitter(); | ||
|
||
d.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.message, 'foobar'); | ||
assert.strictEqual(err.domain, d); | ||
assert.strictEqual(err.domainEmitter, e); | ||
assert.strictEqual(err.domainBound, undefined); | ||
assert.strictEqual(err.domainThrown, false); | ||
})); | ||
|
||
d.add(e); | ||
e.emit('error', new Error('foobar')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const domain = require('domain'); | ||
|
||
// This test is similar to test-domain-multiple-errors, but uses a new domain | ||
// for each errors. | ||
|
||
for (const something of [ | ||
42, null, undefined, false, () => {}, 'string', Symbol('foo') | ||
]) { | ||
const d = new domain.Domain(); | ||
d.run(common.mustCall(() => { | ||
process.nextTick(common.mustCall(() => { | ||
throw something; | ||
})); | ||
})); | ||
|
||
d.on('error', common.mustCall((err) => { | ||
assert.strictEqual(something, err); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const domain = require('domain'); | ||
const fs = require('fs'); | ||
|
||
const d = new domain.Domain(); | ||
|
||
const fst = fs.createReadStream('stream for nonexistent file'); | ||
|
||
d.on('error', common.mustCall((err) => { | ||
assert.ok(err.message.match(/^ENOENT: no such file or directory, open '/)); | ||
assert.strictEqual(err.domain, d); | ||
assert.strictEqual(err.domainEmitter, fst); | ||
assert.strictEqual(err.domainBound, undefined); | ||
assert.strictEqual(err.domainThrown, false); | ||
})); | ||
|
||
d.add(fst); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const domain = require('domain'); | ||
const fs = require('fs'); | ||
|
||
{ | ||
const d = new domain.Domain(); | ||
|
||
d.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.message, 'foobar'); | ||
assert.strictEqual(err.domain, d); | ||
assert.strictEqual(err.domainEmitter, undefined); | ||
assert.strictEqual(err.domainBound, undefined); | ||
assert.strictEqual(err.domainThrown, true); | ||
})); | ||
|
||
d.run(common.mustCall(() => { | ||
process.nextTick(common.mustCall(() => { | ||
const i = setInterval(common.mustCall(() => { | ||
clearInterval(i); | ||
setTimeout(common.mustCall(() => { | ||
fs.stat('this file does not exist', common.mustCall((er, stat) => { | ||
throw new Error('foobar'); | ||
})); | ||
}), 1); | ||
}), 1); | ||
})); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const domain = require('domain'); | ||
|
||
{ | ||
const d = new domain.Domain(); | ||
|
||
const mustNotCall = common.mustNotCall(); | ||
|
||
d.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.message, 'foobar'); | ||
assert.strictEqual(err.domain, d); | ||
assert.strictEqual(err.domainEmitter, undefined); | ||
assert.strictEqual(err.domainBound, mustNotCall); | ||
assert.strictEqual(err.domainThrown, false); | ||
})); | ||
|
||
const bound = d.intercept(mustNotCall); | ||
bound(new Error('foobar')); | ||
} | ||
|
||
{ | ||
const d = new domain.Domain(); | ||
|
||
const bound = d.intercept(common.mustCall((data) => { | ||
assert.strictEqual(data, 'data'); | ||
})); | ||
|
||
bound(null, 'data'); | ||
} | ||
|
||
{ | ||
const d = new domain.Domain(); | ||
|
||
const bound = d.intercept(common.mustCall((data, data2) => { | ||
assert.strictEqual(data, 'data'); | ||
assert.strictEqual(data2, 'data2'); | ||
})); | ||
|
||
bound(null, 'data', 'data2'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const domain = require('domain'); | ||
|
||
// This test is similar to test-domain-error-types, but uses a single domain | ||
// to emit all errors. | ||
|
||
const d = new domain.Domain(); | ||
|
||
const values = [ | ||
42, null, undefined, false, () => {}, 'string', Symbol('foo') | ||
]; | ||
|
||
d.on('error', common.mustCall((err) => { | ||
assert(values.includes(err)); | ||
}, values.length)); | ||
|
||
for (const something of values) { | ||
d.run(common.mustCall(() => { | ||
process.nextTick(common.mustCall(() => { | ||
throw something; | ||
})); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const domain = require('domain'); | ||
|
||
const d = new domain.Domain(); | ||
|
||
d.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.message, 'foobar'); | ||
assert.strictEqual(err.domain, d); | ||
assert.strictEqual(err.domainEmitter, undefined); | ||
assert.strictEqual(err.domainBound, undefined); | ||
assert.strictEqual(err.domainThrown, true); | ||
})); | ||
|
||
d.run(common.mustCall(() => { | ||
process.nextTick(common.mustCall(() => { | ||
throw new Error('foobar'); | ||
})); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const domain = require('domain'); | ||
|
||
const d = new domain.Domain(); | ||
|
||
assert.strictEqual(d.run(() => 'return value'), | ||
'return value'); | ||
|
||
assert.strictEqual(d.run((a, b) => `${a} ${b}`, 'return', 'value'), | ||
'return value'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const domain = require('domain'); | ||
|
||
const d = new domain.Domain(); | ||
|
||
d.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.message, 'foobar'); | ||
assert.strictEqual(err.domain, d); | ||
assert.strictEqual(err.domainEmitter, undefined); | ||
assert.strictEqual(err.domainBound, undefined); | ||
assert.strictEqual(err.domainThrown, true); | ||
})); | ||
|
||
d.run(common.mustCall(() => { | ||
setTimeout(common.mustCall(() => { | ||
throw new Error('foobar'); | ||
}), 1); | ||
})); |
Oops, something went wrong.