-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patchers.test.ts
108 lines (80 loc) · 3.88 KB
/
patchers.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
102
103
104
105
106
107
108
import * as fs from "fs";
import { patchFile, VersionType } from "./patchers";
type NoParamsCallback = () => void;
async function match(from: string, to: string, ready: string, callback: NoParamsCallback) {
if (fs.existsSync(to))
{
fs.unlinkSync(to);
}
fs.copyFileSync(from, to);
await callback();
const patched = fs.readFileSync(to, "utf-8");
const sample = fs.readFileSync(ready, "utf-8");
//fs.unlinkSync(to);
expect(patched).toEqual(sample);
}
describe("patchers", () => {
test("Patch csproj", async () => {
const from = "files/csproj/TestProject.csproj";
const to = "files/csproj/TestProject.Edit.csproj";
const ready = "files/csproj/TestProject.Ready.csproj";
await match(from, to, ready, async () => await patchFile(to, "2.3.4", VersionType.CSProject));
});
test("Invalid csproj", async () => {
await expect(async () => await patchFile("invalid.csproj", "1.0", VersionType.CSProject)).rejects.toThrow();
});
test("Patch npm package.json", async () => {
const from = "files/npm/package.json";
const to = "files/npm/package.edit.json";
const ready = "files/npm/package.ready.json";
await match(from, to, ready, async () => await patchFile(to, "2.3.4", VersionType.NPM));
});
test("Invalid npm package.json", async () => {
await expect(async () => await patchFile("invalid.json", "1.0", VersionType.NPM)).rejects.toThrow();
});
test("Patch setup.py", async () => {
const from = "files/setuppy/setup.py";
const to = "files/setuppy/setup.edit.py";
const ready = "files/setuppy/setup.ready.py";
await match(from, to, ready, async () => await patchFile(to, "2.3.4", VersionType.SetupPython));
});
test("Invalid setup.py", async () => {
await expect(async () => await patchFile("invalid.py", "1.0", VersionType.SetupPython)).rejects.toThrow();
});
test("Patch __init__.py", async () => {
const from = "files/initpy/__init__.py";
const to = "files/initpy/__init__.edit.py";
const ready = "files/initpy/__init__.ready.py";
await match(from, to, ready, async () => await patchFile(to, "2.3.4", VersionType.InitPython));
});
test("Invalid __init__.py", async () => {
await expect(async () => await patchFile("invalid.py", "1.0", VersionType.InitPython)).rejects.toThrow();
});
test("Patch fxmanifest.lua", async () => {
const from = "files/fxmanifest/fxmanifest.lua";
const to = "files/fxmanifest/fxmanifest.edit.lua";
const ready = "files/fxmanifest/fxmanifest.ready.lua";
await match(from, to, ready, async () => await patchFile(to, "2.3.4", VersionType.CFXManifest));
});
test("Invalid fxmanifest.lua", async () => {
await expect(async () => await patchFile("invalid.lua", "1.0", VersionType.CFXManifest)).rejects.toThrow();
});
test("Patch .gemspec", async () => {
const from = "files/gemspec/octi.gemspec";
const to = "files/gemspec/octi.edit.gemspec";
const ready = "files/gemspec/octi.ready.gemspec";
await match(from, to, ready, async () => await patchFile(to, "2.3.4", VersionType.Gemspec));
});
test("Invalid .gemspec", async () => {
await expect(async () => await patchFile("invalid.gemspec", "1.0", VersionType.Gemspec)).rejects.toThrow();
});
test("Patch pyproject.toml", async () => {
const from = "files/pyproject/pyproject.toml";
const to = "files/pyproject/pyproject.edit.toml";
const ready = "files/pyproject/pyproject.ready.toml";
await match(from, to, ready, async () => await patchFile(to, "2.3.4", VersionType.PyProject));
});
test("Invalid pyproject.toml", async () => {
await expect(async () => await patchFile("invalid.toml", "1.0", VersionType.PyProject)).rejects.toThrow();
});
});