Skip to content

Commit f7aabec

Browse files
test: add tests for public interface (#4587)
This adds tests for what’s exposed from packages. They make it visible when something is accidentally leaked. Especially because of current `export *` use. From #4538 (comment) In a future PR I’d like to add export maps everywhere. That prevents leaking entire files. Then these test cases can be updated to check the paths that are exposed too.
1 parent 80ef9eb commit f7aabec

File tree

28 files changed

+325
-7
lines changed

28 files changed

+325
-7
lines changed

analyze-wasm/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
"build": "npm run build:jco && npm run build:rollup",
5555
"lint": "eslint .",
5656
"prepublishOnly": "npm run build",
57-
"test": "npm run build && npm run lint"
57+
"test-api": "node --test",
58+
"test-coverage": "node --experimental-test-coverage --test",
59+
"test": "npm run build && npm run lint && npm run test-coverage"
5860
},
5961
"dependencies": {},
6062
"devDependencies": {

analyze-wasm/test/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
test("@arcjet/analyze-wasm", async function (t) {
5+
await t.test("should expose the public api", async function () {
6+
assert.deepEqual(Object.keys(await import("../index.js")).sort(), [
7+
"initializeWasm",
8+
]);
9+
});
10+
});

analyze/test/analyze.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ const exampleEmailOptions = {
1414
requireTopLevelDomain: true,
1515
};
1616

17+
test("@arcjet/analyze", async function (t) {
18+
await t.test("should expose the public api", async function () {
19+
assert.deepEqual(Object.keys(await import("../index.js")).sort(), [
20+
"detectBot",
21+
"detectSensitiveInfo",
22+
"generateFingerprint",
23+
"isValidEmail",
24+
]);
25+
});
26+
});
27+
1728
test("detectBot", async function (t) {
1829
await t.test("should fail w/o user agent", async function () {
1930
await assert.rejects(

arcjet/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"build": "rollup --config rollup.config.js",
4343
"lint": "eslint .",
4444
"prepublishOnly": "npm run build",
45-
"pretest": "npm run build",
4645
"test-api": "node --test",
4746
"test-coverage": "node --experimental-test-coverage --test",
4847
"test": "npm run build && npm run lint && npm run test-coverage"

arcjet/test/index.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
test("arcjet", async function (t) {
5+
await t.test("should expose the public api", async function () {
6+
assert.deepEqual(Object.keys(await import("../index.js")).sort(), [
7+
"ArcjetAllowDecision",
8+
"ArcjetBotReason",
9+
"ArcjetChallengeDecision",
10+
"ArcjetConclusion",
11+
"ArcjetDecision",
12+
"ArcjetDenyDecision",
13+
"ArcjetEdgeRuleReason",
14+
"ArcjetEmailReason",
15+
"ArcjetEmailType",
16+
"ArcjetErrorDecision",
17+
"ArcjetErrorReason",
18+
"ArcjetIpDetails",
19+
"ArcjetMode",
20+
"ArcjetRateLimitAlgorithm",
21+
"ArcjetRateLimitReason",
22+
"ArcjetReason",
23+
"ArcjetRuleResult",
24+
"ArcjetRuleState",
25+
"ArcjetSensitiveInfoReason",
26+
"ArcjetSensitiveInfoType",
27+
"ArcjetShieldReason",
28+
"ArcjetStack",
29+
"botCategories",
30+
"default",
31+
"detectBot",
32+
"fixedWindow",
33+
"protectSignup",
34+
"sensitiveInfo",
35+
"shield",
36+
"slidingWindow",
37+
"tokenBucket",
38+
"validateEmail",
39+
]);
40+
});
41+
});

body/test/body.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import * as http from "http";
44
import { readBody } from "../index.js";
55
import type { AddressInfo } from "net";
66

7+
test("@arcjet/body", async function (t) {
8+
await t.test("should expose the public api", async function () {
9+
assert.deepEqual(Object.keys(await import("../index.js")).sort(), [
10+
"readBody",
11+
]);
12+
});
13+
});
14+
715
describe("reads the body from the readable stream", () => {
816
test("should read normal body streams", (t, done) => {
917
const server = http.createServer(async (req, res) => {

cache/test/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import assert from "node:assert/strict";
2+
import { test } from "node:test";
3+
4+
test("@arcjet/cache", async function (t) {
5+
await t.test("should expose the public api", async function () {
6+
assert.deepEqual(Object.keys(await import("../index.js")).sort(), [
7+
"MemoryCache",
8+
]);
9+
});
10+
});

decorate/test/decorate.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ import { OutgoingMessage } from "http";
1111

1212
function noop() {}
1313

14+
test("@arcjet/decorate", async function (t) {
15+
await t.test("should expose the public api", async function () {
16+
assert.deepEqual(Object.keys(await import("../index.js")).sort(), [
17+
"setRateLimitHeaders",
18+
]);
19+
});
20+
});
21+
1422
describe("setRateLimitHeaders", () => {
1523
describe("Header object", () => {
1624
test("empty results do not set headers", () => {

duration/test/index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import assert from "node:assert/strict";
22
import { describe, test } from "node:test";
33
import { parse } from "../index.js";
44

5+
test("@arcjet/duration", async function (t) {
6+
await t.test("should expose the public api", async function () {
7+
assert.deepEqual(Object.keys(await import("../index.js")).sort(), [
8+
"parse",
9+
]);
10+
});
11+
});
12+
513
describe("parse", () => {
614
test("always returns 0 if the duration string is just 0", () => {
715
assert.equal(parse("0"), 0);

env/test/env.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ import assert from "node:assert/strict";
22
import { describe, test } from "node:test";
33
import * as env from "../index.ts";
44

5+
test("@arcjet/env", async function (t) {
6+
await t.test("should expose the public api", async function () {
7+
assert.deepEqual(Object.keys(await import("../index.js")).sort(), [
8+
"apiKey",
9+
"baseUrl",
10+
"isDevelopment",
11+
"logLevel",
12+
"platform",
13+
]);
14+
});
15+
});
16+
517
describe("env", () => {
618
test("platform", () => {
719
assert.equal(env.platform({}), undefined);

0 commit comments

Comments
 (0)