Skip to content

Commit

Permalink
chore: add test for resolving aliases from nested path
Browse files Browse the repository at this point in the history
  • Loading branch information
benyap committed May 14, 2022
1 parent ad267c5 commit 1e8aaf0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/steps/loadTSConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TSConfigPropertyError } from "~/utils/errors";
* Load the tsconfig file. If the file extends another tsconfig,
* it will be recursively loaded.
*
* @param path The path to the tsconfig file.
* @param basePath The path to the tsconfig file.
*/
export function loadTSConfig(basePath: string): TSConfig {
const baseConfig = loadJSON<TSConfig>(basePath, "loadTSConfig");
Expand Down
28 changes: 26 additions & 2 deletions test/steps/computeAliases.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { resolve } from "path";

import { computeAliases } from "~/steps/computeAliases";

describe("steps/computeAliases", () => {
it("computes aliases correctly", () => {
const aliases = computeAliases(".", {
it("computes aliases correctly from the root path", () => {
const aliases = computeAliases(resolve("."), {
compilerOptions: {
paths: {
"*": ["./lib/*"],
Expand All @@ -22,4 +24,26 @@ describe("steps/computeAliases", () => {
expect(aliases[1].aliasPaths).toEqual([`${cwd}/src`, `${cwd}/root`]);
expect(aliases[2].aliasPaths).toEqual([`${cwd}/src/app`]);
});

it("computes aliases correctly using a nested path", () => {
const aliases = computeAliases(resolve("./src"), {
compilerOptions: {
paths: {
"*": ["../lib/*"],
"~/*": ["./*", "../root/*"],
"@app": ["./app/*"],
},
},
});

expect(aliases).toHaveLength(3);
expect(aliases[0].prefix).toEqual("");
expect(aliases[1].prefix).toEqual("~/");
expect(aliases[2].prefix).toEqual("@app");

const cwd = process.cwd();
expect(aliases[0].aliasPaths).toEqual([`${cwd}/lib`]);
expect(aliases[1].aliasPaths).toEqual([`${cwd}/src`, `${cwd}/root`]);
expect(aliases[2].aliasPaths).toEqual([`${cwd}/src/app`]);
});
});

0 comments on commit 1e8aaf0

Please sign in to comment.