@monorepolint/rules 0.5.0-alpha.13 → 0.5.0-alpha.130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-clean.log +4 -0
- package/.turbo/turbo-compile-typescript.log +4 -0
- package/.turbo/turbo-lint.log +14 -0
- package/.turbo/turbo-test.log +666 -0
- package/.turbo/turbo-transpile-typescript.log +18 -0
- package/build/js/chunk-A2MUUSNE.js +26 -0
- package/build/js/chunk-A2MUUSNE.js.map +1 -0
- package/build/js/index.js +1402 -0
- package/build/js/index.js.map +1 -0
- package/build/js/public/util.js +7 -0
- package/build/js/public/util.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/build/types/__tests__/alphabeticalScripts.spec.d.ts.map +1 -0
- package/build/types/__tests__/bannedDependencies.spec.d.ts +2 -0
- package/build/types/__tests__/bannedDependencies.spec.d.ts.map +1 -0
- package/build/types/__tests__/consistentDependencies.spec.d.ts.map +1 -0
- package/build/types/__tests__/consistentVersions.spec.d.ts +8 -0
- package/build/types/__tests__/consistentVersions.spec.d.ts.map +1 -0
- package/build/types/__tests__/fileContents.spec.d.ts.map +1 -0
- package/build/types/__tests__/mustSatisfyPeerDependencies.spec.d.ts +8 -0
- package/build/types/__tests__/mustSatisfyPeerDependencies.spec.d.ts.map +1 -0
- package/build/types/__tests__/nestedWorkspaces.spec.d.ts +2 -0
- package/build/types/__tests__/nestedWorkspaces.spec.d.ts.map +1 -0
- package/build/types/__tests__/packageEntry.spec.d.ts.map +1 -0
- package/build/types/__tests__/packageOrder.spec.d.ts.map +1 -0
- package/build/types/__tests__/packageScript.spec.d.ts.map +1 -0
- package/build/types/__tests__/requireDependency.spec.d.ts +2 -0
- package/build/types/__tests__/requireDependency.spec.d.ts.map +1 -0
- package/build/types/__tests__/utils.d.ts +81 -0
- package/build/types/__tests__/utils.d.ts.map +1 -0
- package/build/types/alphabeticalDependencies.d.ts +8 -0
- package/build/types/alphabeticalDependencies.d.ts.map +1 -0
- package/build/types/alphabeticalScripts.d.ts +8 -0
- package/build/types/alphabeticalScripts.d.ts.map +1 -0
- package/build/types/bannedDependencies.d.ts +66 -0
- package/build/types/bannedDependencies.d.ts.map +1 -0
- package/build/types/consistentDependencies.d.ts +18 -0
- package/build/types/consistentDependencies.d.ts.map +1 -0
- package/build/types/consistentVersions.d.ts +25 -0
- package/build/types/consistentVersions.d.ts.map +1 -0
- package/build/types/fileContents.d.ts +39 -0
- package/build/types/fileContents.d.ts.map +1 -0
- package/build/types/index.d.ts +20 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/mustSatisfyPeerDependencies.d.ts +427 -0
- package/build/types/mustSatisfyPeerDependencies.d.ts.map +1 -0
- package/build/types/nestedWorkspaces.d.ts +10 -0
- package/build/types/nestedWorkspaces.d.ts.map +1 -0
- package/build/types/packageEntry.d.ts +62 -0
- package/build/types/packageEntry.d.ts.map +1 -0
- package/build/types/packageOrder.d.ts +12 -0
- package/build/types/packageOrder.d.ts.map +1 -0
- package/build/types/packageScript.d.ts +47 -0
- package/build/types/packageScript.d.ts.map +1 -0
- package/build/types/public/util.d.ts +2 -0
- package/build/types/public/util.d.ts.map +1 -0
- package/build/types/requireDependency.d.ts +50 -0
- package/build/types/requireDependency.d.ts.map +1 -0
- package/build/types/standardTsconfig.d.ts +29 -0
- package/build/types/standardTsconfig.d.ts.map +1 -0
- package/{lib → build/types}/util/checkAlpha.d.ts +2 -1
- package/build/types/util/checkAlpha.d.ts.map +1 -0
- package/build/types/util/makeDirectory.d.ts.map +1 -0
- package/build/types/util/makeRule.d.ts +12 -0
- package/build/types/util/makeRule.d.ts.map +1 -0
- package/build/types/util/packageDependencyGraphService.d.ts +37 -0
- package/build/types/util/packageDependencyGraphService.d.ts.map +1 -0
- package/package.json +45 -20
- package/src/__tests__/alphabeticalScripts.spec.ts +33 -31
- package/src/__tests__/bannedDependencies.spec.ts +189 -0
- package/src/__tests__/consistentDependencies.spec.ts +40 -15
- package/src/__tests__/consistentVersions.spec.ts +224 -0
- package/src/__tests__/fileContents.spec.ts +69 -50
- package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +1189 -0
- package/src/__tests__/nestedWorkspaces.spec.ts +153 -0
- package/src/__tests__/packageEntry.spec.ts +127 -49
- package/src/__tests__/packageOrder.spec.ts +68 -53
- package/src/__tests__/packageScript.spec.ts +124 -98
- package/src/__tests__/requireDependency.spec.ts +152 -0
- package/src/__tests__/utils.ts +111 -19
- package/src/alphabeticalDependencies.ts +7 -9
- package/src/alphabeticalScripts.ts +7 -9
- package/src/bannedDependencies.ts +135 -46
- package/src/consistentDependencies.ts +41 -17
- package/src/consistentVersions.ts +141 -0
- package/src/fileContents.ts +45 -40
- package/src/index.ts +13 -9
- package/src/mustSatisfyPeerDependencies.ts +744 -0
- package/src/nestedWorkspaces.ts +60 -0
- package/src/packageEntry.ts +72 -28
- package/src/packageOrder.ts +17 -13
- package/src/packageScript.ts +15 -19
- package/src/public/util.ts +1 -0
- package/src/requireDependency.ts +71 -0
- package/src/standardTsconfig.ts +51 -27
- package/src/util/checkAlpha.ts +9 -6
- package/src/util/makeRule.ts +29 -0
- package/src/util/packageDependencyGraphService.ts +114 -0
- package/tsconfig.json +10 -2
- package/lib/__tests__/alphabeticalScripts.spec.d.ts.map +0 -1
- package/lib/__tests__/alphabeticalScripts.spec.js +0 -61
- package/lib/__tests__/alphabeticalScripts.spec.js.map +0 -1
- package/lib/__tests__/consistentDependencies.spec.d.ts.map +0 -1
- package/lib/__tests__/consistentDependencies.spec.js +0 -99
- package/lib/__tests__/consistentDependencies.spec.js.map +0 -1
- package/lib/__tests__/fileContents.spec.d.ts.map +0 -1
- package/lib/__tests__/fileContents.spec.js +0 -66
- package/lib/__tests__/fileContents.spec.js.map +0 -1
- package/lib/__tests__/packageEntry.spec.d.ts.map +0 -1
- package/lib/__tests__/packageEntry.spec.js +0 -99
- package/lib/__tests__/packageEntry.spec.js.map +0 -1
- package/lib/__tests__/packageOrder.spec.d.ts.map +0 -1
- package/lib/__tests__/packageOrder.spec.js +0 -115
- package/lib/__tests__/packageOrder.spec.js.map +0 -1
- package/lib/__tests__/packageScript.spec.d.ts.map +0 -1
- package/lib/__tests__/packageScript.spec.js +0 -172
- package/lib/__tests__/packageScript.spec.js.map +0 -1
- package/lib/__tests__/utils.d.ts +0 -9
- package/lib/__tests__/utils.d.ts.map +0 -1
- package/lib/__tests__/utils.js +0 -33
- package/lib/__tests__/utils.js.map +0 -1
- package/lib/alphabeticalDependencies.d.ts +0 -12
- package/lib/alphabeticalDependencies.d.ts.map +0 -1
- package/lib/alphabeticalDependencies.js +0 -21
- package/lib/alphabeticalDependencies.js.map +0 -1
- package/lib/alphabeticalScripts.d.ts +0 -12
- package/lib/alphabeticalScripts.d.ts.map +0 -1
- package/lib/alphabeticalScripts.js +0 -19
- package/lib/alphabeticalScripts.js.map +0 -1
- package/lib/bannedDependencies.d.ts +0 -15
- package/lib/bannedDependencies.d.ts.map +0 -1
- package/lib/bannedDependencies.js +0 -57
- package/lib/bannedDependencies.js.map +0 -1
- package/lib/consistentDependencies.d.ts +0 -10
- package/lib/consistentDependencies.d.ts.map +0 -1
- package/lib/consistentDependencies.js +0 -57
- package/lib/consistentDependencies.js.map +0 -1
- package/lib/fileContents.d.ts +0 -25
- package/lib/fileContents.d.ts.map +0 -1
- package/lib/fileContents.js +0 -80
- package/lib/fileContents.js.map +0 -1
- package/lib/index.d.ts +0 -16
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -27
- package/lib/index.js.map +0 -1
- package/lib/packageEntry.d.ts +0 -16
- package/lib/packageEntry.d.ts.map +0 -1
- package/lib/packageEntry.js +0 -40
- package/lib/packageEntry.js.map +0 -1
- package/lib/packageOrder.d.ts +0 -12
- package/lib/packageOrder.d.ts.map +0 -1
- package/lib/packageOrder.js +0 -103
- package/lib/packageOrder.js.map +0 -1
- package/lib/packageScript.d.ts +0 -25
- package/lib/packageScript.d.ts.map +0 -1
- package/lib/packageScript.js +0 -89
- package/lib/packageScript.js.map +0 -1
- package/lib/standardTsconfig.d.ts +0 -33
- package/lib/standardTsconfig.d.ts.map +0 -1
- package/lib/standardTsconfig.js +0 -98
- package/lib/standardTsconfig.js.map +0 -1
- package/lib/util/checkAlpha.d.ts.map +0 -1
- package/lib/util/checkAlpha.js +0 -47
- package/lib/util/checkAlpha.js.map +0 -1
- package/lib/util/makeDirectory.d.ts.map +0 -1
- package/lib/util/makeDirectory.js +0 -27
- package/lib/util/makeDirectory.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -2510
- /package/{lib → build/types}/__tests__/alphabeticalScripts.spec.d.ts +0 -0
- /package/{lib → build/types}/__tests__/consistentDependencies.spec.d.ts +0 -0
- /package/{lib → build/types}/__tests__/fileContents.spec.d.ts +0 -0
- /package/{lib → build/types}/__tests__/packageEntry.spec.d.ts +0 -0
- /package/{lib → build/types}/__tests__/packageOrder.spec.d.ts +0 -0
- /package/{lib → build/types}/__tests__/packageScript.spec.d.ts +0 -0
- /package/{lib → build/types}/util/makeDirectory.d.ts +0 -0
- /package/{jest.config.js → jest.config.cjs} +0 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright 2020 Palantir Technologies, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { WorkspaceContextImpl } from "@monorepolint/core";
|
|
9
|
+
import { Host, PackageJson, SimpleHost } from "@monorepolint/utils";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import * as tmp from "tmp";
|
|
12
|
+
import { consistentVersions, Options } from "../consistentVersions.js";
|
|
13
|
+
import { makeDirectoryRecursively } from "../util/makeDirectory.js";
|
|
14
|
+
import { describe, expect, it, beforeEach, afterEach, jest } from "@jest/globals";
|
|
15
|
+
|
|
16
|
+
describe("consistentVersions", () => {
|
|
17
|
+
tmp.setGracefulCleanup();
|
|
18
|
+
|
|
19
|
+
let cleanupJobs: Array<() => void> = [];
|
|
20
|
+
let cwd: string | undefined;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
const dir = tmp.dirSync({ unsafeCleanup: true });
|
|
24
|
+
cleanupJobs.push(() => dir.removeCallback());
|
|
25
|
+
cwd = dir.name;
|
|
26
|
+
|
|
27
|
+
const spy = jest.spyOn(process, "cwd");
|
|
28
|
+
spy.mockReturnValue(cwd);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
for (const cleanupJob of cleanupJobs) {
|
|
33
|
+
cleanupJob();
|
|
34
|
+
}
|
|
35
|
+
cleanupJobs = [];
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function makeWorkspace(fix = false) {
|
|
39
|
+
const host: Host = new SimpleHost();
|
|
40
|
+
const workspaceContext = new WorkspaceContextImpl(
|
|
41
|
+
cwd!,
|
|
42
|
+
{
|
|
43
|
+
rules: [],
|
|
44
|
+
fix,
|
|
45
|
+
verbose: false,
|
|
46
|
+
silent: true,
|
|
47
|
+
},
|
|
48
|
+
host
|
|
49
|
+
);
|
|
50
|
+
const addErrorSpy = jest.spyOn(workspaceContext, "addError");
|
|
51
|
+
|
|
52
|
+
function check(options: Options = { matchDependencyVersions: {} }) {
|
|
53
|
+
consistentVersions({ options }).check(workspaceContext);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { addErrorSpy, check, host };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function addPackageJson(host: Host, filePath: string, packageJson: PackageJson) {
|
|
60
|
+
const dirPath = path.resolve(cwd!, path.dirname(filePath));
|
|
61
|
+
const resolvedFilePath = path.resolve(cwd!, filePath);
|
|
62
|
+
|
|
63
|
+
makeDirectoryRecursively(dirPath);
|
|
64
|
+
host.writeJson(resolvedFilePath, packageJson);
|
|
65
|
+
return (): PackageJson => {
|
|
66
|
+
return host.readJson(resolvedFilePath);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
describe("standard tests", () => {
|
|
71
|
+
let testPackageJson: PackageJson;
|
|
72
|
+
|
|
73
|
+
beforeEach(() => {
|
|
74
|
+
testPackageJson = {
|
|
75
|
+
name: "test",
|
|
76
|
+
dependencies: {
|
|
77
|
+
greatLib: "^15",
|
|
78
|
+
both: "1",
|
|
79
|
+
},
|
|
80
|
+
peerDependencies: {
|
|
81
|
+
whatever: "15",
|
|
82
|
+
},
|
|
83
|
+
devDependencies: {
|
|
84
|
+
else: "27.2.1",
|
|
85
|
+
both: "1",
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("Does nothing when arguments are empty", async () => {
|
|
91
|
+
const { addErrorSpy, check, host } = makeWorkspace();
|
|
92
|
+
addPackageJson(host, "./package.json", testPackageJson);
|
|
93
|
+
|
|
94
|
+
check();
|
|
95
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
96
|
+
check({ matchDependencyVersions: {} });
|
|
97
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("Fixes packages that have an incorrect dependency version", async () => {
|
|
101
|
+
const { addErrorSpy, check, host } = makeWorkspace(true);
|
|
102
|
+
const readTestPackageJson = addPackageJson(host, "./package.json", testPackageJson);
|
|
103
|
+
|
|
104
|
+
const requiredGreatLibVersion = "1.2.3";
|
|
105
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
106
|
+
check({
|
|
107
|
+
matchDependencyVersions: { both: testPackageJson.dependencies!.both, greatLib: requiredGreatLibVersion },
|
|
108
|
+
});
|
|
109
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
110
|
+
expect(readTestPackageJson().dependencies!.greatLib).toEqual(requiredGreatLibVersion);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("Ignores packages that have a correct dependency version", async () => {
|
|
114
|
+
const { addErrorSpy, check, host } = makeWorkspace();
|
|
115
|
+
addPackageJson(host, "./package.json", testPackageJson);
|
|
116
|
+
|
|
117
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
118
|
+
check({
|
|
119
|
+
matchDependencyVersions: {
|
|
120
|
+
both: testPackageJson.dependencies!.both,
|
|
121
|
+
greatLib: testPackageJson.dependencies!.greatLib,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("Fixes packages that have an incorrect devDependency version", async () => {
|
|
128
|
+
const { addErrorSpy, check, host } = makeWorkspace(true);
|
|
129
|
+
const readTestPackageJson = addPackageJson(host, "./package.json", testPackageJson);
|
|
130
|
+
|
|
131
|
+
const requiredElseLibVersion = "1.2.3";
|
|
132
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
133
|
+
check({ matchDependencyVersions: { both: testPackageJson.dependencies!.both, else: requiredElseLibVersion } });
|
|
134
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
135
|
+
expect(readTestPackageJson().devDependencies!.else).toEqual(requiredElseLibVersion);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("Ignores packages that have a correct devDependency version", async () => {
|
|
139
|
+
const { addErrorSpy, check, host } = makeWorkspace();
|
|
140
|
+
addPackageJson(host, "./package.json", testPackageJson);
|
|
141
|
+
|
|
142
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
143
|
+
check({
|
|
144
|
+
matchDependencyVersions: {
|
|
145
|
+
both: testPackageJson.dependencies!.both,
|
|
146
|
+
greatLib: testPackageJson.dependencies!.greatLib,
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("Fixes packages that have an incorrect dependency and devDependency versions", async () => {
|
|
153
|
+
const { addErrorSpy, check, host } = makeWorkspace(true);
|
|
154
|
+
const readTestPackageJson = addPackageJson(host, "./package.json", testPackageJson);
|
|
155
|
+
|
|
156
|
+
const requiredBothVersion = "1.2.3";
|
|
157
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
158
|
+
check({ matchDependencyVersions: { both: requiredBothVersion } });
|
|
159
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(2);
|
|
160
|
+
expect(readTestPackageJson().dependencies!.both).toEqual(requiredBothVersion);
|
|
161
|
+
expect(readTestPackageJson().devDependencies!.both).toEqual(requiredBothVersion);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe("Multiple accepted versions tests", () => {
|
|
166
|
+
let testPackageJson: PackageJson;
|
|
167
|
+
|
|
168
|
+
beforeEach(() => {
|
|
169
|
+
testPackageJson = {
|
|
170
|
+
name: "test",
|
|
171
|
+
dependencies: {
|
|
172
|
+
greatLib: "^15",
|
|
173
|
+
both: "1",
|
|
174
|
+
},
|
|
175
|
+
peerDependencies: {
|
|
176
|
+
whatever: "15",
|
|
177
|
+
},
|
|
178
|
+
devDependencies: {
|
|
179
|
+
else: "27.2.1",
|
|
180
|
+
both: "1",
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("Accepts a match when multiple versions are configured", async () => {
|
|
186
|
+
const { addErrorSpy, check, host } = makeWorkspace();
|
|
187
|
+
addPackageJson(host, "./package.json", testPackageJson);
|
|
188
|
+
|
|
189
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
190
|
+
check({ matchDependencyVersions: { greatLib: [testPackageJson.dependencies!.greatLib] } });
|
|
191
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
192
|
+
check({ matchDependencyVersions: { greatLib: ["1", "2", testPackageJson.dependencies!.greatLib] } });
|
|
193
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
194
|
+
check({ matchDependencyVersions: { greatLib: ["1", "2", testPackageJson.dependencies!.greatLib, "99", "100"] } });
|
|
195
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
196
|
+
check({ matchDependencyVersions: { greatLib: [testPackageJson.dependencies!.greatLib, "99", "100"] } });
|
|
197
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("Errors when version does not match", async () => {
|
|
201
|
+
const { addErrorSpy, check, host } = makeWorkspace();
|
|
202
|
+
addPackageJson(host, "./package.json", testPackageJson);
|
|
203
|
+
|
|
204
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
205
|
+
check({ matchDependencyVersions: { greatLib: ["1", "2"] } });
|
|
206
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
207
|
+
addErrorSpy.mockReset();
|
|
208
|
+
|
|
209
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
210
|
+
check({ matchDependencyVersions: { both: ["99", "100"] } });
|
|
211
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(2);
|
|
212
|
+
expect(addErrorSpy.mock.calls[0][0].message).toEqual(
|
|
213
|
+
`Expected dependency on both to match one of '["99","100"]', got '${
|
|
214
|
+
testPackageJson.dependencies!.both
|
|
215
|
+
}' instead.`
|
|
216
|
+
);
|
|
217
|
+
expect(addErrorSpy.mock.calls[1][0].message).toEqual(
|
|
218
|
+
`Expected devDependency on both to match one of '["99","100"]', got '${
|
|
219
|
+
testPackageJson.devDependencies!.both
|
|
220
|
+
}' instead.`
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -6,77 +6,96 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// tslint:disable:no-console
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import { Failure, PackageContext } from "@monorepolint/core";
|
|
15
|
-
import * as path from "path";
|
|
16
|
-
import { fileContents } from "../fileContents";
|
|
9
|
+
import { createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils.js";
|
|
10
|
+
import { AddErrorOptions, Failure } from "@monorepolint/config";
|
|
11
|
+
import { fileContents } from "../fileContents.js";
|
|
12
|
+
import { describe, expect, it, beforeEach, jest } from "@jest/globals";
|
|
17
13
|
|
|
18
14
|
const EXPECTED_FOO_FILE = "hello world";
|
|
19
15
|
|
|
20
|
-
describe("fileContents", () => {
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
mockFiles.clear();
|
|
23
|
-
});
|
|
24
|
-
|
|
16
|
+
describe.each(HOST_FACTORIES)("fileContents ($name)", (hostFactory) => {
|
|
25
17
|
describe("fix: true", () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
fix: true,
|
|
29
|
-
verbose: false,
|
|
30
|
-
silent: true,
|
|
31
|
-
});
|
|
32
|
-
const spy = jest.spyOn(context, "addError");
|
|
18
|
+
let workspace: TestingWorkspace;
|
|
19
|
+
let spy: jest.SpiedFunction<(opts: AddErrorOptions) => void>;
|
|
33
20
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
workspace = await createTestingWorkspace({
|
|
23
|
+
fixFlag: true,
|
|
24
|
+
host: hostFactory.make(),
|
|
25
|
+
});
|
|
26
|
+
workspace.writeFile("shared/foo-template.txt", EXPECTED_FOO_FILE);
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
spy = jest.spyOn(workspace.context, "addError");
|
|
29
|
+
});
|
|
40
30
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
31
|
+
it("works with async generator", async () => {
|
|
32
|
+
await fileContents({
|
|
33
|
+
options: {
|
|
34
|
+
file: "foo.txt",
|
|
35
|
+
generator: () => Promise.resolve(EXPECTED_FOO_FILE),
|
|
36
|
+
},
|
|
37
|
+
}).check(workspace.context);
|
|
47
38
|
|
|
48
39
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
49
40
|
|
|
50
41
|
const failure: Failure = spy.mock.calls[0][0];
|
|
51
|
-
expect(failure
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
expect(failure).toMatchObject(
|
|
43
|
+
workspace.failureMatcher({
|
|
44
|
+
file: "foo.txt",
|
|
45
|
+
hasFixer: true,
|
|
46
|
+
message: "Expect file contents to match",
|
|
47
|
+
})
|
|
48
|
+
);
|
|
54
49
|
|
|
55
|
-
expect(
|
|
50
|
+
expect(workspace.readFile("foo.txt")).toEqual(EXPECTED_FOO_FILE);
|
|
56
51
|
});
|
|
57
52
|
|
|
58
|
-
it("fixes missing
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
it("fixes missing file", async () => {
|
|
54
|
+
await fileContents({
|
|
55
|
+
options: {
|
|
56
|
+
file: "foo.txt",
|
|
57
|
+
templateFile: "shared/foo-template.txt",
|
|
58
|
+
generator: undefined,
|
|
59
|
+
template: undefined,
|
|
60
|
+
},
|
|
61
|
+
}).check(workspace.context);
|
|
62
|
+
|
|
63
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
64
|
+
|
|
65
|
+
const failure: Failure = spy.mock.calls[0][0];
|
|
66
|
+
expect(failure).toMatchObject(
|
|
67
|
+
workspace.failureMatcher({
|
|
68
|
+
file: "foo.txt",
|
|
69
|
+
hasFixer: true,
|
|
70
|
+
message: "Expect file contents to match",
|
|
71
|
+
})
|
|
62
72
|
);
|
|
63
73
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
expect(workspace.readFile("foo.txt")).toEqual(EXPECTED_FOO_FILE);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("fixes missing nested file", async () => {
|
|
78
|
+
await fileContents({
|
|
79
|
+
options: {
|
|
80
|
+
file: "nested/foo.txt",
|
|
81
|
+
templateFile: "shared/foo-template.txt",
|
|
82
|
+
generator: undefined,
|
|
83
|
+
template: undefined,
|
|
84
|
+
},
|
|
85
|
+
}).check(workspace.context);
|
|
70
86
|
|
|
71
87
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
72
88
|
|
|
73
89
|
const failure: Failure = spy.mock.calls[0][0];
|
|
74
|
-
expect(failure
|
|
75
|
-
|
|
76
|
-
|
|
90
|
+
expect(failure).toMatchObject(
|
|
91
|
+
workspace.failureMatcher({
|
|
92
|
+
file: "nested/foo.txt",
|
|
93
|
+
hasFixer: true,
|
|
94
|
+
message: "Expect file contents to match",
|
|
95
|
+
})
|
|
96
|
+
);
|
|
77
97
|
|
|
78
|
-
expect(
|
|
79
|
-
expect(mockFiles.get("nested/foo.txt")).toEqual(EXPECTED_FOO_FILE);
|
|
98
|
+
expect(workspace.readFile("nested/foo.txt")).toEqual(EXPECTED_FOO_FILE);
|
|
80
99
|
});
|
|
81
100
|
});
|
|
82
101
|
});
|