Skip to content

Commit 8b25b2d

Browse files
committed
test(node): Cover mongoose callback signature against real v6
The instrumentation supports the callback form (mongoose 5/6) by forwarding the original `arguments` and swapping the callback slot by position. Exercise `save(callback)` end-to-end against real mongoose 6 and assert the callback receives the saved document, so the positional handling is covered (the unit test's fake finds the callback by type, not position).
1 parent 3b32be8 commit 8b25b2d

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

  • dev-packages/node-integration-tests/suites/tracing/mongoose

dev-packages/node-integration-tests/suites/tracing/mongoose/scenario.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ async function run() {
2929

3030
await BlogPost.findOne({});
3131

32+
// Callback form (mongoose 5/6 only): the callback is passed as the sole argument, so it must
33+
// be forwarded in the correct position. Reject if the callback doesn't receive the saved doc.
34+
await new Promise((resolve, reject) => {
35+
new BlogPost({ title: 'Callback', body: 'cb', date: new Date() }).save((err, doc) => {
36+
if (err) {
37+
reject(err);
38+
} else if (!doc || doc.title !== 'Callback') {
39+
reject(new Error('save(callback) did not receive the saved document'));
40+
} else {
41+
resolve();
42+
}
43+
});
44+
});
45+
3246
await BlogPost.aggregate([{ $match: {} }]);
3347

3448
await BlogPost.insertMany([{ title: 'Insert', body: 'Insert body', date: new Date() }]);

0 commit comments

Comments
 (0)