-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathj2t.test.ts
101 lines (91 loc) · 2.34 KB
/
j2t.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import fs from "fs";
import _ from "lodash";
import path from "path";
import JSONToType from "../src/index";
const inputPath = __dirname
const outputPath = path.join(__dirname, "typings")
const data = {
"index": [
{
"demo1": {
"id": 1,
"name": "qinchen",
"list": [
{
"id": 1,
"color": "red"
}
]
}
}
],
"demo": [
{
"demo2": {
"id": 1,
"name": "qinchen",
"list": [
{
"id": 1,
"color": "red"
}
]
}
}
]
}
test('Test generate', () => {
new JSONToType().schedule(data).output(outputPath).run()
for (const dataKey in data) {
const fileName = `${ _.kebabCase(dataKey) }.d.ts`
const exists = fs.existsSync(path.join(outputPath, fileName));
expect(exists).toBe(true);
fs.rmdir(path.join(outputPath, fileName), { recursive: true }, (err) => {
if (err) {
console.log(err)
}
});
}
});
test('Test schedule not found', () => {
expect(() => {
new JSONToType()
.output(outputPath)
.run()
}).toThrowError(Error);
});
test('Test input illegal schedule ', () => {
expect(() => {
new JSONToType()
.schedule({})
.output(outputPath)
.run()
}).toThrowError(Error);
expect(() => {
new JSONToType()
// @ts-ignore
.schedule({ a: "" })
.output(outputPath)
.run()
}).toThrowError(Error);
expect(() => {
new JSONToType()
// @ts-ignore
.schedule(null)
.path(inputPath)
.output(outputPath)
.run()
}).toThrowError(Error);
});
test('Test rename schedule file ', () => {
new JSONToType()
.rename("test.json")
.path(inputPath)
.output(outputPath)
.run()
for (const dataKey in data) {
const fileName = `${ _.kebabCase(dataKey) }.d.ts`
const exists = fs.existsSync(path.join(outputPath, fileName));
expect(exists).toBe(true);
}
});