1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-18 21:35:31 -05:00
denoland-deno/tests/node_compat/test/parallel/test-domain-top-level-error-handler-clears-stack.js
Yoshiya Hinosawa fb24fd37c9
test: add node compat test cases (#27134)
This PR enables node compat test cases found passing by using the tool
added in #27122

The percentage of passing test case increases from 16.16% to 30.43% by
this change.
2024-12-04 11:37:20 +09:00

38 lines
1.4 KiB
JavaScript

// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const domain = require('domain');
// Make sure that the domains stack is cleared after a top-level domain
// error handler exited gracefully.
const d = domain.create();
d.on('error', common.mustCall(() => {
// Scheduling a callback with process.nextTick _could_ enter a _new_ domain,
// but domain's error handlers are called outside of their domain's context.
// So there should _no_ domain on the domains stack if the domains stack was
// cleared properly when the domain error handler was called.
process.nextTick(() => {
if (domain._stack.length !== 0) {
// Do not use assert to perform this test: this callback runs in a
// different callstack as the original process._fatalException that
// handled the original error, thus throwing here would trigger another
// call to process._fatalException, and so on recursively and
// indefinitely.
console.error('domains stack length should be 0, but instead is:',
domain._stack.length);
process.exit(1);
}
});
}));
d.run(() => {
throw new Error('Error from domain');
});