From: Chris Duncan Date: Thu, 5 Dec 2024 14:48:15 +0000 (-0800) Subject: Scrap this node polyfill idea and move on to a different testing tool. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=d825933c028f09e0f7e6d5669b36b8d2b2979593;p=libnemo.git Scrap this node polyfill idea and move on to a different testing tool. --- diff --git a/src/lib/bip44-ckd.ts b/src/lib/bip44-ckd.ts index 00a6dce..97777c3 100644 --- a/src/lib/bip44-ckd.ts +++ b/src/lib/bip44-ckd.ts @@ -1,34 +1,12 @@ // SPDX-FileCopyrightText: 2024 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later -import { isMainThread, parentPort } from 'node:worker_threads' - type ExtendedKey = { privateKey: DataView chainCode: DataView } const b = () => { - /** - * Polyfill for window methods which do not exist when executing Node.js tests. - */ - console.log(`isMainThread: ${isMainThread}`) - console.log(`parentPort: ${parentPort}`) - if (typeof window === 'undefined' && typeof self === 'undefined') { - console.log(`in one`) - try { - if (!isMainThread && parentPort) { - console.log(`in two`) - //@ts-expect-error - var addEventListener = addEventListener || Object.getPrototypeOf(parentPort).addListener.bind(parentPort) - //@ts-expect-error - var postMessage = postMessage || Object.getPrototypeOf(parentPort).postMessage.bind(parentPort) - } - } catch { } - } - console.log(`typeof addEventListener: ${typeof addEventListener}`) - console.log(`typeof postMessage: ${typeof postMessage}`) - console.log(' ') const BIP44_COIN_NANO = 165 const BIP44_PURPOSE = 44 @@ -38,16 +16,14 @@ const b = () => { /** * Listens for messages from a calling function. */ - if (typeof addEventListener === 'function') { - addEventListener('message', (message: any): void => { - console.log(`bip44 worker`) - const data = JSON.parse(new TextDecoder().decode(message.data ?? message)) - calculate(data).then(results => { - const buf = new TextEncoder().encode(JSON.stringify(results)).buffer - postMessage(buf, [buf]) - }) + addEventListener('message', (message: any): void => { + const data = JSON.parse(new TextDecoder().decode(message.data ?? message)) + calculate(data).then(results => { + const buf = new TextEncoder().encode(JSON.stringify(results)).buffer + //@ts-expect-error + postMessage(buf, [buf]) }) - } + }) async function calculate (data: any[]): Promise { return new Promise(async (resolve) => { diff --git a/src/lib/pool.ts b/src/lib/pool.ts index 4c48300..49e1188 100644 --- a/src/lib/pool.ts +++ b/src/lib/pool.ts @@ -1,17 +1,6 @@ // SPDX-FileCopyrightText: 2024 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later -/** -* Polyfill for window methods which do not exist when executing Node.js tests. -*/ -if (typeof window === 'undefined' && typeof self === 'undefined') { - const { Worker } = await import('node:worker_threads') - //@ts-expect-error - Worker.prototype.addEventListener = Worker.prototype.addListener - //@ts-expect-error - globalThis.Worker = Worker -} - type Thread = { isBusy: boolean worker: Worker