-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14ef9c1
commit 5a8a195
Showing
6 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Unit tests (ESM) | ||
on: | ||
push: {} | ||
workflow_call: {} | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: [22.x] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Add local.aikido.io to /etc/hosts | ||
run: | | ||
sudo echo "127.0.0.1 local.aikido.io" | sudo tee -a /etc/hosts | ||
- run: make install | ||
- run: cd library && npm run test:esm | ||
- name: "Upload coverage" | ||
uses: codecov/[email protected] | ||
with: | ||
file: ./library/.tap/report/lcov.info | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
slug: AikidoSec/firewall-node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import t from "tap"; | ||
|
||
import wrapImport from "./wrapImport.js"; | ||
import Package from "./Package.js"; | ||
import BuiltinModule from "./BuiltinModule.js"; | ||
|
||
t.test("it works", async (t) => { | ||
const initialSqlite3 = await import("sqlite3"); | ||
t.same(typeof initialSqlite3.default, "object"); | ||
|
||
const sqlite3Pkg = new Package.Package("sqlite3"); | ||
sqlite3Pkg.withVersion("^5.0.0").onRequire((exports, pkgInfo) => { | ||
t.same(pkgInfo.name, "sqlite3"); | ||
t.same(pkgInfo.type, "external"); | ||
t.ok(pkgInfo.path?.base.endsWith("node_modules/sqlite3")); | ||
t.same(pkgInfo.path?.relative, "lib/sqlite3.js"); | ||
|
||
exports.default = 42; | ||
}); | ||
|
||
const internalFs = new BuiltinModule.BuiltinModule("fs"); | ||
internalFs.onRequire((exports, pkgInfo) => { | ||
t.same(pkgInfo.name, "fs"); | ||
t.same(pkgInfo.type, "builtin"); | ||
t.same(pkgInfo.path, undefined); | ||
|
||
exports.readFile = () => "hello from aikido"; | ||
}); | ||
|
||
wrapImport.wrapImport([sqlite3Pkg], [internalFs]); | ||
|
||
// Should not change anything | ||
wrapImport.wrapImport(); | ||
|
||
const sqlite3 = await import("sqlite3"); | ||
t.same(sqlite3.default, 42); | ||
|
||
const fs = await import("fs"); | ||
t.same(fs.readFile(), "hello from aikido"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"lib": ["ESNext", "DOM"], | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"declaration": true, | ||
"strict": true, | ||
"allowJs": false, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true | ||
}, | ||
"include": ["**/*.test.mjs"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters