Skip to content

Commit d162a4b

Browse files
authored
Alias paths on integration tests (RooCodeInc#3196)
* Run pretest in CI to build all tests * Alias paths when running tests
1 parent 1704684 commit d162a4b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

.vscode-test.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export default defineConfig({
66
mocha: {
77
ui: "bdd",
88
timeout: 20000, // Maximum time (in ms) that a test can run before failing
9+
/** Set up alias path resolution during tests
10+
* @See {@link file://./test-setup.js}
11+
*/
12+
require: ["./test-setup.js"],
913
},
1014
workspaceFolder: "test-workspace",
1115
version: "stable",

test-setup.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const tsConfigPaths = require("tsconfig-paths")
2+
const fs = require("fs")
3+
4+
const tsConfig = JSON.parse(fs.readFileSync("./tsconfig.json", "utf-8"))
5+
6+
/**
7+
* The aliases point towards the `src` directory.
8+
* However, `tsc` doesn't compile paths by itself
9+
* (https://www.typescriptlang.org/docs/handbook/modules/reference.html#paths-does-not-affect-emit)
10+
* So we need to use tsconfig-paths to resolve the aliases when running tests,
11+
* but pointing to `out` instead.
12+
*/
13+
const outPaths = {}
14+
Object.keys(tsConfig.compilerOptions.paths).forEach((key) => {
15+
const value = tsConfig.compilerOptions.paths[key]
16+
outPaths[key] = value.map((path) => path.replace("src", "out"))
17+
})
18+
19+
tsConfigPaths.register({
20+
baseUrl: ".",
21+
paths: outPaths,
22+
})

0 commit comments

Comments
 (0)