Skip to content

Commit

Permalink
chore(deps-dev): bump undici from 6.2.1 to 6.3.0 (#3827)
Browse files Browse the repository at this point in the history
* fix test assertions for AbortController changes in undici@6.3.0
* correct the 'Error.prepareStackTrace is not set' test assumptions, node v21.6.0 sets a default Error.prepareStackTrace

Co-authored-by: Trent Mick <trent.mick@elastic.co>
  • Loading branch information
dependabot[bot] and trentm authored Jan 16, 2024
1 parent bc36123 commit 6c6d90a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 41 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 27 additions & 8 deletions test/instrumentation/modules/undici/undici.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ if (isUndiciIncompat) {
const http = require('http');
const { Writable } = require('stream');
const { promisify } = require('util');
const semver = require('semver');
const test = require('tape');
const undici = require('undici');
const undiciVer = require('undici/package.json').version;

const promisyApmFlush = promisify(apm.flush.bind(apm));
let server;
Expand Down Expand Up @@ -240,15 +242,32 @@ if (global.AbortController) {
{ name: 'aTransName', type: 'manual', sampled: true },
'error.transaction',
);
t.equal(
error.exception.message,
'Request aborted',
'error.exception.message',
);
t.equal(error.exception.type, 'AbortError', 'error.exception.type');
t.equal(error.exception.code, 'UND_ERR_ABORTED', 'error.exception.code');
t.equal(error.exception.module, 'undici', 'error.exception.module');
t.equal(error.exception.handled, true, 'error.exception.handled');
t.equal(error.exception.type, 'AbortError', 'error.exception.type');
if (semver.gte(undiciVer, '6.3.0')) {
// In undici@6.3.0 (https://github.com/nodejs/undici/pull/2592)
// `abort.reason` is used, if any. Node.js core AbortController's
// default reason uses "This operation was aborted".
t.equal(
error.exception.message,
'This operation was aborted',
'error.exception.message',
);
// https://developer.mozilla.org/en-US/docs/Web/API/DOMException#aborterror
t.equal(error.exception.code, '20', 'error.exception.code');
} else {
t.equal(
error.exception.message,
'Request aborted',
'error.exception.message',
);
t.equal(
error.exception.code,
'UND_ERR_ABORTED',
'error.exception.code',
);
t.equal(error.exception.module, 'undici', 'error.exception.module');
}

t.end();
}
Expand Down
63 changes: 36 additions & 27 deletions test/stacktraces/stacktraces.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const {
stackTraceFromErrStackString,
} = require('../../lib/stacktraces');

// Determine Node.js's default `Error.prepareStackTrace` value before any
// tests run that might start the agent, which changes this value.
const defaultNodePrepareStackTraceStr = Error.prepareStackTrace
? Error.prepareStackTrace.name
: 'undefined';

const log = logging.createLogger('off');

// Execute 'node fixtures/throw-an-error.js' and assert APM server gets the
Expand Down Expand Up @@ -452,7 +458,7 @@ tape.test('gatherStackTrace()', function (suite) {
});
});

tape.test('Error.prepareStackTrace is set', function (t) {
tape.test('Error.prepareStackTrace is set when agent active', function (t) {
const server = new MockAPMServer();
server.start(function (serverUrl) {
execFile(
Expand All @@ -479,32 +485,35 @@ tape.test('gatherStackTrace()', function (suite) {
});
});

tape.test('Error.prepareStackTrace is not set', function (t) {
const server = new MockAPMServer();
server.start(function (serverUrl) {
execFile(
process.execPath,
['fixtures/get-prepare-stacktrace.js'],
{
cwd: __dirname,
timeout: 3000,
env: Object.assign({}, process.env, {
ELASTIC_APM_ACTIVE: false,
}),
},
function done(err, _stdout, _stderr) {
t.ok(!err);
t.equals(
_stdout.trim(),
'undefined',
'Error.prepareStackTrace is not set',
);
server.close();
t.end();
},
);
});
});
tape.test(
'Error.prepareStackTrace is Node.js default when agent is inactive',
function (t) {
const server = new MockAPMServer();
server.start(function (serverUrl) {
execFile(
process.execPath,
['fixtures/get-prepare-stacktrace.js'],
{
cwd: __dirname,
timeout: 3000,
env: Object.assign({}, process.env, {
ELASTIC_APM_ACTIVE: false,
}),
},
function done(err, _stdout, _stderr) {
t.ok(!err);
t.equals(
_stdout.trim(),
defaultNodePrepareStackTraceStr,
'Error.prepareStackTrace is the Node.js default',
);
server.close();
t.end();
},
);
});
},
);

suite.end();
});

0 comments on commit 6c6d90a

Please sign in to comment.