Skip to content

Commit bec4711

Browse files
authored
Reorganize wasm unit testing (#2)
1 parent 2ab74b2 commit bec4711

File tree

4 files changed

+46
-36
lines changed

4 files changed

+46
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"types": "./pkg/orchestrion_js.d.ts",
1818
"scripts": {
1919
"build": "wasm-pack build --target nodejs --release -- --features wasm",
20-
"test": "node ./tests/tests.mjs"
20+
"test": "node ./tests/wasm/tests.mjs"
2121
},
2222
"dependencies": {
2323
"wasm-pack": "^0.13.1"
Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,4 @@
1-
import { create } from "../pkg/orchestrion_js.js";
2-
import * as assert from "node:assert";
3-
4-
const instrumentor = create([
5-
{
6-
channelName: "up:constructor",
7-
module: { name: "one", versionRange: ">=1", filePath: "index.js" },
8-
functionQuery: { className: "Up" },
9-
},
10-
{
11-
channelName: "up:fetch",
12-
module: { name: "one", versionRange: ">=1", filePath: "index.js" },
13-
functionQuery: {
14-
className: "Up",
15-
methodName: "fetch",
16-
kind: "Sync",
17-
},
18-
},
19-
]);
20-
21-
const matchedTransforms = instrumentor.getTransformer(
22-
"one",
23-
"1.0.0",
24-
"index.js",
25-
);
26-
27-
assert.ok(matchedTransforms);
28-
29-
const output = matchedTransforms.transform(
30-
"export class Up { constructor() {console.log('constructor')} fetch() {console.log('fetch')} }",
31-
true,
32-
);
33-
34-
assert.strictEqual(output, `import { tracingChannel as tr_ch_apm_tracingChannel } from "diagnostics_channel";
1+
import { tracingChannel as tr_ch_apm_tracingChannel } from "diagnostics_channel";
352
const tr_ch_apm$up:fetch = tr_ch_apm_tracingChannel("orchestrion:one:up:fetch");
363
const tr_ch_apm$up:constructor = tr_ch_apm_tracingChannel("orchestrion:one:up:constructor");
374
export class Up {
@@ -71,4 +38,3 @@ export class Up {
7138
});
7239
}
7340
}
74-
`);

tests/wasm/testdata/original.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class Up {
2+
constructor() {
3+
console.log('constructor')
4+
}
5+
6+
fetch() {
7+
console.log('fetch')
8+
}
9+
}

tests/wasm/tests.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { create } from "../../pkg/orchestrion_js.js";
2+
import * as assert from "node:assert";
3+
import fs from 'node:fs/promises'
4+
import path from 'node:path'
5+
6+
const instrumentor = create([
7+
{
8+
channelName: "up:constructor",
9+
module: { name: "one", versionRange: ">=1", filePath: "index.js" },
10+
functionQuery: { className: "Up" },
11+
},
12+
{
13+
channelName: "up:fetch",
14+
module: { name: "one", versionRange: ">=1", filePath: "index.js" },
15+
functionQuery: {
16+
className: "Up",
17+
methodName: "fetch",
18+
kind: "Sync",
19+
},
20+
},
21+
]);
22+
23+
const matchedTransforms = instrumentor.getTransformer(
24+
"one",
25+
"1.0.0",
26+
"index.js",
27+
);
28+
29+
assert.ok(matchedTransforms);
30+
31+
const original = await fs.readFile(path.join(import.meta.dirname, './testdata/original.mjs'))
32+
const output = matchedTransforms.transform(original.toString('utf8'), true);
33+
34+
const expected = await fs.readFile(path.join(import.meta.dirname, './testdata/expected.mjs'))
35+
assert.strictEqual(output, expected.toString('utf8'));

0 commit comments

Comments
 (0)