-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from GordonSmith/NODEJS_WORKER
chore: Add specific NodeJS worker test
- Loading branch information
Showing
14 changed files
with
90 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { wasmFolder } from "../index"; | ||
wasmFolder("dist"); | ||
|
||
export * from "./base91"; | ||
export * from "./expat"; | ||
export * from "./graphviz"; | ||
export * from "./zstd"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./index-common"; | ||
export * from "./node-tests"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
|