File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff 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" ,
Original file line number Diff line number Diff line change 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+ } )
You can’t perform that action at this time.
0 commit comments