-
-
Notifications
You must be signed in to change notification settings - Fork 224
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 #510 from perrin4869/chore/nodejs/test-worker-threads
Node.JS bindings Worker threads segfault reproduction
- Loading branch information
Showing
3 changed files
with
27 additions
and
1 deletion.
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
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,26 @@ | ||
import { Worker, isMainThread, workerData, parentPort } from 'node:worker_threads'; | ||
|
||
if (isMainThread) { | ||
let input = "<html><span style=\"color:#ff0000;\">A phrase</span>"; | ||
const worker = new Worker(new URL(import.meta.url), { | ||
workerData: input, | ||
}); | ||
|
||
let expected = "<html><span style=color:red>A phrase</span>"; | ||
let output = await new Promise((resolve, reject) => { | ||
worker.on('message', resolve); | ||
worker.on('error', reject); | ||
worker.on('exit', (code) => { | ||
if (code !== 0) | ||
reject(new Error(`Worker stopped with exit code ${code}`)); | ||
}); | ||
}) | ||
if (output != expected) { | ||
throw "unexpected output using worker threads: '"+output+"' instead of '"+expected+"'"; | ||
} | ||
await worker.terminate(); | ||
} else { | ||
const { config, string } = await import('@tdewolff/minify'); | ||
config({'html-keep-document-tags': true}) | ||
parentPort.postMessage(string("text/html", workerData)); | ||
} |