Skip to content

Commit

Permalink
Hack nodejs module loader for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Jan 13, 2025
1 parent d0d0f63 commit 16927da
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: denoland/setup-deno@909cc5acb0fdd60627fb858598759246509fa755 # v2.0.2
- run: deno install
- run: deno task build
- run: deno --allow-env --allow-read --allow-write test/index.js
- run: deno --allow-env --allow-read --import-map=./test/import_map.json test/index.js
lint:
name: Lint
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"build:clean": "rm -f *.{js,d.ts,js.map,d.ts.map} esm/*.{js,js.map,d.ts.map}",
"lint": "prettier --check 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
"format": "prettier --write 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
"test": "node test/index.js",
"test": "node --import ./test/esm-register.js test/index.js",
"test:dos": "node test/slow-dos.test.js",
"test:big": "node test/slow-big.test.js",
"test:coverage": "c8 node test/index.js"
Expand All @@ -42,6 +42,9 @@
"engines": {
"node": "^14.21.3 || >=16"
},
"imports": {
"@noble/hashes/crypto": "../esm/crypto.js"
},
"exports": {
".": {
"import": "./esm/index.js",
Expand Down
6 changes: 6 additions & 0 deletions test/esm-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { pathToFileURL } from 'node:url';
export function resolve(url, context, nextResolve) {
if (url === '@noble/hashes/crypto')
url = pathToFileURL('./esm/crypto.js').toString();
return nextResolve(url, context);
}
3 changes: 3 additions & 0 deletions test/esm-register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { register } from 'node:module';
import { pathToFileURL } from 'node:url';
register('./test/esm-loader.js', pathToFileURL('./'));
5 changes: 5 additions & 0 deletions test/import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"@noble/hashes/crypto": "../src/crypto.ts"
}
}

0 comments on commit 16927da

Please sign in to comment.