avajs / typescript

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

rewritePaths is less restrictive than expected #14

Closed bitjson closed 4 years ago

bitjson commented 4 years ago

Thank you for this project! I migrated bitcoin-ts recently, and I just wanted to note an issue I had.

My Typescript project builds the same source to two different output locations, one build/main/ for Node.js usage and one build/module/ for consumers which use build tools like Rollup.

I primarily test against the build/main/ build, so the configuration seemed simple:

  "ava": {
    "typescript": {
      "rewritePaths": {
        "src/": "build/main/"
      }
    }
  }

But with that configuration, AVA was also trying to test files in the build/module/ folder. I ended up needing to add an exclusion:

  "ava": {
    "typescript": {
      "rewritePaths": {
        "src/": "build/main/"
      }
    },
    "files": [
      "!build/module/**"
    ]
  }

This works well now, so I'm happy to leave it as-is. I just wanted to mention that it differed from my initial impression of how rewritePaths would work. I thought setting src/ to build/main/ would map files in those directories one-to-one, but AVA seems to also be searching in build/module/ without the specific exclusion.

(Thanks again for v3 of AVA and the improved Typescript integration! Even debugging is working beautifully now.)

novemberborn commented 4 years ago

This works well now, so I'm happy to leave it as-is. I just wanted to mention that it differed from my initial impression of how rewritePaths would work. I thought setting src/ to build/main/ would map files in those directories one-to-one, but AVA seems to also be searching in build/module/ without the specific exclusion.

AVA still searches the entire project for *.js, *.cjs, *.mjs and *.ts files. The TypeScript integration is now smart enough to tell AVA to ignore build/main/, but it doesn't know about build/module/.

Would documentation help here? Looks like you figured out AVA's behavior pretty quick?

(Thanks again for v3 of AVA and the improved Typescript integration! Even debugging is working beautifully now.)

😍

(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)

bitjson commented 4 years ago

AVA still searches the entire project for *.js, *.cjs, *.mjs and *.ts files. The TypeScript integration is now smart enough to tell AVA to ignore build/main/, but it doesn't know about build/module/.

Ah, that makes much more sense. I only figured out I needed to ignore the contents of build/module when I added some console.logs to AVA in node_modules. 😅

Would documentation help here? Looks like you figured out AVA's behavior pretty quick?

Ya, I think an explanation of rewritePaths in the readme would be helpful. It took me a while to look in the right places, and even then, I went away thinking it was a bug.

novemberborn commented 4 years ago

Fair enough.

Let's add something like this to the rewritePaths section in the README:

AVA searches your entire project for *.js, *.cjs, *.mjs and *.ts files (or other extensions you've configured). It will ignore such files found in the rewritePaths targets (e.g. build/). If you use more specific paths, for instance build/main/, you may need to change AVA's files configuration to ignore other directories.

What do you think?

bitjson commented 4 years ago

That’s perfect 👍