Skip to content

Commit 49f7e0e

Browse files
committed
feat: update tap to 18
BREAKING CHANGE: This update is not backwards compatible with previous versions of testing. This also adds some tests to the skeleton itself showcases how to use mocking with built in plugins, and spies via the added sinon plugin. A .taprc file has also been added as an example of adding some tap configuration.
1 parent 72683ca commit 49f7e0e

File tree

8 files changed

+109
-19
lines changed

8 files changed

+109
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
!/.gitignore
1111
!/.npmrc
1212
!/.prettierrc.json
13+
!/.taprc
1314
!/Dockerfile
1415
!/bin/
1516
!/CHANGELOG*

.taprc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# vim: set filetype=yaml :
2+
disable-coverage: false
3+
allow-incomplete-coverage: false
4+
plugin:
5+
- "@tapjs/sinon"
6+
- "!@tapjs/intercept"

lib/content/gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
!/.gitignore
1111
!/.npmrc
1212
!/.prettierrc.json
13+
!/.taprc
1314
!/Dockerfile
1415
!/bin/
1516
!/CHANGELOG*

lib/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,20 @@ export default async function (root: string, variables: Variables) {
6767
}
6868
),
6969
},
70-
tap: {
71-
coverage: true,
72-
ts: true,
73-
},
7470
types: "lib/index.d.ts",
7571
devDependencies: {
7672
"@tsconfig/node18": "^18.0.0",
7773
"@types/node": "^18.0.0",
78-
"@types/tap": "^15.0.0",
7974
"@typescript-eslint/eslint-plugin": "^6.0.0",
8075
"@typescript-eslint/parser": "^6.0.0",
8176
"eslint": "^8.0.0",
82-
"tap": "^16.0.0",
77+
"tap": "^18.7.0",
8378
"ts-node": "^10.0.0",
8479
"typescript": "^5.0.0"
8580
},
81+
removeDependencies: [
82+
"@types/tap"
83+
]
8684
}),
8785
"tsconfig.json": json({
8886
set: {

package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
"mustache": "^4.2.0"
2323
},
2424
"devDependencies": {
25+
"@tapjs/sinon": "^1.1.18",
2526
"@tsconfig/node18": "^18.0.0",
2627
"@types/mustache": "^4.0.0",
2728
"@types/node": "^18.0.0",
28-
"@types/tap": "^15.0.0",
29+
"@types/sinon": "^17.0.3",
2930
"@typescript-eslint/eslint-plugin": "^6.0.0",
3031
"@typescript-eslint/parser": "^6.0.0",
3132
"eslint": "^8.0.0",
32-
"tap": "^16.0.0",
33+
"tap": "^18.7.0",
3334
"ts-node": "^10.0.0",
3435
"typescript": "5.2.2"
3536
},
@@ -54,9 +55,5 @@
5455
"lib/**/*.d.ts",
5556
"!lib/types/**",
5657
"lib/content/**"
57-
],
58-
"tap": {
59-
"coverage": true,
60-
"ts": true
61-
}
58+
]
6259
}

test/index.test.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/mustache.test.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import t from "tap";
2+
import { mustache } from "../lib/mustache.ts";
3+
4+
void t.test("mustache", async (t) => {
5+
await t.test("must include a path", (t) => {
6+
// @ts-expect-error bad data on purpose
7+
t.throws(() => mustache({}));
8+
t.end();
9+
});
10+
11+
await t.test("should generate", async (t) => {
12+
const { mustache } = t.mockRequire<typeof import("../lib/mustache.ts")>("../lib/mustache.ts", {
13+
"node:fs/promises": {
14+
readFile: (path: string) => {
15+
t.equal(path, "path/to/file.txt");
16+
return Promise.resolve("<% title %>");
17+
}
18+
}
19+
});
20+
const variables = {
21+
title: "it generates"
22+
};
23+
24+
const generator = mustache({
25+
path: "path/to/file.txt",
26+
variables,
27+
});
28+
29+
const output = await generator.generate();
30+
t.equal(output, "it generates");
31+
});
32+
33+
await t.test("should validate partials", async (t) => {
34+
const { mustache } = t.mockRequire<typeof import("../lib/mustache.ts")>("../lib/mustache.ts", {
35+
"node:fs/promises": {
36+
readFile: () => Promise.resolve("<% title %>")
37+
}
38+
});
39+
const variables = {
40+
title: "it generates"
41+
};
42+
43+
const generator = mustache({
44+
path: "path/to/file.txt",
45+
variables,
46+
});
47+
48+
const generateSpy = t.sinon.spy(generator, "generate");
49+
const reportSpy = t.sinon.spy(generator, "report");
50+
51+
await generator.validate({
52+
path: "path/to/file.txt",
53+
found: "it generates\nand handles extras"
54+
});
55+
56+
t.equal(generateSpy.callCount, 1);
57+
// Report not called because we passed
58+
t.equal(reportSpy.callCount, 0);
59+
});
60+
61+
await t.test("should fail validation when base template not found", async (t) => {
62+
const { mustache } = t.mockRequire<typeof import("../lib/mustache.ts")>("../lib/mustache.ts", {
63+
"node:fs/promises": {
64+
readFile: () => Promise.resolve("<% title %>")
65+
}
66+
});
67+
const variables = {
68+
title: "it generates"
69+
};
70+
71+
const generator = mustache({
72+
path: "path/to/file.txt",
73+
variables,
74+
});
75+
76+
const generateSpy = t.sinon.spy(generator, "generate");
77+
const reportSpy = t.sinon.spy(generator, "report");
78+
79+
await generator.validate({
80+
path: "path/to/file.txt",
81+
found: "a new file"
82+
});
83+
84+
t.equal(generateSpy.callCount, 1);
85+
t.ok(reportSpy.calledOnceWithExactly({
86+
expected: "it generates",
87+
found: "a new file",
88+
message: "path/to/file.txt does not include the original template"
89+
}));
90+
});
91+
});

tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
".eslintrc.js"
66
],
77
"compilerOptions": {
8+
"allowImportingTsExtensions": true,
9+
"noEmit": true,
810
"typeRoots": [
911
"./node_modules/@types",
1012
"./lib/types"

0 commit comments

Comments
 (0)