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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"types": "./pkg/orchestrion_js.d.ts",
"scripts": {
"build": "wasm-pack build --target nodejs --release -- --features wasm",
"test": "node ./tests/tests.mjs"
"test": "node ./tests/wasm/tests.mjs"
},
"dependencies": {
"wasm-pack": "^0.13.1"
Expand Down
36 changes: 1 addition & 35 deletions tests/tests.mjs → tests/wasm/testdata/expected.mjs
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
import { create } from "../pkg/orchestrion_js.js";
import * as assert from "node:assert";

const instrumentor = create([
{
channelName: "up:constructor",
module: { name: "one", versionRange: ">=1", filePath: "index.js" },
functionQuery: { className: "Up" },
},
{
channelName: "up:fetch",
module: { name: "one", versionRange: ">=1", filePath: "index.js" },
functionQuery: {
className: "Up",
methodName: "fetch",
kind: "Sync",
},
},
]);

const matchedTransforms = instrumentor.getTransformer(
"one",
"1.0.0",
"index.js",
);

assert.ok(matchedTransforms);

const output = matchedTransforms.transform(
"export class Up { constructor() {console.log('constructor')} fetch() {console.log('fetch')} }",
true,
);

assert.strictEqual(output, `import { tracingChannel as tr_ch_apm_tracingChannel } from "diagnostics_channel";
import { tracingChannel as tr_ch_apm_tracingChannel } from "diagnostics_channel";
const tr_ch_apm$up:fetch = tr_ch_apm_tracingChannel("orchestrion:one:up:fetch");
const tr_ch_apm$up:constructor = tr_ch_apm_tracingChannel("orchestrion:one:up:constructor");
export class Up {
Expand Down Expand Up @@ -71,4 +38,3 @@ export class Up {
});
}
}
`);
9 changes: 9 additions & 0 deletions tests/wasm/testdata/original.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class Up {
constructor() {
console.log('constructor')
}

fetch() {
console.log('fetch')
}
}
35 changes: 35 additions & 0 deletions tests/wasm/tests.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { create } from "../../pkg/orchestrion_js.js";
import * as assert from "node:assert";
import fs from 'node:fs/promises'
import path from 'node:path'

const instrumentor = create([
{
channelName: "up:constructor",
module: { name: "one", versionRange: ">=1", filePath: "index.js" },
functionQuery: { className: "Up" },
},
{
channelName: "up:fetch",
module: { name: "one", versionRange: ">=1", filePath: "index.js" },
functionQuery: {
className: "Up",
methodName: "fetch",
kind: "Sync",
},
},
]);

const matchedTransforms = instrumentor.getTransformer(
"one",
"1.0.0",
"index.js",
);

assert.ok(matchedTransforms);

const original = await fs.readFile(path.join(import.meta.dirname, './testdata/original.mjs'))
const output = matchedTransforms.transform(original.toString('utf8'), true);

const expected = await fs.readFile(path.join(import.meta.dirname, './testdata/expected.mjs'))
assert.strictEqual(output, expected.toString('utf8'));