0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-domain-ee-implicit.js
Anna Henningsen 1a2f579ba0
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: https://github.com/nodejs/node/pull/13614
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2017-10-16 11:24:35 +02:00

29 lines
799 B
JavaScript

'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);