Skip to content

Commit 4444c50

Browse files
committed
test: add handlePackage tests
1 parent 612c8ac commit 4444c50

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

codebook.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ words = [
1414
"jsdom",
1515
"pathe",
1616
"pino",
17+
"preact",
1718
"prerender",
1819
"rollup",
1920
"runed",
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { expect, test } from "vitest";
2+
import { handlePackage } from "./handle-package";
3+
4+
test("invalid slug", async () => {
5+
const res = await handlePackage(".");
6+
expect(res).toMatchInlineSnapshot(`
7+
{
8+
"status": "bad-request",
9+
}
10+
`);
11+
});
12+
13+
test("package not found", async () => {
14+
const res = await handlePackage("@jsdocs-io/not-found");
15+
expect(res).toMatchInlineSnapshot(`
16+
{
17+
"status": "not-found",
18+
}
19+
`);
20+
});
21+
22+
test("package version not found", async () => {
23+
const res = await handlePackage("@jsdocs-io/extractor@9999");
24+
expect(res).toMatchInlineSnapshot(`
25+
{
26+
"status": "not-found",
27+
}
28+
`);
29+
});
30+
31+
test("redirect to fixed package version", async () => {
32+
const res = await handlePackage("@jsdoc-io/test-pkg-no-repository");
33+
expect(res).toMatchInlineSnapshot(`
34+
{
35+
"path": "/package/@jsdoc-io/[email protected]",
36+
"status": "found",
37+
}
38+
`);
39+
});
40+
41+
test("invalid license", async () => {
42+
const res = await handlePackage("[email protected]");
43+
expect(res).toMatchObject({
44+
status: "pkg-has-invalid-license",
45+
pkgInfo: {
46+
47+
},
48+
});
49+
});
50+
51+
test("deprecated dt package", async () => {
52+
const res = await handlePackage("@types/[email protected]");
53+
expect(res).toMatchObject({
54+
status: "pkg-is-deprecated-dt-pkg",
55+
pkgInfo: {
56+
pkgId: "@types/[email protected]",
57+
},
58+
});
59+
});
60+
61+
test("subpath not found", async () => {
62+
const res = await handlePackage("[email protected]/not/found");
63+
expect(res).toMatchObject({
64+
status: "pkg-has-no-types",
65+
pkgInfo: {
66+
pkgId: "[email protected]/not/found",
67+
},
68+
});
69+
});
70+
71+
test("definitely typed", async () => {
72+
const res = await handlePackage("[email protected]");
73+
expect(res).toMatchObject({
74+
status: "pkg-has-dt-pkg",
75+
pkgInfo: {
76+
77+
},
78+
});
79+
});
80+
81+
test("with api", async () => {
82+
const res = await handlePackage("[email protected]");
83+
expect(res).toMatchObject({
84+
status: "pkg-has-api",
85+
pkgInfo: {
86+
87+
},
88+
});
89+
});

0 commit comments

Comments
 (0)