-
-
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.
- Loading branch information
1 parent
0b8831c
commit a01c7d6
Showing
3 changed files
with
26 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
import { config, string } from '@tdewolff/minify'; | ||
import { workerData, parentPort } from 'node:worker_threads'; | ||
import { Worker, isMainThread, workerData, parentPort } from 'node:worker_threads'; | ||
|
||
config({'html-keep-document-tags': true}) | ||
parentPort.postMessage(string("text/html", workerData)); | ||
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)); | ||
} |