diff --git a/cpp/base91/CMakeLists.txt b/cpp/base91/CMakeLists.txt index 9f734e30..137debc5 100644 --- a/cpp/base91/CMakeLists.txt +++ b/cpp/base91/CMakeLists.txt @@ -37,6 +37,7 @@ TARGET_LINK_LIBRARIES(base91lib ) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/base91lib.wasm DESTINATION dist COMPONENT runtime) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/base91lib.wasm DESTINATION dist-test COMPONENT runtime) IF (CMAKE_BUILD_TYPE STREQUAL "Debug") INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/base91lib.wasm.map DESTINATION dist COMPONENT runtime) diff --git a/cpp/expat/expatlib/CMakeLists.txt b/cpp/expat/expatlib/CMakeLists.txt index 4ce580d4..125b28df 100644 --- a/cpp/expat/expatlib/CMakeLists.txt +++ b/cpp/expat/expatlib/CMakeLists.txt @@ -37,6 +37,7 @@ TARGET_LINK_LIBRARIES(expatlib ) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/expatlib.wasm DESTINATION dist COMPONENT runtime) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/expatlib.wasm DESTINATION dist-test COMPONENT runtime) IF (CMAKE_BUILD_TYPE STREQUAL "Debug") INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/expatlib.wasm.map DESTINATION dist COMPONENT runtime) diff --git a/cpp/graphviz/graphvizlib/CMakeLists.txt b/cpp/graphviz/graphvizlib/CMakeLists.txt index 9bd22368..352e116e 100644 --- a/cpp/graphviz/graphvizlib/CMakeLists.txt +++ b/cpp/graphviz/graphvizlib/CMakeLists.txt @@ -90,6 +90,7 @@ TARGET_LINK_LIBRARIES(graphvizlib PRIVATE # ) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/graphvizlib.wasm DESTINATION dist COMPONENT runtime) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/graphvizlib.wasm DESTINATION dist-test COMPONENT runtime) IF (CMAKE_BUILD_TYPE STREQUAL "Debug") INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/graphvizlib.wasm.map DESTINATION dist COMPONENT runtime) diff --git a/cpp/zstd/CMakeLists.txt b/cpp/zstd/CMakeLists.txt index ba80b5b7..b53b8e01 100644 --- a/cpp/zstd/CMakeLists.txt +++ b/cpp/zstd/CMakeLists.txt @@ -37,6 +37,7 @@ TARGET_LINK_LIBRARIES(zstdlib ) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdlib.wasm DESTINATION dist COMPONENT runtime) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdlib.wasm DESTINATION dist-test COMPONENT runtime) IF (CMAKE_BUILD_TYPE STREQUAL "Debug") INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdlib.wasm.map DESTINATION dist COMPONENT runtime) diff --git a/package.json b/package.json index 7373d34d..e4ce260e 100644 --- a/package.json +++ b/package.json @@ -152,4 +152,4 @@ "url": "https://github.com/hpcc-systems/hpcc-js-wasm/issues" }, "homepage": "https://github.com/hpcc-systems/hpcc-js-wasm#readme" -} +} \ No newline at end of file diff --git a/rollup.config.mjs b/rollup.config.mjs index 50a8895e..77b1cb02 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -50,7 +50,7 @@ const nodeTpl = (input, cjsOutput, esOutput) => ({ include: ["lib-es6/__tests__/*.js"], delimiters: ['', ''], values: { - "../index": "../index-node" + "\"../index\"": "\"../index-node\"" } }), nodeResolve({ @@ -99,8 +99,9 @@ export default [ browserTpl("lib-es6/extract", "dist/extract", "dist/extract.es6"), browserTpl("lib-es6/__tests__/index", "dist-test/index", "dist-test/index.es6"), - nodeTpl("lib-es6/__tests__/index", "dist-test/index.node", "dist-test/index.node.es6"), - browserTpl("lib-es6/__tests__/worker", "dist-test/worker", "dist-test/worker.es6"), + nodeTpl("lib-es6/__tests__/index-node", "dist-test/index.node", "dist-test/index.node.es6"), + browserTpl("lib-es6/__tests__/worker-browser", "dist-test/worker", "dist-test/worker.es6"), + nodeTpl("lib-es6/__tests__/worker-node", "dist-test/worker.node", "dist-test/worker.node.es6"), binTpl("lib-es6/__bin__/dot-wasm", "bin/dot-wasm.mjs"), binTpl("lib-es6/__bin__/sfx-wasm", "bin/sfx-wasm.mjs"), diff --git a/src/__tests__/base91.ts b/src/__tests__/base91.ts index 7a00d287..6aec5a3d 100644 --- a/src/__tests__/base91.ts +++ b/src/__tests__/base91.ts @@ -34,32 +34,4 @@ describe("base91", function () { const data2 = zstd.decompress(compressed_data2); expect(data).to.deep.equal(data2); }); - - if (globalThis.window?.Worker) { - it("worker", async function () { - const data = new Uint8Array(Array.from({ length: 1000 }, (_, i) => i % 256)); - - const value = await new Promise(resolve => { - const myWorker = new Worker("dist-test/worker.js"); - myWorker.postMessage(data); - myWorker.onmessage = function (e) { - resolve(e.data); - }; - }); - expect(value).to.deep.equal(data); - }); - - it("worker-es6", async function () { - const data = new Uint8Array(Array.from({ length: 1000 }, (_, i) => i % 256)); - - const value = await new Promise(resolve => { - const myWorker = new Worker("dist-test/worker.es6.js"); - myWorker.postMessage(data); - myWorker.onmessage = function (e) { - resolve(e.data); - }; - }); - expect(value).to.deep.equal(data); - }); - } }); diff --git a/src/__tests__/browser-tests.ts b/src/__tests__/browser-tests.ts new file mode 100644 index 00000000..14ba6ee2 --- /dev/null +++ b/src/__tests__/browser-tests.ts @@ -0,0 +1,29 @@ +import { expect } from "chai"; + +describe("worker-browser", function () { + it("worker-umd", async function () { + const data = new Uint8Array(Array.from({ length: 1000 }, (_, i) => i % 256)); + + const value = await new Promise(resolve => { + const myWorker = new Worker("dist-test/worker.js"); + myWorker.postMessage(data); + myWorker.onmessage = function (e) { + resolve(e.data); + }; + }); + expect(value).to.deep.equal(data); + }); + + it("worker-esm", async function () { + const data = new Uint8Array(Array.from({ length: 1000 }, (_, i) => i % 256)); + + const value = await new Promise(resolve => { + const myWorker = new Worker("dist-test/worker.es6.js"); + myWorker.postMessage(data); + myWorker.onmessage = function (e) { + resolve(e.data); + }; + }); + expect(value).to.deep.equal(data); + }); +}); diff --git a/src/__tests__/index-common.ts b/src/__tests__/index-common.ts new file mode 100644 index 00000000..4158f497 --- /dev/null +++ b/src/__tests__/index-common.ts @@ -0,0 +1,7 @@ +import { wasmFolder } from "../index"; +wasmFolder("dist"); + +export * from "./base91"; +export * from "./expat"; +export * from "./graphviz"; +export * from "./zstd"; diff --git a/src/__tests__/index-node.ts b/src/__tests__/index-node.ts new file mode 100644 index 00000000..e346e00c --- /dev/null +++ b/src/__tests__/index-node.ts @@ -0,0 +1,2 @@ +export * from "./index-common"; +export * from "./node-tests"; \ No newline at end of file diff --git a/src/__tests__/index.ts b/src/__tests__/index.ts index 4158f497..c56f1449 100644 --- a/src/__tests__/index.ts +++ b/src/__tests__/index.ts @@ -1,7 +1,2 @@ -import { wasmFolder } from "../index"; -wasmFolder("dist"); - -export * from "./base91"; -export * from "./expat"; -export * from "./graphviz"; -export * from "./zstd"; +export * from "./index-common"; +export * from "./browser-tests"; diff --git a/src/__tests__/node-tests.ts b/src/__tests__/node-tests.ts new file mode 100644 index 00000000..8f53d669 --- /dev/null +++ b/src/__tests__/node-tests.ts @@ -0,0 +1,30 @@ +import { expect } from "chai"; +import { Worker } from "node:worker_threads"; + +describe("worker-node", function () { + it("worker-cjs", async function () { + const data = new Uint8Array(Array.from({ length: 1000 }, (_, i) => i % 256)); + + const value = await new Promise(resolve => { + const myWorker = new Worker("./dist-test/worker.node.js"); + myWorker.postMessage(data); + myWorker.on("message", function (data) { + resolve(data); + }); + }); + expect(value).to.deep.equal(data); + }); + + it("worker-esm", async function () { + const data = new Uint8Array(Array.from({ length: 1000 }, (_, i) => i % 256)); + + const value = await new Promise(resolve => { + const myWorker = new Worker("./dist-test/worker.node.es6.mjs"); + myWorker.postMessage(data); + myWorker.on("message", function (data) { + resolve(data); + }); + }); + expect(value).to.deep.equal(data); + }); +}); diff --git a/src/__tests__/worker.ts b/src/__tests__/worker-browser.ts similarity index 100% rename from src/__tests__/worker.ts rename to src/__tests__/worker-browser.ts diff --git a/src/__tests__/worker-node.ts b/src/__tests__/worker-node.ts new file mode 100644 index 00000000..f303d1b6 --- /dev/null +++ b/src/__tests__/worker-node.ts @@ -0,0 +1,11 @@ +import { parentPort } from "node:worker_threads"; +import { Base91 } from "../index-node"; + +parentPort?.on("message", async function (data) { + const base91 = await Base91.load(); + const base91Str = base91.encode(data); + const data2 = base91.decode(base91Str); + parentPort?.postMessage(data2); + process.exit(0); +}); +