Skip to content

Commit 360dfdc

Browse files
committed
most unit tests work now
1 parent d31d1c1 commit 360dfdc

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/sdk/src/signature/SignatureValidationWorker.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ const workerApi = {
1111
export type SignatureValidationWorkerApi = typeof workerApi
1212

1313
// Detect environment and expose accordingly
14-
if (typeof self !== 'undefined') {
15-
// Browser Web Worker
16-
Comlink.expose(workerApi)
17-
} else {
18-
// Node.js Worker Thread
14+
// Check for Node.js worker_threads first, since `self` is defined in both environments
15+
// but only browser Web Workers have WorkerGlobalScope with addEventListener
16+
let parentPort: import('worker_threads').MessagePort | null = null
17+
try {
1918
// eslint-disable-next-line @typescript-eslint/no-require-imports
20-
const { parentPort } = require('worker_threads')
19+
parentPort = require('worker_threads').parentPort
20+
} catch {
21+
// Not in Node.js environment
22+
}
23+
24+
if (parentPort) {
25+
// Node.js Worker Thread
2126
// eslint-disable-next-line @typescript-eslint/no-require-imports
2227
const nodeEndpoint = require('comlink/dist/umd/node-adapter')
2328
Comlink.expose(workerApi, nodeEndpoint(parentPort))
29+
} else {
30+
// Browser Web Worker
31+
Comlink.expose(workerApi)
2432
}

packages/sdk/test/unit/SignatureValidator.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('SignatureValidator', () => {
2424

2525
describe('SECP256K1', () => {
2626

27-
it.only('unencrypted message passes signature validation', async () => {
27+
it('unencrypted message passes signature validation', async () => {
2828
const message = new StreamMessage({
2929
messageId: new MessageID(
3030
toStreamID('streamr.eth/foo/bar'),

0 commit comments

Comments
 (0)