avajs / typescript

Test TypeScript projects using AVA.
MIT License
73 stars 16 forks source link

Perform compilation #3

Closed novemberborn closed 3 years ago

novemberborn commented 4 years ago

It should be possible to compile the TypeScript project before tests are run.

We should be able to control TypeScript programmatically. There is a feature to cache some of the compilation work, for faster subsequent compilation runs. We should use this.

As alluded to in #2 we should probably only support configuration files in the project directory itself (next to package.json files).

I'm not sure where to write the output files. Perhaps just follow the TypeScript configuration. With #2 done that makes it easiest to subsequently load the test files.

I'm not sure how to handle compilation errors. We could just write the files and run the tests. We could also explore an integration with AVA to surface errors better.

This should work automatically with AVA's watch mode, since AVA invokes compilation before every test run.

cinderblock commented 4 years ago

How does this work with various rootDirs?

For instance, I usually use two tsconfig.conf files. The first is at the root (next to package.json) and that is for my src sources. It sets rootDir: 'src' since I want my output dist folder to not have the extra src directory in the path. This causes problems with test files in a different root dir. Therefore I use a second tsconfig.json to extend the first and give a rootDir (for testing) that includes both src and tests dir. This also enables using certain TypeScript features that I might only want in the testing environment.

novemberborn commented 4 years ago

@szmarczak is working on an implementation in https://github.com/avajs/typescript/pull/12. Right now that assumes a single tsconfig.json file in the root.

I'm inclined to ship that, and then think about supporting your use case. Though in the meanwhile ideas are most welcome.

novemberborn commented 4 years ago

Right now that assumes a single tsconfig.json file in the root.

Come to think of it, we can just invoke tsc and it should work fine.

fregante commented 4 years ago

Couldn't this be handled by @ava/babel with a TypeScript plugin?

novemberborn commented 4 years ago

Couldn't this be handled by @ava/babel with a TypeScript plugin?

Sure, though if I understand correctly that strips types, and there are some constructs like const enum that don't work. But if it works for you then that's great.