Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
effervescentia committed Apr 25, 2024
1 parent 525ffa2 commit ec0cda5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -69,5 +69,8 @@
"hooks": {
"pre-commit": "lint-staged"
}
},
"volta": {
"node": "16.20.2"
}
}
69 changes: 38 additions & 31 deletions src/__tests__/tsconfig-loader.test.ts
@@ -1,5 +1,6 @@
import { tsConfigLoader, walkForTsConfig } from "../tsconfig-loader";
import { join, resolve } from "path";
import { getTsconfig } from "get-tsconfig";

describe("tsconfig-loader", () => {
it("should find tsconfig in cwd", () => {
Expand Down Expand Up @@ -207,37 +208,7 @@ describe("loadSyncDefault", () => {

expect(result).toEqual({
baseUrl: undefined,
paths: { foo: ['bar'] },
tsConfigPath: resolve(cwd, 'tsconfig.json')
});
});

it("should load a config with string extends and overwrite all options", () => {
const cwd = resolve(__dirname, "../../example/extend-overwrite")
const tsConfigPath = resolve(cwd, 'nested/tsconfig.json');

const result = tsConfigLoader({
cwd,
getEnv: (name: string) => name === 'TS_NODE_PROJECT' ? tsConfigPath : undefined
});

expect(result).toEqual({
baseUrl: "./kalle",
paths: { foo: ["bar2"] },
strict: true,
tsConfigPath
});
});

it("should load a config with string extends from node_modules and overwrite all options", () => {
const cwd = resolve(__dirname, "../../example/extend-node-module")

const result = tsConfigLoader({ cwd, getEnv: () => undefined });

expect(result).toEqual({
baseUrl: "./kalle",
paths: { foo: ["bar2"] },
strict: true,
paths: { foo: ["bar"] },
tsConfigPath: resolve(cwd, "tsconfig.json")
});
});
Expand Down Expand Up @@ -289,3 +260,39 @@ describe("loadSyncDefault", () => {
});
});
});

describe("getTsconfig", () => {
it("should load a config with string extends and overwrite all options", () => {
const tsConfigPath = resolve(__dirname, "../../example/extend-overwrite/nested/tsconfig.json");

const result = getTsconfig(tsConfigPath);

expect(result).toEqual({
config: {
compilerOptions: {
baseUrl: "./kalle",
paths: { foo: ["bar2"] },
strict: true,
}
},
path: tsConfigPath
});
});

it("should load a config with string extends from node_modules and overwrite all options", () => {
const tsConfigPath = resolve(__dirname, "../../example/extend-node-module/tsconfig.json")

const result = getTsconfig(tsConfigPath);

expect(result).toEqual({
config: {
compilerOptions: {
baseUrl: "./kalle",
paths: { foo: ["bar2"] },
strict: true,
}
},
path: tsConfigPath
});
});
});
1 change: 0 additions & 1 deletion src/tsconfig-loader.ts
Expand Up @@ -64,7 +64,6 @@ function loadSyncDefault(

return {
tsConfigPath: configPath,
...tsconfig?.config.compilerOptions,
baseUrl: baseUrl || tsconfig?.config.compilerOptions?.baseUrl,
paths: tsconfig?.config.compilerOptions?.paths ?? {},
};
Expand Down

0 comments on commit ec0cda5

Please sign in to comment.