diff --git a/package.json b/package.json index c0f79cd..ae0d04b 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/tests/tests.mjs b/tests/wasm/testdata/expected.mjs similarity index 60% rename from tests/tests.mjs rename to tests/wasm/testdata/expected.mjs index 3c6637f..9d3e514 100644 --- a/tests/tests.mjs +++ b/tests/wasm/testdata/expected.mjs @@ -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 { @@ -71,4 +38,3 @@ export class Up { }); } } -`); diff --git a/tests/wasm/testdata/original.mjs b/tests/wasm/testdata/original.mjs new file mode 100644 index 0000000..c55116c --- /dev/null +++ b/tests/wasm/testdata/original.mjs @@ -0,0 +1,9 @@ +export class Up { + constructor() { + console.log('constructor') + } + + fetch() { + console.log('fetch') + } +} \ No newline at end of file diff --git a/tests/wasm/tests.mjs b/tests/wasm/tests.mjs new file mode 100644 index 0000000..1aacf2c --- /dev/null +++ b/tests/wasm/tests.mjs @@ -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'));