Description
I'm kinda confused how I'm supposed to properly use this package alongside baseUrl
, I think I'm holding it wrong lol.
So I upgraded AVA to ava@next
(4.0.0-rc.1
) and installed the latest @ava/typescript
(3.0.1
). My project uses TypeScript Project References, and dumps files into a .build-tsc/
directory, so I set compile: false
, and edited my test script to compile before running ava
.
Project has a src/
directory at the root containing code, and a tests/
directory containing a mix of tests (file extension *.test.tsx?
) and utilities for tests (just ending in .ts
). I set baseUrl
in my tsconfig
to the package root, and before trying @ava/typescript
, I was just setting NODE_PATH
to .build-tsc
so that Node could find all the proper files.
That's fine, but the main downsides are A) all the errors are in the compiled JS instead of the TS, making it harder to understand where the errors come from; and B) pretty sure it just doesn't work with JSX at the moment (but that's less pressing since I'm mostly testing backend business logic).
So trying out @ava/typescript
, I set my config as follows:
// package.json
"scripts": {
"test": "tsc --build tests && ava",
// ...
},
"ava": {
"typescript": {
"rewritePaths": {
"src/": ".build-tsc/src/",
"tests/": ".build-tsc/tests/"
},
"compile": false,
"extensions": ["ts", "tsx"]
},
"files": [
"./tests/**/*.test.ts?(x)"
]
}
This evidently is not correct, as I get errors like the following whenever a test tries to import anything in src
:
Uncaught exception in tests/utility/markup-description.test.ts
Error: Cannot find module 'src/utility/array'
Require stack:
- /Users/omar/code/spinach/web-app/.build-tsc/tests/utility/markup-description.test.js
- /Users/omar/code/spinach/web-app/node_modules/ava/lib/worker/base.js
And then if I set NODE_PATH
again to .build-tsc
, then it works, but once again it's no different in that error line numbers are in the original JS files, not the TS ones.
So yeah I'm not totally sure how to A) make TypeScript baseUrl
(and relatedly paths
which I'm not using right now) work, and B) how I should be doing things to get the line numbers to be those of the TypeScript files. I think some more detailed examples/documentation for these kinds of use cases, or at least a disclaimer that this isn't supported, would be helpful for me!