Closed SephReed closed 4 years ago
Found this: https://github.com/avajs/ava/blob/master/docs/recipes/typescript.md
Where do the files go and how do they run?
Found this: https://github.com/avajs/typescript
I don't get it. I need to update package.json? If I'm not installing anything, couldn't ava just figure out that the files end in .ts
and pretend package.json said some stuff? I like this project. Hope this gets fixed eventually.
What is this:
"rewritePaths": {
"src/": "build/"
}
why would I rewrite a path. Everything is where it's supposed to be. I'm not trying to hack something together here. Is this the default?
I found this code in one of my old projects:
"ava": {
"compileEnhancements": false,
"extensions": [
"ts"
],
"require": [
"./src/testing/setupBrowser.js",
"ts-node/register"
]
}
It's totally different than what I'm finding in your docs but at least looks reasonable.
I tried a bunch more stuff but finally got it. Holy fuck you guys, it's like two lines of instructions:
run this npm i ts-node --save-dev
add this to your package.json
{
"ava": {
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
}
}
I don't know if this is a bug or feature request issue, but could you add these instructions to your docs WAY UP at the top. It's insane how difficult this is for being --- for better or worse -- an industry standard.
Sorry for being impatient.
There's no special place where you need to place your files.
@ava/typescript
, at this stage, assumes you compile your codebase first. You then give it a test file in its original location (eg src/test/thing.ts
) and it'll load the build output (given the rewrite path, so perhaps build/test/thing.js
).
ts-node/register
can be quite slow since it might compile all files over and over again for each test file you have, since AVA uses a new worker process for each test file.
@ava/typescript, at this stage, assumes you compile your codebase first
Ah, that makes a lot of sense.
I use a typescript bundler, which skips the .js file output stage entirely.
I use a typescript bundler, which skips the .js file output stage entirely.
Could you elaborate on that?
This is the bundler: https://github.com/fuse-box/fuse-box
One can direct it at a root file and it will proceed to compile it and all of its dependencies into a single .js file. It also does fancy stuff like tree shaking unneeded code.
So it does output a .js file, but not the way that tsc
would. I don't have a /dist
folder with *.js
files that map to *.ts
files in /src
Does your bundle include the tests? Presumably it includes everything else, right? So then in your tests you'd import the bundle?
My bundle does not include the tests, and I'd never thought of running the tests using the bundle as the source. I prefer to use .ts files for everything I can as they're much more inspectable. It's nice to be able to meta-click and see the source code of any given thing.
When using AVA, I currently just do it the slow way above. It's still plenty fast, so that's good.
Ever heard of the drunk test? It's a UX thing where you see if a person can figure it out when drunk: Facebook passes... so does Paypal.
I can't figure out how to make my
/__tests/tets.ts
file to run withava
. I think maybe I'm supposed to do something extra for ava to work with .ts files... it's been a month or two. This probably should be on the landing page. I don't know many professionals who don't use typescript, to be frank.Cheers.