Skip to content

Commit

Permalink
chore: mock dns
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreDemailly committed Oct 29, 2023
1 parent a1e6edc commit 6d23514
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/morphix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
node-version: [18.x, 20.x]
fail-fast: false
steps:
- name: Harden Runner
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
with:
egress-policy: audit
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
Expand Down
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/morphix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
"prepublishOnly": "npm run build",
"test": "glob -c \"tsx --test\" \"./test/**/*.spec.ts\"",
"test": "npm run build && glob -c \"tsx --test --loader=esmock\" \"./test/**/*.spec.mts\"",
"coverage": "c8 -r html npm test",
"lint": "cross-env eslint src/**/*.ts"
},
Expand All @@ -36,5 +36,8 @@
],
"keywords": [],
"author": "GENTILHOMME Thomas <[email protected]>",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"esmock": "^2.5.8"
}
}
23 changes: 21 additions & 2 deletions src/morphix/test/index.spec.ts → src/morphix/test/index.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import assert from "node:assert";
import { describe, it } from "node:test";

// Import Third-party Dependencies
import esmock from "esmock";

// Import Internal Dependencies
import { morphix } from "../src/index";
import { morphix } from "../dist/index.mjs";

describe("Morphix", () => {
it("main", async() => {
Expand Down Expand Up @@ -79,6 +82,22 @@ describe("Morphix", () => {
});

it("should find ip hostname", async() => {
assert.equal(await morphix("{foo | dnsresolve}", { foo: "8.8.8.8" }), "dns.google");
const { morphix } = await esmock("../dist/index.mjs", {
"node:dns/promises": {
reverse: async() => ["dns.google"]
}
});
assert.equal(await morphix("host: {foo | dnsresolve}", { foo: "8.8.8.8" }), "host: dns.google");
});

it("should not find ip hostname", async() => {
const { morphix } = await esmock("../dist/index.mjs", {
"node:dns/promises": {
reverse: async() => {
throw new Error("Not found");
}
}
});
assert.equal(await morphix("host: {foo | dnsresolve}", { foo: "8.8.8.8" }), "host: 8.8.8.8");
});
});

0 comments on commit 6d23514

Please sign in to comment.