Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

So -- like -- where do I put my test files as .ts? #2460

Closed
SephReed opened this issue Apr 18, 2020 · 11 comments
Closed

So -- like -- where do I put my test files as .ts? #2460

SephReed opened this issue Apr 18, 2020 · 11 comments

Comments

@SephReed
Copy link
Contributor

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 with ava. 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.

@SephReed
Copy link
Contributor Author

Found this: https://github.com/avajs/ava/blob/master/docs/recipes/typescript.md

Where do the files go and how do they run?

@SephReed
Copy link
Contributor Author

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.

@SephReed
Copy link
Contributor Author

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?

@SephReed
Copy link
Contributor Author

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.

@SephReed
Copy link
Contributor Author

I tried a bunch more stuff but finally got it. Holy fuck you guys, it's like two lines of instructions:

  1. run this npm i ts-node --save-dev

  2. 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.

@novemberborn
Copy link
Member

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.

@SephReed
Copy link
Contributor Author

@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.

@novemberborn
Copy link
Member

I use a typescript bundler, which skips the .js file output stage entirely.

Could you elaborate on that?

@SephReed
Copy link
Contributor Author

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

@novemberborn
Copy link
Member

Does your bundle include the tests? Presumably it includes everything else, right? So then in your tests you'd import the bundle?

@SephReed
Copy link
Contributor Author

SephReed commented May 5, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants