1 | import {Utility} from "../src/classLibrary/Utility";
|
2 | import {IDirectory, IFile} from "../src/classLibrary/File";
|
3 | import {Core, Kore, SortType} from "@kirinnee/core";
|
4 | import {should} from 'chai';
|
5 | import {MoveResolver} from "../src/classLibrary/ParsingStrategy/MoveResolver";
|
6 |
|
7 | should();
|
8 |
|
9 | let core: Core = new Kore();
|
10 | core.ExtendPrimitives();
|
11 |
|
12 | let util: Utility = new Utility(core);
|
13 |
|
14 | let packageParser: MoveResolver = new MoveResolver(util);
|
15 | let flags: object = {
|
16 | a: false,
|
17 | b: false,
|
18 | move: {
|
19 | "@types/mocha": true,
|
20 | "@types/chai": false
|
21 | }
|
22 | };
|
23 |
|
24 | describe("MoveResolver", () => {
|
25 | describe("ResolveJsonFile", () => {
|
26 | it("should move dev dependency to dependency", () => {
|
27 |
|
28 | let map: Map<string, boolean> = new Map<string, boolean>([
|
29 | ["@types/mocha", true],
|
30 | ["@types/chai", false]
|
31 | ]);
|
32 |
|
33 | let testSubj: string =
|
34 | `{
|
35 | "name": "@kirinnee/weave",
|
36 | "license": "MIT",
|
37 | "devDependencies": {
|
38 | "@types/chai": "^4.1.5",
|
39 | "@types/mocha": "^5.2.5",
|
40 | "@types/webpack": "^4.4.12",
|
41 | "typescript": "^3.0.3",
|
42 | "webpack": "^4.19.1",
|
43 | "webpack-cli": "^3.1.0"
|
44 | },
|
45 | "dependencies": {
|
46 | "chai": "^4.1.2",
|
47 | "mocha": "^5.2.0"
|
48 | }
|
49 | }`;
|
50 | let expectedContent: string =
|
51 | `{
|
52 | "name": "@kirinnee/weave",
|
53 | "license": "MIT",
|
54 | "devDependencies": {
|
55 | "@types/chai": "^4.1.5",
|
56 | "@types/webpack": "^4.4.12",
|
57 | "typescript": "^3.0.3",
|
58 | "webpack": "^4.19.1",
|
59 | "webpack-cli": "^3.1.0"
|
60 | },
|
61 | "dependencies": {
|
62 | "chai": "^4.1.2",
|
63 | "mocha": "^5.2.0",
|
64 | "@types/mocha": "^5.2.5"
|
65 | }
|
66 | }`;
|
67 | let testFile: IFile = {
|
68 | destinationAbsolutePath: "root/package.json",
|
69 | sourceAbsolutePath: "root/package.json",
|
70 | relativePath: "root/package.json",
|
71 | content: testSubj
|
72 | };
|
73 |
|
74 | let expectedFile: IFile = {
|
75 | destinationAbsolutePath: "root/package.json",
|
76 | sourceAbsolutePath: "root/package.json",
|
77 | relativePath: "root/package.json",
|
78 | content: expectedContent
|
79 | };
|
80 |
|
81 | packageParser.ResolveJsonFile(map, testFile).should.deep.equal(expectedFile);
|
82 | });
|
83 |
|
84 | it("should move dependency to dev dependency", () => {
|
85 |
|
86 | let map: Map<string, boolean> = new Map<string, boolean>([
|
87 | ["@types/mocha", false],
|
88 | ["@types/chai", true]
|
89 | ]);
|
90 |
|
91 | let testSubj: string =
|
92 | `{
|
93 | "name": "@kirinnee/weave",
|
94 | "license": "MIT",
|
95 | "devDependencies": {
|
96 | "@types/webpack": "^4.4.12",
|
97 | "typescript": "^3.0.3",
|
98 | "webpack": "^4.19.1",
|
99 | "webpack-cli": "^3.1.0"
|
100 | },
|
101 | "dependencies": {
|
102 | "@types/chai": "^4.1.5",
|
103 | "@types/mocha": "^5.2.5",
|
104 | "chai": "^4.1.2",
|
105 | "mocha": "^5.2.0"
|
106 | }
|
107 | }`;
|
108 | let expectedContent: string =
|
109 | `{
|
110 | "name": "@kirinnee/weave",
|
111 | "license": "MIT",
|
112 | "devDependencies": {
|
113 | "@types/webpack": "^4.4.12",
|
114 | "typescript": "^3.0.3",
|
115 | "webpack": "^4.19.1",
|
116 | "webpack-cli": "^3.1.0",
|
117 | "@types/chai": "^4.1.5"
|
118 | },
|
119 | "dependencies": {
|
120 | "@types/mocha": "^5.2.5",
|
121 | "chai": "^4.1.2",
|
122 | "mocha": "^5.2.0"
|
123 | }
|
124 | }`;
|
125 | let testFile: IFile = {
|
126 | destinationAbsolutePath: "root/package.json",
|
127 | sourceAbsolutePath: "root/package.json",
|
128 | relativePath: "root/package.json",
|
129 | content: testSubj
|
130 | };
|
131 |
|
132 | let expectedFile: IFile = {
|
133 | destinationAbsolutePath: "root/package.json",
|
134 | sourceAbsolutePath: "root/package.json",
|
135 | relativePath: "root/package.json",
|
136 | content: expectedContent
|
137 | };
|
138 |
|
139 | packageParser.ResolveJsonFile(map, testFile).should.deep.equal(expectedFile);
|
140 | });
|
141 | });
|
142 |
|
143 | describe("ResolveContents", () => {
|
144 | it("should move dev dependency to dependency", () => {
|
145 | let testSubj: string =
|
146 | `{
|
147 | "name": "@kirinnee/weave",
|
148 | "license": "MIT",
|
149 | "devDependencies": {
|
150 | "@types/chai": "^4.1.5",
|
151 | "@types/mocha": "^5.2.5",
|
152 | "@types/webpack": "^4.4.12",
|
153 | "typescript": "^3.0.3",
|
154 | "webpack": "^4.19.1",
|
155 | "webpack-cli": "^3.1.0"
|
156 | },
|
157 | "dependencies": {
|
158 | "chai": "^4.1.2",
|
159 | "mocha": "^5.2.0"
|
160 | }
|
161 | }`;
|
162 | let expectedContent: string =
|
163 | `{
|
164 | "name": "@kirinnee/weave",
|
165 | "license": "MIT",
|
166 | "devDependencies": {
|
167 | "@types/chai": "^4.1.5",
|
168 | "@types/webpack": "^4.4.12",
|
169 | "typescript": "^3.0.3",
|
170 | "webpack": "^4.19.1",
|
171 | "webpack-cli": "^3.1.0"
|
172 | },
|
173 | "dependencies": {
|
174 | "chai": "^4.1.2",
|
175 | "mocha": "^5.2.0",
|
176 | "@types/mocha": "^5.2.5"
|
177 | }
|
178 | }`;
|
179 | let testFile: IFile = {
|
180 | destinationAbsolutePath: "root/package.json",
|
181 | sourceAbsolutePath: "root/package.json",
|
182 | relativePath: "root/package.json",
|
183 | content: testSubj
|
184 | };
|
185 | let file2: IFile = {
|
186 | destinationAbsolutePath: "root/main.js",
|
187 | sourceAbsolutePath: "root/main.js",
|
188 | relativePath: "root/main.js",
|
189 | content: "rofl"
|
190 | };
|
191 | let dir: IDirectory = {
|
192 | destinationAbsolutePath: "root/src",
|
193 | sourceAbsolutePath: "root/src",
|
194 | relativePath: "root/src"
|
195 | };
|
196 |
|
197 | let expectedFile: IFile = {
|
198 | destinationAbsolutePath: "root/package.json",
|
199 | sourceAbsolutePath: "root/package.json",
|
200 | relativePath: "root/package.json",
|
201 | content: expectedContent
|
202 | };
|
203 | let expectedFile2: IFile = {
|
204 | destinationAbsolutePath: "root/main.js",
|
205 | sourceAbsolutePath: "root/main.js",
|
206 | relativePath: "root/main.js",
|
207 | content: "rofl"
|
208 | };
|
209 | let expectedDir: IDirectory = {
|
210 | destinationAbsolutePath: "root/src",
|
211 | sourceAbsolutePath: "root/src",
|
212 | relativePath: "root/src"
|
213 | };
|
214 |
|
215 | let test = [testFile, file2, dir];
|
216 | let expected = [expectedFile, expectedFile2, expectedDir];
|
217 |
|
218 | packageParser.ResolveContents(flags, test).should.deep.equal(expected);
|
219 |
|
220 |
|
221 | });
|
222 | it("should move dependency to dev dependency", () => {
|
223 | let testSubj: string =
|
224 | `{
|
225 | "name": "@kirinnee/weave",
|
226 | "license": "MIT",
|
227 | "devDependencies": {
|
228 | "@types/webpack": "^4.4.12",
|
229 | "typescript": "^3.0.3",
|
230 | "webpack": "^4.19.1",
|
231 | "webpack-cli": "^3.1.0"
|
232 | },
|
233 | "dependencies": {
|
234 | "@types/chai": "^4.1.5",
|
235 | "@types/mocha": "^5.2.5",
|
236 | "chai": "^4.1.2",
|
237 | "mocha": "^5.2.0"
|
238 | }
|
239 | }`;
|
240 | let expectedContent: string =
|
241 | `{
|
242 | "name": "@kirinnee/weave",
|
243 | "license": "MIT",
|
244 | "devDependencies": {
|
245 | "@types/webpack": "^4.4.12",
|
246 | "typescript": "^3.0.3",
|
247 | "webpack": "^4.19.1",
|
248 | "webpack-cli": "^3.1.0",
|
249 | "@types/mocha": "^5.2.5"
|
250 | },
|
251 | "dependencies": {
|
252 | "@types/chai": "^4.1.5",
|
253 | "chai": "^4.1.2",
|
254 | "mocha": "^5.2.0"
|
255 | }
|
256 | }`;
|
257 | let testFile: IFile = {
|
258 | destinationAbsolutePath: "root/package.json",
|
259 | sourceAbsolutePath: "root/package.json",
|
260 | relativePath: "root/package.json",
|
261 | content: testSubj
|
262 | };
|
263 | let file2: IFile = {
|
264 | destinationAbsolutePath: "root/main.js",
|
265 | sourceAbsolutePath: "root/main.js",
|
266 | relativePath: "root/main.js",
|
267 | content: "rofl"
|
268 | };
|
269 | let dir: IDirectory = {
|
270 | destinationAbsolutePath: "root/src",
|
271 | sourceAbsolutePath: "root/src",
|
272 | relativePath: "root/src"
|
273 | };
|
274 |
|
275 | let expectedFile: IFile = {
|
276 | destinationAbsolutePath: "root/package.json",
|
277 | sourceAbsolutePath: "root/package.json",
|
278 | relativePath: "root/package.json",
|
279 | content: expectedContent
|
280 | };
|
281 | let expectedFile2: IFile = {
|
282 | destinationAbsolutePath: "root/main.js",
|
283 | sourceAbsolutePath: "root/main.js",
|
284 | relativePath: "root/main.js",
|
285 | content: "rofl"
|
286 | };
|
287 | let expectedDir: IDirectory = {
|
288 | destinationAbsolutePath: "root/src",
|
289 | sourceAbsolutePath: "root/src",
|
290 | relativePath: "root/src"
|
291 | };
|
292 |
|
293 | let test = [testFile, file2, dir];
|
294 | let expected = [expectedFile, expectedFile2, expectedDir];
|
295 |
|
296 | packageParser.ResolveContents(flags, test).should.deep.equal(expected);
|
297 |
|
298 |
|
299 | });
|
300 | });
|
301 |
|
302 |
|
303 | describe("Count", () => {
|
304 | it("should count the occurrences of the move flags", () => {
|
305 | let testSubj: string =
|
306 | `{
|
307 | "name": "@kirinnee/weave",
|
308 | "license": "MIT",
|
309 | "devDependencies": {
|
310 | "@types/chai": "^4.1.5",
|
311 | "@types/mocha": "^5.2.5",
|
312 | "@types/webpack": "^4.4.12",
|
313 | "typescript": "^3.0.3",
|
314 | "webpack": "^4.19.1",
|
315 | "webpack-cli": "^3.1.0"
|
316 | },
|
317 | "dependencies": {
|
318 | "chai": "^4.1.2",
|
319 | "mocha": "^5.2.0"
|
320 | }
|
321 | }`;
|
322 |
|
323 | let testFile: IFile = {
|
324 | destinationAbsolutePath: "root/package.json",
|
325 | sourceAbsolutePath: "root/package.json",
|
326 | relativePath: "root/package.json",
|
327 | content: testSubj
|
328 | };
|
329 | let file2: IFile = {
|
330 | destinationAbsolutePath: "root/main.js",
|
331 | sourceAbsolutePath: "root/main.js",
|
332 | relativePath: "root/main.js",
|
333 | content: "rofl"
|
334 | };
|
335 | let dir: IDirectory = {
|
336 | destinationAbsolutePath: "root/src",
|
337 | sourceAbsolutePath: "root/src",
|
338 | relativePath: "root/src"
|
339 | };
|
340 |
|
341 | let test = [dir, file2, testFile];
|
342 |
|
343 | let expected: [string, number][] = new Map([
|
344 | ["move.@types/mocha", 1],
|
345 | ["move.@types/chai", 1]
|
346 | ])
|
347 | .SortByKey(SortType.AtoZ)
|
348 | .Arr();
|
349 |
|
350 | let oldMap: Map<string, number> = new Map([
|
351 | ["move.chai", 1],
|
352 | ["move.@types/mocha", 1],
|
353 | ]);
|
354 | let oldExpected: [string, number][] = new Map([
|
355 | ["move.chai", 1],
|
356 | ["move.@types/mocha", 2],
|
357 | ["move.@types/chai", 1]
|
358 | ])
|
359 | .SortByKey(SortType.AtoZ)
|
360 | .Arr();
|
361 |
|
362 | packageParser.Count(flags, test, new Map([]), true).SortByKey(SortType.AtoZ).Arr().should.deep.equal(expected);
|
363 | packageParser.Count(flags, test, oldMap, true).SortByKey(SortType.AtoZ).Arr().should.deep.equal(oldExpected);
|
364 | });
|
365 | });
|
366 | });
|
367 |
|