Skip to content

Commit bad40f2

Browse files
Fix tests and lint (#211)
* Fix tests and lint for config-loader * Fix another broken test * Remove commented-out assertions * Remove unused parameters * Fix failing test * Remove remaining commented-out assertions Co-authored-by: Jonas Kello <[email protected]>
1 parent 8e4452c commit bad40f2

File tree

7 files changed

+10
-142
lines changed

7 files changed

+10
-142
lines changed

src/__tests__/config-loader.test.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ describe("config-loader", (): void => {
1919
});
2020

2121
const successResult = result as ConfigLoaderSuccessResult;
22-
// assert.equal(successResult.resultType, "success");
23-
// assert.equal(successResult.absoluteBaseUrl, "/foo/bar");
24-
// assert.equal(successResult.paths["asd"][0], "asd");
2522
expect(successResult.resultType).toBe("success");
2623
expect(successResult.absoluteBaseUrl).toBe("/foo/bar");
2724
expect(successResult.paths["asd"][0]).toBe("asd");
@@ -39,8 +36,6 @@ describe("config-loader", (): void => {
3936
});
4037

4138
const successResult = result as ConfigLoaderSuccessResult;
42-
// assert.equal(successResult.resultType, "success");
43-
// assert.equal(successResult.absoluteBaseUrl, join("/baz", "bar/"));
4439
expect(successResult.resultType).toBe("success");
4540
expect(successResult.absoluteBaseUrl).toBe(join("/baz", "bar/"));
4641
});
@@ -49,38 +44,31 @@ describe("config-loader", (): void => {
4944
const result = configLoader({
5045
explicitParams: undefined,
5146
cwd: "/baz",
52-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
53-
tsConfigLoader: (_: any) => ({
47+
tsConfigLoader: () => ({
5448
tsConfigPath: "/baz/tsconfig.json",
5549
baseUrl: "./src",
5650
paths: {},
5751
}),
5852
});
5953

6054
const successResult = result as ConfigLoaderSuccessResult;
61-
// assert.equal(successResult.resultType, "success");
62-
// assert.equal(successResult.absoluteBaseUrl, join("/baz", "src"));
6355
expect(successResult.resultType).toBe("success");
6456
expect(successResult.absoluteBaseUrl).toBe(join("/baz", "src"));
6557
});
6658

67-
it("should show an error message when baseUrl is missing", () => {
59+
it("should tolerate a missing baseUrl", () => {
6860
const result = configLoader({
6961
explicitParams: undefined,
7062
cwd: "/baz",
71-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
72-
tsConfigLoader: (_: any) => ({
63+
tsConfigLoader: () => ({
7364
tsConfigPath: "/baz/tsconfig.json",
7465
baseUrl: undefined,
7566
paths: {},
7667
}),
7768
});
7869

7970
const failResult = result as ConfigLoaderFailResult;
80-
// assert.equal(failResult.resultType, "failed");
81-
// assert.isTrue(failResult.message.indexOf("baseUrl") > -1);
82-
expect(failResult.resultType).toBe("failed");
83-
expect(failResult.message.indexOf("baseUrl") > -1).toBeTruthy();
71+
expect(failResult.resultType).toBe("success");
8472
});
8573

8674
it("should presume cwd to be a tsconfig file when loadConfig is called with absolute path to tsconfig.json", () => {
@@ -92,8 +80,6 @@ describe("config-loader", (): void => {
9280
const result = loadConfig(configFile);
9381

9482
const successResult = result as ConfigLoaderSuccessResult;
95-
// assert.equal(successResult.resultType, "success");
96-
// assert.equal(successResult.configFileAbsolutePath, configFile);
9783
expect(successResult.resultType).toBe("success");
9884
expect(successResult.configFileAbsolutePath).toBe(configFile);
9985
});
@@ -102,15 +88,14 @@ describe("config-loader", (): void => {
10288
const result = configLoader({
10389
explicitParams: undefined,
10490
cwd: "/baz",
105-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
106-
tsConfigLoader: (_: any) => ({
91+
tsConfigLoader: () => ({
10792
tsConfigPath: "/baz/tsconfig.json",
10893
baseUrl: "/baz",
10994
paths: {},
11095
}),
11196
});
11297

11398
const successResult = result as ConfigLoaderSuccessResult;
114-
assert.equal(successResult.absoluteBaseUrl, "/baz");
99+
expect(successResult.absoluteBaseUrl).toEqual("/baz");
115100
});
116101
});

src/__tests__/filesystem.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,17 @@ describe("filesystem", () => {
77

88
it("should find file that exists, sync", () => {
99
const result = Filesystem.fileExistsSync(fileThatExists);
10-
// assert.equal(result, true);
1110
expect(result).toBe(true);
1211
});
1312

1413
it("should not find file that not exists, sync", () => {
1514
const result = Filesystem.fileExistsSync(fileThatNotExists);
16-
// assert.equal(result, false);
1715
expect(result).toBe(false);
1816
});
1917

2018
it("should find file that exists, async", (done) => {
2119
Filesystem.fileExistsAsync(fileThatExists, (_err, result) => {
2220
try {
23-
// assert.equal(result, true);
2421
expect(result).toBe(true);
2522
done();
2623
} catch (error) {
@@ -32,7 +29,6 @@ describe("filesystem", () => {
3229
it("should not find file that not exists, async", (done) => {
3330
Filesystem.fileExistsAsync(fileThatNotExists, (_err, result) => {
3431
try {
35-
// assert.equal(result, false);
3632
expect(result).toBe(false);
3733
done();
3834
} catch (error) {
@@ -43,18 +39,14 @@ describe("filesystem", () => {
4339

4440
it("should load json, sync", () => {
4541
const result = Filesystem.readJsonFromDiskSync(fileThatExists);
46-
// assert.isOk(result);
4742
expect(result);
48-
// assert.equal(result.main, "lib/index.js");
4943
expect(result.main).toBe("lib/index.js");
5044
});
5145

5246
it("should load json, async", (done) => {
5347
Filesystem.readJsonFromDiskAsync(fileThatExists, (_err, result) => {
5448
try {
55-
// assert.isOk(result); // Asserts that object is truthy.
5649
expect(result).toBeTruthy();
57-
// assert.equal(result.main, "lib/index.js");
5850
expect(result.main).toBe("lib/index.js");
5951
done();
6052
} catch (error) {

src/__tests__/mapping-entry.test.ts

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,30 @@ describe("mapping-entry", () => {
66
const result = getAbsoluteMappingEntries(
77
"/absolute/base/url",
88
{
9-
"*": ["/foo1", "/foo2"],
10-
"longest/pre/fix/*": ["/foo2/bar"],
9+
"*": ["/foo1", "./foo2"],
10+
"longest/pre/fix/*": ["./foo2/bar"],
1111
"pre/fix/*": ["/foo3"],
1212
},
1313
true
1414
);
15-
// assert.deepEqual(result, [
16-
// {
17-
// pattern: "longest/pre/fix/*",
18-
// paths: [join("/absolute", "base", "url", "foo2", "bar")],
19-
// },
20-
// {
21-
// pattern: "pre/fix/*",
22-
// paths: [join("/absolute", "base", "url", "foo3")],
23-
// },
24-
// {
25-
// pattern: "*",
26-
// paths: [
27-
// join("/absolute", "base", "url", "foo1"),
28-
// join("/absolute", "base", "url", "foo2"),
29-
// ],
30-
// },
31-
// ]);
3215
expect(result).toEqual([
3316
{
3417
pattern: "longest/pre/fix/*",
3518
paths: [join("/absolute", "base", "url", "foo2", "bar")],
3619
},
3720
{
3821
pattern: "pre/fix/*",
39-
paths: [join("/absolute", "base", "url", "foo3")],
22+
paths: [join("/foo3")],
4023
},
4124
{
4225
pattern: "*",
43-
paths: [
44-
join("/absolute", "base", "url", "foo1"),
45-
join("/absolute", "base", "url", "foo2"),
46-
],
26+
paths: [join("/foo1"), join("/absolute", "base", "url", "foo2")],
4727
},
4828
]);
4929
});
5030

5131
it("should should add a match-all pattern when requested", () => {
5232
let result = getAbsoluteMappingEntries("/absolute/base/url", {}, true);
53-
// assert.deepEqual(result, [
54-
// {
55-
// pattern: "*",
56-
// paths: [join("/absolute", "base", "url", "*")],
57-
// },
58-
// ]);
5933
expect(result).toEqual([
6034
{
6135
pattern: "*",
@@ -64,7 +38,6 @@ describe("mapping-entry", () => {
6438
]);
6539

6640
result = getAbsoluteMappingEntries("/absolute/base/url", {}, false);
67-
// assert.deepEqual(result, []);
6841
expect(result).toEqual([]);
6942
});
7043
});

src/__tests__/match-path-async.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe("match-path-async", () => {
1717
callback(undefined, t.existingFiles.indexOf(path) !== -1),
1818
t.extensions,
1919
(_err, result) => {
20-
// assert.equal(result, t.expectedPath);
2120
expect(result).toBe(t.expectedPath);
2221
done();
2322
}

src/__tests__/match-path-sync.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ describe("match-path-sync", () => {
1616
(name: string) => t.existingFiles.indexOf(name) !== -1,
1717
t.extensions
1818
);
19-
// assert.equal(result, t.expectedPath);
2019
expect(result).toBe(t.expectedPath);
2120
})
2221
);

src/__tests__/try-path.test.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ describe("mapping-entry", () => {
2626
abosolutePathMappings,
2727
"./requested-module"
2828
);
29-
// assert.deepEqual(result, undefined);
3029
expect(result).toBeUndefined();
3130
});
3231

@@ -54,46 +53,6 @@ describe("mapping-entry", () => {
5453
abosolutePathMappings,
5554
"longest/pre/fix/requested-module"
5655
);
57-
// assert.deepEqual(result, [
58-
// // "longest/pre/fix/*"
59-
// { type: "file", path: join("/absolute", "base", "url", "foo2", "bar") },
60-
// {
61-
// type: "extension",
62-
// path: join("/absolute", "base", "url", "foo2", "bar.ts"),
63-
// },
64-
// {
65-
// type: "extension",
66-
// path: join("/absolute", "base", "url", "foo2", "bar.tsx"),
67-
// },
68-
// {
69-
// type: "package",
70-
// path: join("/absolute", "base", "url", "foo2", "bar", "package.json"),
71-
// },
72-
// {
73-
// type: "index",
74-
// path: join("/absolute", "base", "url", "foo2", "bar", "index.ts"),
75-
// },
76-
// {
77-
// type: "index",
78-
// path: join("/absolute", "base", "url", "foo2", "bar", "index.tsx"),
79-
// },
80-
// // "*"
81-
// { type: "file", path: join("/absolute", "base", "url", "foo1") },
82-
// { type: "extension", path: join("/absolute", "base", "url", "foo1.ts") },
83-
// { type: "extension", path: join("/absolute", "base", "url", "foo1.tsx") },
84-
// {
85-
// type: "package",
86-
// path: join("/absolute", "base", "url", "foo1", "package.json"),
87-
// },
88-
// {
89-
// type: "index",
90-
// path: join("/absolute", "base", "url", "foo1", "index.ts"),
91-
// },
92-
// {
93-
// type: "index",
94-
// path: join("/absolute", "base", "url", "foo1", "index.tsx"),
95-
// },
96-
// ]);
9756
expect(result).toEqual([
9857
// "longest/pre/fix/*"
9958
{ type: "file", path: join("/absolute", "base", "url", "foo2", "bar") },
@@ -180,14 +139,3 @@ describe("mapping-entry", () => {
180139
]);
181140
});
182141
});
183-
184-
// describe("match-star", () => {
185-
// it("should match star in last position", () => {
186-
// const result = matchStar("lib/*", "lib/mylib");
187-
// assert.equal(result, "mylib");
188-
// });
189-
// it("should match star in first position", () => {
190-
// const result = matchStar("*/lib", "mylib/lib");
191-
// assert.equal(result, "mylib");
192-
// });
193-
// });

src/__tests__/tsconfig-loader.test.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ describe("tsconfig-loader", () => {
1919
},
2020
});
2121

22-
// assert.equal(result.tsConfigPath, "/foo/bar/tsconfig.json");
2322
expect(result.tsConfigPath).toBe("/foo/bar/tsconfig.json");
2423
});
2524

@@ -36,7 +35,6 @@ describe("tsconfig-loader", () => {
3635
},
3736
});
3837

39-
// assert.isUndefined(result.tsConfigPath);
4038
expect(result.tsConfigPath).toBeUndefined();
4139
});
4240

@@ -62,7 +60,6 @@ describe("tsconfig-loader", () => {
6260
},
6361
});
6462

65-
// assert.equal(result.tsConfigPath, "/foo/baz/tsconfig.json");
6663
expect(result.tsConfigPath).toBe("/foo/baz/tsconfig.json");
6764
});
6865

@@ -80,7 +77,6 @@ describe("tsconfig-loader", () => {
8077
},
8178
});
8279

83-
// assert.equal(result.baseUrl, "SOME_BASEURL");
8480
expect(result.baseUrl).toBe("SOME_BASEURL");
8581
});
8682

@@ -99,7 +95,6 @@ describe("tsconfig-loader", () => {
9995
},
10096
});
10197

102-
// assert.equal(result.baseUrl, undefined);
10398
expect(result.baseUrl).toBeUndefined();
10499
});
105100
});
@@ -180,7 +175,6 @@ describe("loadConfig", () => {
180175
(path) => path === "/root/dir1/tsconfig.json",
181176
(_) => JSON.stringify(config)
182177
);
183-
// assert.deepEqual(res, config);
184178
expect(res).toStrictEqual(config);
185179
});
186180

@@ -196,7 +190,6 @@ describe("loadConfig", () => {
196190
}
197191
}`
198192
);
199-
// assert.deepEqual(res, config);
200193
expect(res).toStrictEqual(config);
201194
});
202195

@@ -211,7 +204,6 @@ describe("loadConfig", () => {
211204
},
212205
}`
213206
);
214-
// assert.deepEqual(res, config);
215207
expect(res).toStrictEqual(config);
216208
});
217209

@@ -243,14 +235,6 @@ describe("loadConfig", () => {
243235
}
244236
);
245237

246-
// assert.deepEqual(res, {
247-
// extends: "../base-config.json",
248-
// compilerOptions: {
249-
// baseUrl: "kalle",
250-
// paths: { foo: ["bar2"] },
251-
// strict: true,
252-
// },
253-
// });
254238
expect(res).toEqual({
255239
extends: "../base-config.json",
256240
compilerOptions: {
@@ -295,14 +279,6 @@ describe("loadConfig", () => {
295279
}
296280
);
297281

298-
// assert.deepEqual(res, {
299-
// extends: "my-package/base-config.json",
300-
// compilerOptions: {
301-
// baseUrl: "kalle",
302-
// paths: { foo: ["bar2"] },
303-
// strict: true,
304-
// },
305-
// });
306282
expect(res).toEqual({
307283
extends: "my-package/base-config.json",
308284
compilerOptions: {
@@ -340,10 +316,6 @@ describe("loadConfig", () => {
340316
}
341317
);
342318

343-
// assert.deepEqual(res, {
344-
// extends: "../second-config.json",
345-
// compilerOptions: { baseUrl: join("..", "..") },
346-
// });
347319
expect(res).toEqual({
348320
extends: "../second-config.json",
349321
compilerOptions: { baseUrl: join("..", "..") },

0 commit comments

Comments
 (0)