-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Instrument calls to libraries - ESM support
- Loading branch information
1 parent
567929c
commit 5610984
Showing
4 changed files
with
250 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
import * as AppMap from "../src/AppMap"; | ||
import { integrationTest, readAppmaps, runAppmapNode } from "./helpers"; | ||
|
||
integrationTest("mapping standard library calls", () => { | ||
expect(runAppmapNode("yarn", "exec", "ts-node", "index.ts").status).toBe(0); | ||
|
||
const appmaps = readAppmaps(); | ||
// properties of "console" object can be different accross node versions | ||
fixAppMaps(appmaps); | ||
|
||
expect(appmaps).toMatchSnapshot(); | ||
}); | ||
|
||
integrationTest("mapping standard library calls - ESM", () => { | ||
expect(runAppmapNode("index.mjs").status).toBe(0); | ||
|
||
const appmaps = readAppmaps(); | ||
fixAppMaps(appmaps); | ||
|
||
expect(appmaps).toMatchSnapshot(); | ||
}); | ||
|
||
// properties of "console" object can be different accross node versions | ||
function fixAppMaps(appmaps: Record<string, AppMap.AppMap>) { | ||
for (const key in appmaps) { | ||
appmaps[key].events?.forEach((e) => { | ||
if (e.event == "call" && "receiver" in e) delete e.receiver?.properties; | ||
}); | ||
} | ||
|
||
expect(appmaps).toMatchSnapshot(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import console from "node:console"; | ||
import json5 from "json5"; | ||
|
||
console.log("Hello World"); | ||
|
||
// This calls console.log internally, and this internal | ||
// console.log call won't be recorded in shallow mode. | ||
// https://github.com/nodejs/node/blob/57d2e4881c9a7f9ac52d49d19d781dc455b2789d/lib/internal/console/constructor.js#L475 | ||
console.count("abc"); | ||
|
||
console.warn("This is excluded in settings"); | ||
|
||
const obj = json5.parse("{ a: 123 }"); | ||
console.log("obj", obj); |