1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-19 05:45:09 -05:00
denoland-deno/tests/node_compat/test/parallel/test-error-aggregateTwoErrors.js

67 lines
1.8 KiB
JavaScript
Raw Normal View History

// 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.
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { aggregateTwoErrors } = require('internal/errors');
assert.strictEqual(aggregateTwoErrors(null, null), null);
{
const err = new Error();
assert.strictEqual(aggregateTwoErrors(null, err), err);
}
{
const err = new Error();
assert.strictEqual(aggregateTwoErrors(err, null), err);
}
{
const err0 = new Error('original');
const err1 = new Error('second error');
err0.code = 'ERR0';
err1.code = 'ERR1';
const chainedError = aggregateTwoErrors(err1, err0);
assert.strictEqual(chainedError.message, err0.message);
assert.strictEqual(chainedError.code, err0.code);
assert.deepStrictEqual(chainedError.errors, [err0, err1]);
}
{
const err0 = new Error('original');
const err1 = new Error('second error');
const err2 = new Error('third error');
err0.code = 'ERR0';
err1.code = 'ERR1';
err2.code = 'ERR2';
const chainedError = aggregateTwoErrors(err2, aggregateTwoErrors(err1, err0));
assert.strictEqual(chainedError.message, err0.message);
assert.strictEqual(chainedError.code, err0.code);
assert.deepStrictEqual(chainedError.errors, [err0, err1, err2]);
}
{
const err0 = new Error('original');
const err1 = new Error('second error');
err0.code = 'ERR0';
err1.code = 'ERR1';
const chainedError = aggregateTwoErrors(null, aggregateTwoErrors(err1, err0));
assert.strictEqual(chainedError.message, err0.message);
assert.strictEqual(chainedError.code, err0.code);
assert.deepStrictEqual(chainedError.errors, [err0, err1]);
}