Skip to content

Commit 27ed51e

Browse files
committed
chore: present tests
1 parent 642f56f commit 27ed51e

File tree

6 files changed

+1893
-7
lines changed

6 files changed

+1893
-7
lines changed

package.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,35 @@
1919
"author": "Vitaly <vital2580@icloud.com>",
2020
"license": "MIT",
2121
"files": [
22-
"build"
22+
"build"
2323
],
2424
"scripts": {
25-
"prepublishOnly": "tsc",
26-
"test": "echo they're definitely needed"
25+
"prepublishOnly": "yarn test && tsc",
26+
"test": "ava --serial"
2727
},
2828
"devDependencies": {
29+
"@ava/typescript": "^1.1.1",
30+
"@types/jsonfile": "^6.0.0",
2931
"@types/node": "^15.12.2",
3032
"@zardoy/tsconfig": "^1.0.2",
33+
"ava": "^3.15.0",
34+
"del": "^6.0.0",
35+
"jsonfile": "^6.1.0",
3136
"ts-node": "^10.0.0",
3237
"typescript": "^4.3.2"
3338
},
3439
"dependencies": {
3540
"detect-indent": "^6.1.0",
3641
"load-json-file": "^6.2.0",
42+
"nanoid": "^3.1.23",
3743
"type-fest": "^1.2.0"
44+
},
45+
"ava": {
46+
"extensions": [
47+
"ts"
48+
],
49+
"require": [
50+
"ts-node/register"
51+
]
3852
}
3953
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ We're using [detect-indent](https://www.npmjs.com/package/detect-indent) to pres
5757
## TODO
5858

5959
- [ ] Fix. Currently, to preserve the tab size, json file readed twice
60-
- [ ] tests. should be easy but I'm extremely lazy
60+
- [ ] Fix double tsc compilation (and test actual build/)
6161
- [ ] transformer for paths (most likely babel plugin):
6262

6363
```ts

tests/index.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import test from "ava";
2+
3+
import jsonfile from "jsonfile";
4+
import path from "path";
5+
import del from "del";
6+
import nanoid from "nanoid";
7+
import { modifyJsonFile } from "../src/index"
8+
import fs from "fs/promises";
9+
10+
const jsonFilePath = path.join(__dirname, "testing-file.json");
11+
12+
test.beforeEach(async () => {
13+
await jsonfile.writeFile(jsonFilePath, {
14+
"name": "package",
15+
"main": "index.js",
16+
"author": "eldar",
17+
"dependencies": {
18+
"type-fest": "*",
19+
"fdir": ">=2"
20+
}
21+
}, { spaces: 4 });
22+
})
23+
24+
test.afterEach.always(async () => {
25+
await del(jsonFilePath);
26+
})
27+
28+
test("modifies JSON file", async t => {
29+
await modifyJsonFile(jsonFilePath, {
30+
name: s => `super ${s}`,
31+
main: "build/electron.js",
32+
dependencies: {
33+
"type-fest": "^1.0.0"
34+
}
35+
})
36+
const modifiedJsonFle = await fs.readFile(jsonFilePath, "utf8");
37+
t.snapshot(modifiedJsonFle);
38+
})

tests/snapshots/index.test.ts.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Snapshot report for `tests/index.test.ts`
2+
3+
The actual snapshot is saved in `index.test.ts.snap`.
4+
5+
Generated by [AVA](https://avajs.dev).
6+
7+
## modifies JSON file
8+
9+
> Snapshot 1
10+
11+
`{␊
12+
"name": "super package",␊
13+
"main": "build/electron.js",␊
14+
"author": "eldar",␊
15+
"dependencies": {␊
16+
"type-fest": "^1.0.0"␊
17+
}␊
18+
}`

tests/snapshots/index.test.ts.snap

206 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)