Skip to content

Commit ed62e17

Browse files
committed
chore: tests
1 parent cbfc964 commit ed62e17

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

tests/index.test-d.ts renamed to test-d/index.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expectType } from "tsd";
22

3-
// todo change to ../build
4-
import { modifyJsonFile, modifyPackageJsonFile } from "../src/";
3+
// todo-high https://nodejs.org/api/packages.html#packages_package_entry_points
4+
import { modifyJsonFile, modifyPackageJsonFile } from "../build";
55

66
modifyJsonFile("path.json", {
77
value: 5,

tests/index.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import { modifyJsonFile, modifyPackageJsonFile } from "../build/";
99

1010
const jsonFilePath = path.join(__dirname, "testing-file.json");
1111

12-
// that's fine until tests are running with --serial flag
13-
let dataToWrite;
14-
15-
test.beforeEach(async () => {
12+
const prepare = async (dataToWrite?) => {
1613
await jsonfile.writeFile(jsonFilePath, dataToWrite ?? {
1714
"name": "package",
1815
"main": "index.js",
@@ -22,13 +19,14 @@ test.beforeEach(async () => {
2219
"fdir": ">=2"
2320
}
2421
}, { spaces: 4 });
25-
});
22+
};
2623

2724
test.afterEach.always(async () => {
2825
await del(jsonFilePath);
2926
});
3027

3128
test("modifies JSON file", async t => {
29+
await prepare();
3230
await modifyJsonFile(jsonFilePath, {
3331
name: s => `super ${s}`,
3432
main: "build/electron.js",
@@ -41,6 +39,7 @@ test("modifies JSON file", async t => {
4139
});
4240

4341
test("modifies package.json file with async function", async t => {
42+
await prepare();
4443
await modifyPackageJsonFile(jsonFilePath, async ({ main }) => {
4544
return { types: main, name: "ahaha" };
4645
});
@@ -49,8 +48,8 @@ test("modifies package.json file with async function", async t => {
4948
});
5049

5150
test("modifies package.json file which has numeric type", async t => {
52-
dataToWrite = 50;
53-
await modifyPackageJsonFile(jsonFilePath, n => n + 5);
51+
await prepare(50);
52+
await modifyJsonFile<number>(jsonFilePath, n => n + 5);
5453
const modifiedJsonFle = await fs.readFile(jsonFilePath, "utf8");
5554
t.snapshot(modifiedJsonFle);
5655
});

tests/snapshots/index.test.ts.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ Generated by [AVA](https://avajs.dev).
2525
"types": "index.js",␊
2626
"name": "ahaha"␊
2727
}`
28+
29+
## modifies package.json file which has numeric type
30+
31+
> Snapshot 1
32+
33+
'55'

tests/snapshots/index.test.ts.snap

26 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)