From af68a3f6c1f9561499feb0c68974ca6619ed4164 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Mon, 3 Oct 2022 09:35:07 -0700 Subject: [PATCH 1/5] chore: add test for structural copying --- test/test-cid.spec.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test-cid.spec.js b/test/test-cid.spec.js index 47754aa8..aa1e044f 100644 --- a/test/test-cid.spec.js +++ b/test/test-cid.spec.js @@ -7,6 +7,7 @@ import { base32 } from '../src/bases/base32.js' import { base64 } from '../src/bases/base64.js' import { sha256, sha512 } from '../src/hashes/sha2.js' import invalidMultihash from './fixtures/invalid-multihash.js' +import { MessageChannel } from './ import OLDCID from 'cids' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' @@ -704,4 +705,12 @@ describe('CID', () => { assert.isFalse(Object.keys(cid).includes('asCID')) assert.equal(cid.asCID, cid) }) + + it('CID can be moved across JS realms', async () => { + const cid = CID.parse('bafybeif2pall7dybz7vecqka3zo24irdwabwdi4wc55jznaq75q7eaavvu') + const { port1: sender, port2: receiver } = new MessageChannel() + sender.postMessage(cid) + const cid2 = await new Promise(resolve => receiver.onmessage = event => resolve(event.data)) + assert.equal(cid2.asCID, cid2) + }) }) From b6a8b12e05073c2ce6c536e0a669d9121cf5ef35 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Mon, 3 Oct 2022 09:35:57 -0700 Subject: [PATCH 2/5] fix: remove generated import --- test/test-cid.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test-cid.spec.js b/test/test-cid.spec.js index aa1e044f..1ed409fa 100644 --- a/test/test-cid.spec.js +++ b/test/test-cid.spec.js @@ -7,7 +7,6 @@ import { base32 } from '../src/bases/base32.js' import { base64 } from '../src/bases/base64.js' import { sha256, sha512 } from '../src/hashes/sha2.js' import invalidMultihash from './fixtures/invalid-multihash.js' -import { MessageChannel } from './ import OLDCID from 'cids' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' From 96a5859edc94768edb6432f47fa3b989b5774d78 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Mon, 3 Oct 2022 09:38:14 -0700 Subject: [PATCH 3/5] fix: lint errors --- test/test-cid.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-cid.spec.js b/test/test-cid.spec.js index 1ed409fa..1eee3677 100644 --- a/test/test-cid.spec.js +++ b/test/test-cid.spec.js @@ -704,7 +704,7 @@ describe('CID', () => { assert.isFalse(Object.keys(cid).includes('asCID')) assert.equal(cid.asCID, cid) }) - + it('CID can be moved across JS realms', async () => { const cid = CID.parse('bafybeif2pall7dybz7vecqka3zo24irdwabwdi4wc55jznaq75q7eaavvu') const { port1: sender, port2: receiver } = new MessageChannel() From e384063f0e884f84b7325601ed389a2100cae127 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Mon, 3 Oct 2022 09:43:44 -0700 Subject: [PATCH 4/5] fix: another attempt to make eslint happy --- test/test-cid.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test-cid.spec.js b/test/test-cid.spec.js index 1eee3677..8aff3a0c 100644 --- a/test/test-cid.spec.js +++ b/test/test-cid.spec.js @@ -709,7 +709,9 @@ describe('CID', () => { const cid = CID.parse('bafybeif2pall7dybz7vecqka3zo24irdwabwdi4wc55jznaq75q7eaavvu') const { port1: sender, port2: receiver } = new MessageChannel() sender.postMessage(cid) - const cid2 = await new Promise(resolve => receiver.onmessage = event => resolve(event.data)) + const cid2 = await new Promise((resolve) => { + receiver.onmessage = event => resolve(event.data) + }) assert.equal(cid2.asCID, cid2) }) }) From 9b0931fb9993d1c9881268eeffdfe5ecbf323197 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Mon, 3 Oct 2022 09:44:36 -0700 Subject: [PATCH 5/5] chore: and another attemp to make eslint happy --- test/test-cid.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-cid.spec.js b/test/test-cid.spec.js index 8aff3a0c..d203c17d 100644 --- a/test/test-cid.spec.js +++ b/test/test-cid.spec.js @@ -710,7 +710,7 @@ describe('CID', () => { const { port1: sender, port2: receiver } = new MessageChannel() sender.postMessage(cid) const cid2 = await new Promise((resolve) => { - receiver.onmessage = event => resolve(event.data) + receiver.onmessage = (event) => { resolve(event.data) } }) assert.equal(cid2.asCID, cid2) })