Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions src/__tests__/classMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,11 @@ describe(makeClassMap, () => {
expect(makeClassMap(functions)).toStrictEqual<AppMap.ClassMap>([
{
type: "package",
name: "foo",
children: [
{
type: "class",
name: "foo",
children: [
{ type: "function", name: "foo", static: true, location: "/test/app/src/foo.js:3" },
],
},
],
},
{
type: "package",
name: "util",
name: "src",
children: [
{
type: "package",
name: "other",
name: "util",
children: [
{
type: "class",
Expand All @@ -49,6 +36,13 @@ describe(makeClassMap, () => {
},
],
},
{
type: "class",
name: "foo",
children: [
{ type: "function", name: "foo", static: true, location: "/test/app/src/foo.js:3" },
],
},
{
type: "class",
name: "util",
Expand Down Expand Up @@ -110,7 +104,7 @@ function f(
id,
params: [],
static: static_,
klassOrPkg: klass,
klassOrFile: klass,
location,
};
}
4 changes: 2 additions & 2 deletions src/__tests__/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe(registry.createFunctionInfo, () => {
params: [],
location: { path: "test.js", lineno: 42 },
static: true,
klassOrPkg: "test",
klassOrFile: "test",
});
});
});
Expand Down Expand Up @@ -56,7 +56,7 @@ describe(registry.createMethodInfo, () => {
generator: false,
params: [],
id: "testMethod",
klassOrPkg: "TestClass",
klassOrFile: "TestClass",
location: undefined,
static: false,
});
Expand Down
7 changes: 3 additions & 4 deletions src/classMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ export function makeClassMap(funs: Iterable<FunctionInfo>): AppMap.ClassMap {
for (const fun of sortFunctions(funs)) {
if (!fun.location) continue;
const pkgs = fun.location.path.replace(/\..+$/, "").split(sep).reverse();
assert(pkgs.length > 0);
if (pkgs.length > 1) pkgs.shift(); // remove the file name (e.g. "foo.js")

let [tree, classes]: FNode = [root, {}];
let pkg = "";
while (pkgs.length > 0) {
pkg = pkgs.pop()!;
const pkg = pkgs.pop()!;
[tree, classes] = tree[pkg] ||= [{}, {}];
}
(classes[fun.klassOrPkg] ||= []).push(fun);
(classes[fun.klassOrFile] ||= []).push(fun);
}

let result = makeTree(root);
Expand Down
2 changes: 1 addition & 1 deletion src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function makeCallEvent(
static: !thisArg,
receiver: optParameter(thisArg),
parameters: resolveParameters(args, fun),
defined_class: fun.klassOrPkg,
defined_class: fun.klassOrFile,
...fun.location,
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/__tests__/instrument.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe(instrument.transform, () => {
"path": "test.js",
"lineno": 2
},
"klassOrPkg": "test",
"klassOrFile": "test",
"static": true
}];

Expand All @@ -64,7 +64,7 @@ describe(instrument.transform, () => {
generator: false,
location: { path: "test.js", lineno: 2 },
static: true,
klassOrPkg: "test",
klassOrFile: "test",
});
});

Expand All @@ -91,7 +91,7 @@ describe(instrument.transform, () => {
"name": "value"
}],
"static": false,
"klassOrPkg": "TestClass",
"klassOrFile": "TestClass",
"location": {
"path": "test.js",
"lineno": 3
Expand All @@ -110,7 +110,7 @@ describe(instrument.transform, () => {
expect(instrument.transformedFunctionInfos[0]).toStrictEqual<registry.FunctionInfo>({
params: [{ type: "Identifier", name: "value" }],
id: "foo",
klassOrPkg: "TestClass",
klassOrFile: "TestClass",
static: false,
async: false,
generator: false,
Expand Down
6 changes: 3 additions & 3 deletions src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface FunctionInfo {
params: ESTree.Parameter[];
static: boolean;
/** Class name, or the package name for a free function */
klassOrPkg: string;
klassOrFile: string;
location?: SourceLocation;
}

Expand All @@ -31,7 +31,7 @@ export function createFunctionInfo(
id: id.name,
params: params.map(stripLocation),
location,
klassOrPkg: pkgOfPath(location.path),
klassOrFile: pkgOfPath(location.path),
static: true,
};
return info;
Expand All @@ -52,7 +52,7 @@ export function createMethodInfo(
id: key.name,
params: params.map(stripLocation),
static: method.static,
klassOrPkg: klass.id.name,
klassOrFile: klass.id.name,
location,
};
return info;
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/httpClient.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ exports[`mapping http client requests (ESM) 1`] = `
"type": "class",
},
],
"name": "esm",
"name": "httpClient",
"type": "package",
},
],
Expand Down Expand Up @@ -192,7 +192,7 @@ exports[`mapping http client requests 1`] = `
"type": "class",
},
],
"name": "index",
"name": "httpClient",
"type": "package",
},
],
Expand Down Expand Up @@ -360,7 +360,7 @@ exports[`mapping mocked http client requests 1`] = `
"type": "class",
},
],
"name": "index",
"name": "httpClient",
"type": "package",
},
],
Expand Down
8 changes: 4 additions & 4 deletions test/__snapshots__/httpServer.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`mapping Express.js requests 1`] = `
"type": "class",
},
],
"name": "express",
"name": "httpServer",
"type": "package",
},
],
Expand Down Expand Up @@ -180,7 +180,7 @@ exports[`mapping Express.js requests 1`] = `
"type": "class",
},
],
"name": "express",
"name": "httpServer",
"type": "package",
},
],
Expand Down Expand Up @@ -351,7 +351,7 @@ exports[`mapping Express.js requests 1`] = `
"type": "class",
},
],
"name": "express",
"name": "httpServer",
"type": "package",
},
],
Expand Down Expand Up @@ -633,7 +633,7 @@ exports[`mapping Express.js requests with remote recording 1`] = `
"type": "class",
},
],
"name": "express",
"name": "httpServer",
"type": "package",
},
],
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/mocha.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`mapping Mocha tests 1`] = `
"type": "class",
},
],
"name": "test",
"name": "mocha",
"type": "package",
},
],
Expand Down Expand Up @@ -92,7 +92,7 @@ exports[`mapping Mocha tests 1`] = `
"type": "class",
},
],
"name": "calc",
"name": "mocha",
"type": "package",
},
],
Expand Down Expand Up @@ -173,7 +173,7 @@ exports[`mapping Mocha tests 1`] = `
"type": "class",
},
],
"name": "calc",
"name": "mocha",
"type": "package",
},
],
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/mysql.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports[`mapping MySQL tests 1`] = `
"type": "class",
},
],
"name": "index",
"name": "mysql",
"type": "package",
},
],
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/next.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`mapping a Next.js appmap 1`] = `
"type": "class",
},
],
"name": "route",
"name": "hello",
"type": "package",
},
],
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/postgres.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports[`mapping PostgreSQL tests 1`] = `
"type": "class",
},
],
"name": "index",
"name": "postgres",
"type": "package",
},
],
Expand Down
Loading