Alias paths on integration tests (#3196)

* Run pretest in CI to build all tests

* Alias paths when running tests
This commit is contained in:
Tomás Barreiro 2025-05-01 02:49:40 +02:00 committed by GitHub
parent 1704684af8
commit d162a4b420
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View File

@ -6,6 +6,10 @@ export default defineConfig({
mocha: {
ui: "bdd",
timeout: 20000, // Maximum time (in ms) that a test can run before failing
/** Set up alias path resolution during tests
* @See {@link file://./test-setup.js}
*/
require: ["./test-setup.js"],
},
workspaceFolder: "test-workspace",
version: "stable",

22
test-setup.js Normal file
View File

@ -0,0 +1,22 @@
const tsConfigPaths = require("tsconfig-paths")
const fs = require("fs")
const tsConfig = JSON.parse(fs.readFileSync("./tsconfig.json", "utf-8"))
/**
* The aliases point towards the `src` directory.
* However, `tsc` doesn't compile paths by itself
* (https://www.typescriptlang.org/docs/handbook/modules/reference.html#paths-does-not-affect-emit)
* So we need to use tsconfig-paths to resolve the aliases when running tests,
* but pointing to `out` instead.
*/
const outPaths = {}
Object.keys(tsConfig.compilerOptions.paths).forEach((key) => {
const value = tsConfig.compilerOptions.paths[key]
outPaths[key] = value.map((path) => path.replace("src", "out"))
})
tsConfigPaths.register({
baseUrl: ".",
paths: outPaths,
})