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

Surprising rewritePaths needed #27

Closed
dsernst opened this issue Jun 19, 2020 · 1 comment
Closed

Surprising rewritePaths needed #27

dsernst opened this issue Jun 19, 2020 · 1 comment

Comments

@dsernst
Copy link

dsernst commented Jun 19, 2020

My source files are organized like this:

./src/
    example.ts
    second-example.ts
    tests/
      test-example.ts
      test-second-example.ts

My tsconfig.json looks like this:

{
  "compilerOptions": {
    "outDir": "./build",
    "allowJs": true,
    "target": "es5"
  },
  "include": ["./src/**/*"]
}

Which results in output like this

./build/
    src/
      example.js
      second-example.js
      tests/
        test-example.js
        test-second-example.js

I installed @ava/typescript and added rewritePaths to package.json as instructed in this library's readme, like this:

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

But then running ava or npx ava src/tests/test-example.ts or other variations kept resulting in fatal errors like:

Uncaught exception in src/tests/test-example.ts

Error: Cannot find module '/Users/dsernst/Documents/myproject/build/tests/test-example.js'

It took me a while to figure out what was going on.

Note that it's missing the /src/ directory between /build/ and /tests/.

So after much tweaking, I was finally able to get it working with:

  "rewritePaths": {
    "src/": "build/src/"
  }

Maybe this is obvious, and I was just being stupid, but I'm putting this up here in part to help anyone else that comes across a similar issue.

version info:

@ava/typescript: 1.1.1
ava: 3.9.0
typescript: 3.9.5

node v12.16.3

@dsernst dsernst closed this as completed Jun 19, 2020
@novemberborn
Copy link
Member

Sorry you got bit by this. The third paragraph of the readme explains build/, but maybe that's too far away from the sample configuration?

In other words, say you have a test file at src/test.ts. You've configured TypeScript to output to build/. Using @ava/typescript you can run the build/test.js file using npx ava src/test.ts. AVA won't pick up any of the JavaScript files present in the build/ directory, unless they have a TypeScript counterpart in src/.

(Emphasis mine)

#2 is open so that hopefully maybe we can determine this automatically.

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

No branches or pull requests

2 participants