Skip to content

Commit

Permalink
test: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Mar 8, 2024
1 parent a8764e8 commit cf429d4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Unit tests

on:
push:

jobs:
unit-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: "20.x"

- name: Keep npm cache around to speed up installs
uses: actions/cache@v4
with:
path: ~/.npm
key: build-${{ hashFiles('**/package-lock.json') }}

- name: Install dependencies
run: npm ci --no-audit

- name: Run tests
run: npm test
12 changes: 8 additions & 4 deletions ip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import { it, describe } from "node:test";
import assert from "node:assert/strict";

void describe("ip()", async (t) => {
void it(`should resolve an IPv4 address`, async () =>
assert.deepEqual(await ipv4("localhost"), ["127.0.0.1"]));
void it(`should resolve an IPv6 address`, async () =>
assert.deepEqual(await ipv6("localhost"), ["::1"]));
void it(`should resolve an IPv4 address`, async () => {
const ips = await ipv4("one.one.one.one");
assert.equal(ips.includes("1.1.1.1"), true);
});
void it(`should resolve an IPv6 address`, async () => {
const ips = await ipv6("one.one.one.one");
assert.equal(ips.includes("2606:4700:4700::1111"), true);
});
});

0 comments on commit cf429d4

Please sign in to comment.