-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest.js
More file actions
38 lines (32 loc) · 1.36 KB
/
test.js
File metadata and controls
38 lines (32 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
* This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2025 Datadog, Inc.
**/
const { fetch_simple, fetch_complex } = require('./instrumented.js');
const assert = require('assert');
const { tracingChannel } = require('diagnostics_channel');
const handler = {
start (message) {
const originalCb = message.arguments[1];
const wrappedCb = function (a, b) {
assert.strictEqual(this.this, 'this');
assert.strictEqual(a, 'arg1');
assert.strictEqual(b, 'arg2');
arguments[1] = 'arg2_mutated';
return originalCb.apply(this, arguments);
}
message.arguments[1] = wrappedCb;
}
};
tracingChannel('orchestrion:undici:fetch_simple').subscribe(handler);
tracingChannel('orchestrion:undici:fetch_complex').subscribe(handler);
assert.strictEqual(fetch_simple.length, 2);
assert.strictEqual(fetch_complex.length, 2);
const cb = function (a, b) {
assert.strictEqual(this.this, 'this');
assert.strictEqual(a, 'arg1');
assert.strictEqual(b, 'arg2_mutated');
return 'result';
};
assert.strictEqual(fetch_simple.apply({ this: 'this' }, ['https://example.com', cb]), 'return');
assert.strictEqual(fetch_complex.apply({ this: 'this' }, [{ url: 'https://example.com', tuple: [] }, cb]), 'return');