Skip to content

Commit 52eb941

Browse files
committed
Adds nodejs smoketest
1 parent cdf89e1 commit 52eb941

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
"scripts": {
1010
"build": "rollup -c",
1111
"test:unit": "karma start",
12+
"test:node": "mocha ./tests/node/main.mjs",
1213
"test:types": "tsc -p ./tests/tsconfig.json",
1314
"test:types:watch": "npm run test:types -- --watch",
14-
"test": "npm run fmt_test && npm run build && npm run test:types && npm run test:unit",
15+
"test": "npm run fmt_test && npm run build && npm run test:types && npm run test:unit && npm run test:node",
1516
"fmt": "prettier --write './*.{mjs,js,ts,md,json,html}' './{src,docs,tests}/{,**/}*.{mjs,js,ts,md,json,html}'",
1617
"fmt_test": "test $(prettier -l './*.{mjs,js,ts,md,json,html}' './{src,docs,tests}/{**/,}*.{mjs,js,ts,md,json,html}' | wc -l) -eq 0",
1718
"watchtest": "CHROME_ONLY=1 karma start --no-single-run"
@@ -28,7 +29,7 @@
2829
"devDependencies": {
2930
"@rollup/plugin-terser": "0.4.0",
3031
"@rollup/plugin-typescript": "11.0.0",
31-
"chai": "4.3.7",
32+
"chai": "^4.3.7",
3233
"conditional-type-checks": "1.0.6",
3334
"husky": "8.0.3",
3435
"karma": "6.4.1",

tests/node/main.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Worker } from "worker_threads";
2+
import * as Comlink from "../../dist/esm/comlink.mjs";
3+
import nodeEndpoint from "../../dist/esm/node-adapter.mjs";
4+
import { expect } from "chai";
5+
6+
describe("node", () => {
7+
describe("Comlink across workers", function () {
8+
beforeEach(function () {
9+
this.worker = new Worker("./tests/node/worker.mjs");
10+
});
11+
12+
afterEach(function () {
13+
this.worker.terminate();
14+
});
15+
16+
it("can communicate", async function () {
17+
const proxy = Comlink.wrap(nodeEndpoint(this.worker));
18+
expect(await proxy(1, 3)).to.equal(4);
19+
});
20+
21+
it("can tunnels a new endpoint with createEndpoint", async function () {
22+
const proxy = Comlink.wrap(nodeEndpoint(this.worker));
23+
const otherEp = await proxy[Comlink.createEndpoint]();
24+
const otherProxy = Comlink.wrap(otherEp);
25+
expect(await otherProxy(20, 1)).to.equal(21);
26+
});
27+
});
28+
});

tests/node/worker.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { parentPort } from "worker_threads";
2+
import * as Comlink from "../../dist/esm/comlink.mjs";
3+
import nodeEndpoint from "../../dist/esm/node-adapter.mjs";
4+
5+
Comlink.expose((a, b) => a + b, nodeEndpoint(parentPort));

0 commit comments

Comments
 (0)