]> zoso.dev Git - libnemo.git/commitdiff
Scrap this node polyfill idea and move on to a different testing tool.
authorChris Duncan <chris@zoso.dev>
Thu, 5 Dec 2024 14:48:15 +0000 (06:48 -0800)
committerChris Duncan <chris@zoso.dev>
Thu, 5 Dec 2024 14:48:15 +0000 (06:48 -0800)
src/lib/bip44-ckd.ts
src/lib/pool.ts

index 00a6dce24067228f2e3fe8411f68249dcb3eec35..97777c30213ff3f289d1ad2fdde01b1cbd267d1d 100644 (file)
@@ -1,34 +1,12 @@
 // SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>
 // 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<any[]> {
                return new Promise(async (resolve) => {
index 4c4830028754ce38cc94635f3ec527e322c7db5f..49e1188722ac08dfd167c4edebcb2c743cdb65b6 100644 (file)
@@ -1,17 +1,6 @@
 // SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>
 // 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