source: frontend/node_modules/tsconfig-paths/src/__tests__/config-loader.test.ts

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.4 KB
Line 
1import {
2 configLoader,
3 loadConfig,
4 ConfigLoaderFailResult,
5 ConfigLoaderSuccessResult,
6} from "../config-loader";
7import { join } from "path";
8
9describe("config-loader", (): void => {
10 it("should use explicitParams when set", () => {
11 const result = configLoader({
12 explicitParams: {
13 baseUrl: "/foo/bar",
14 paths: {
15 asd: ["asd"],
16 },
17 },
18 cwd: "/baz",
19 });
20
21 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");
25 expect(successResult.resultType).toBe("success");
26 expect(successResult.absoluteBaseUrl).toBe("/foo/bar");
27 expect(successResult.paths["asd"][0]).toBe("asd");
28 });
29
30 it("should use explicitParams when set and add cwd when path is relative", () => {
31 const result = configLoader({
32 explicitParams: {
33 baseUrl: "bar/",
34 paths: {
35 asd: ["asd"],
36 },
37 },
38 cwd: "/baz",
39 });
40
41 const successResult = result as ConfigLoaderSuccessResult;
42 // assert.equal(successResult.resultType, "success");
43 // assert.equal(successResult.absoluteBaseUrl, join("/baz", "bar/"));
44 expect(successResult.resultType).toBe("success");
45 expect(successResult.absoluteBaseUrl).toBe(join("/baz", "bar/"));
46 });
47
48 it("should fallback to tsConfigLoader when explicitParams is not set", () => {
49 const result = configLoader({
50 explicitParams: undefined,
51 cwd: "/baz",
52 // tslint:disable-next-line:no-any
53 tsConfigLoader: (_: any) => ({
54 tsConfigPath: "/baz/tsconfig.json",
55 baseUrl: "./src",
56 paths: {},
57 }),
58 });
59
60 const successResult = result as ConfigLoaderSuccessResult;
61 // assert.equal(successResult.resultType, "success");
62 // assert.equal(successResult.absoluteBaseUrl, join("/baz", "src"));
63 expect(successResult.resultType).toBe("success");
64 expect(successResult.absoluteBaseUrl).toBe(join("/baz", "src"));
65 });
66
67 it("should show an error message when baseUrl is missing", () => {
68 const result = configLoader({
69 explicitParams: undefined,
70 cwd: "/baz",
71 // tslint:disable-next-line:no-any
72 tsConfigLoader: (_: any) => ({
73 tsConfigPath: "/baz/tsconfig.json",
74 baseUrl: undefined,
75 paths: {},
76 }),
77 });
78
79 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();
84 });
85
86 it("should presume cwd to be a tsconfig file when loadConfig is called with absolute path to tsconfig.json", () => {
87 // using tsconfig-named.json to ensure that future changes to fix
88 // https://github.com/dividab/tsconfig-paths/issues/31
89 // do not pass this test case just because of a directory walk looking
90 // for tsconfig.json
91 const configFile = join(__dirname, "tsconfig-named.json");
92 const result = loadConfig(configFile);
93
94 const successResult = result as ConfigLoaderSuccessResult;
95 // assert.equal(successResult.resultType, "success");
96 // assert.equal(successResult.configFileAbsolutePath, configFile);
97 expect(successResult.resultType).toBe("success");
98 expect(successResult.configFileAbsolutePath).toBe(configFile);
99 });
100});
Note: See TracBrowser for help on using the repository browser.