From 54bfca002de63f67aced69330f985a2ad70e139d Mon Sep 17 00:00:00 2001 From: Nikita Skovoroda Date: Tue, 12 Nov 2024 07:58:35 +0400 Subject: [PATCH] test: clean up test:webcrypto logic --- package.json | 2 +- test/index.js | 10 +++++++--- ...{secp256k1.webcrypto.test.js => index.webcrypto.js} | 10 +++++----- 3 files changed, 13 insertions(+), 9 deletions(-) rename test/{secp256k1.webcrypto.test.js => index.webcrypto.js} (63%) diff --git a/package.json b/package.json index de64f04..0e28cc6 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "build:mingz": "npm run --silent build:min | gzip -c8", "build:release": "npm run --silent build:min > test/build/noble-secp256k1.min.js; npm run --silent build:mingz > test/build/noble-secp256k1.min.js.gz", "test": "node test/index.js", - "test:webcrypto": "node test/secp256k1.webcrypto.test.js", + "test:webcrypto": "node test/index.webcrypto.js", "bench": "node test/benchmark.js", "loc": "echo \"`npm run --silent build:min | wc -c` symbols `wc -l < index.ts` LOC, `npm run --silent build:mingz | wc -c`B gzipped\"" }, diff --git a/test/index.js b/test/index.js index 62b9695..ea1f84a 100644 --- a/test/index.js +++ b/test/index.js @@ -1,5 +1,9 @@ import { should } from 'micro-should'; -import * as t1 from './basic.test.js'; -import * as t2 from './secp256k1.test.js'; +import './basic.test.js'; +import './secp256k1.test.js'; -should.run(); \ No newline at end of file +if (!globalThis.crypto) { + console.error('global crypto not found (old Node.js?), perhaps you meant to run test:webcrypto'); +} + +should.run(); diff --git a/test/secp256k1.webcrypto.test.js b/test/index.webcrypto.js similarity index 63% rename from test/secp256k1.webcrypto.test.js rename to test/index.webcrypto.js index 2dd0cd0..c6b88e8 100644 --- a/test/secp256k1.webcrypto.test.js +++ b/test/index.webcrypto.js @@ -1,9 +1,9 @@ +import { should } from 'micro-should'; +import './basic.test.js'; +import './secp256k1.test.js'; + +// A copy of index.js with polyfilled globalThis.crypto to run on Node.js 18 import { webcrypto } from 'node:crypto'; -// @ts-ignore if (!globalThis.crypto) globalThis.crypto = webcrypto; -import './secp256k1.test.js'; - -// Force ESM import to execute -import { should } from 'micro-should'; should.run();