Skip to content

Commit 5c9151b

Browse files
committed
Make it impossible to import test files in src
1 parent cb19660 commit 5c9151b

File tree

7 files changed

+36
-16
lines changed

7 files changed

+36
-16
lines changed

.eslintrc.json

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"parserOptions": {
55
"ecmaVersion": 6,
66
"sourceType": "module",
7-
"project": "./tsconfig.json"
7+
"project": true
88
},
99
"plugins": ["@typescript-eslint", "prettier", "import"],
1010
"extends": [
@@ -15,7 +15,25 @@
1515
"plugin:md/prettier",
1616
"prettier"
1717
],
18+
"ignorePatterns": ["out", "dist", "**/*.d.ts"],
19+
"settings": {
20+
"import/resolver": {
21+
"typescript": { "project": "./tsconfig.json" }
22+
},
23+
"import/internal-regex": "^@/"
24+
},
1825
"overrides": [
26+
{
27+
"files": ["test/**/*.{ts,tsx}", "**/*.{test,spec}.ts?(x)"],
28+
"settings": {
29+
"import/resolver": {
30+
"typescript": {
31+
// In tests, resolve using the test tsconfig (has @test/* mapping)
32+
"project": "test/tsconfig.json"
33+
}
34+
}
35+
}
36+
},
1937
{
2038
"files": ["*.ts"],
2139
"rules": {
@@ -88,12 +106,5 @@
88106
}
89107
}
90108
]
91-
},
92-
"ignorePatterns": ["out", "dist", "**/*.d.ts"],
93-
"settings": {
94-
"import/resolver": {
95-
"typescript": { "project": "./tsconfig.json" }
96-
},
97-
"import/internal-regex": "^@/"
98109
}
99110
}

test/tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"baseUrl": "..",
5+
"paths": {
6+
"@/*": ["src/*"],
7+
"@test/*": ["test/*"]
8+
}
9+
},
10+
"include": ["**/*", "../src/**/*"]
11+
}

test/unit/cliManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
MockConfigurationProvider,
2020
MockProgressReporter,
2121
MockUserInteraction,
22-
} from "@tests/mocks/testHelpers";
22+
} from "@test/mocks/testHelpers";
2323

2424
vi.mock("os");
2525
vi.mock("axios");

test/unit/mementoManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it } from "vitest";
22

33
import { MementoManager } from "@/core/mementoManager";
44

5-
import { InMemoryMemento } from "@tests/mocks/testHelpers";
5+
import { InMemoryMemento } from "@test/mocks/testHelpers";
66

77
describe("MementoManager", () => {
88
let memento: InMemoryMemento;

test/unit/secretsManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it } from "vitest";
22

33
import { SecretsManager } from "@/core/secretsManager";
44

5-
import { InMemorySecretStorage } from "@tests/mocks/testHelpers";
5+
import { InMemorySecretStorage } from "@test/mocks/testHelpers";
66

77
describe("SecretsManager", () => {
88
let secretStorage: InMemorySecretStorage;

tsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
// conflicting types. For some reason TypeScript is reading both and
1818
// throwing errors about AxiosInstance not being compatible with
1919
// AxiosInstance. This ensures we use only index.d.ts.
20-
"axios": ["./node_modules/axios/index.d.ts"],
21-
"@/*": ["src/*"],
22-
"@tests/*": ["test/*"]
20+
"axios": ["./node_modules/axios/index.d.ts"]
2321
}
2422
},
2523
"exclude": ["node_modules"],
26-
"include": ["src/**/*", "test/**/*"]
24+
"include": ["src"]
2725
}

vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default defineConfig({
2121
resolve: {
2222
alias: {
2323
"@": path.resolve(__dirname, "src"),
24-
"@tests": path.resolve(__dirname, "test"),
24+
"@test": path.resolve(__dirname, "test"),
2525
vscode: path.resolve(__dirname, "test/mocks/vscode.runtime.ts"),
2626
},
2727
},

0 commit comments

Comments
 (0)