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

Ava watch does not work with pre-compile option #33

Open
StarpTech opened this issue May 9, 2021 · 14 comments
Open

Ava watch does not work with pre-compile option #33

StarpTech opened this issue May 9, 2021 · 14 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@StarpTech
Copy link

StarpTech commented May 9, 2021

Please provide details about:

  • What you're trying to do

Ava watch mode with this package.

{
  "ava": {
    "files": [
      "src/**/*.test.ts"
    ],
    "typescript": {
      "rewritePaths": {
        "src/": "build/"
      },
      "compile": "tsc"
    }
  }
}
  • What happened

ava --watch

If I change a source file or test file the runner is not restarted. If I do the same with ts-node/register it works.

  • What you expected to happen

Ava runner should rerun on file change.

ava: 3.15.0

@novemberborn
Copy link
Member

Could you run AVA with DEBUG=ava:watcher npx ava --watch? That should print out any files that AVA detects as having changed, and what it decided to do in response.

@StarpTech
Copy link
Author

StarpTech commented May 9, 2021

ava:watcher Detected change of src/registry/federation/deactivate-schema.test.ts +0ms
ava:watcher Ignoring changed file /home/starptech/repositories/starptech/graphql-registry/src/registry/federation/deactivate-schema.test.ts +101ms

The test isn't rerun.

@novemberborn
Copy link
Member

I don't think I've noticed this before myself. Does it work when you rewrite from src/ to build/?

This line looks suspect:

return rewritePaths.some(([from]) => filePath.startsWith(from));

The log output gives an absolute path, but that logic assumes a relative path.

If we can figure out what configuration does work then we can make sure alternative configurations also work, or fail to run the tests with a useful error, instead of having the watcher not working.

@StarpTech
Copy link
Author

Does it work when you rewrite from src/ to build/?

no, same result.

@novemberborn
Copy link
Member

Bummer!

This sounds like a bug, though I haven't encountered it myself. If you could share a reproduction that would make it easier to debug.

@novemberborn novemberborn added bug Something isn't working help wanted Extra attention is needed labels May 14, 2021
@StarpTech
Copy link
Author

The repository is public https://github.com/StarpTech/graphql-registry. Just run npm run test:watch.

@StarpTech
Copy link
Author

StarpTech commented May 14, 2021

I think I found the bug. As you already mentioned the conditions in

return rewritePaths.some(([from]) => filePath.startsWith(from));
looks odd. The results must be reversed.

	return !rewritePaths.find(([from]) => filePath.startsWith(from));

After that the test is rerun but then I run into

  ava:watcher /home/starptech/repositories/starptech/graphql-registry/build/registry/maintanance/garbage-collect.test.js is a dependency of /home/starptech/repositories/starptech/graphql-registry/src/registry/maintanance/garbage-collect.test.ts +2s
  ava:watcher Files remain that cannot be traced to specific tests: [
  ava:watcher   '/home/starptech/repositories/starptech/graphql-registry/build/registry/maintanance/garbage-collect.test.js',
  ava:watcher   '/home/starptech/repositories/starptech/graphql-registry/build/tsconfig.tsbuildinfo'
  ava:watcher ] +0ms
  ava:watcher Rerunning all tests +0ms

@StarpTech
Copy link
Author

Friendly ping @novemberborn. Any idea? I'd work on it.

@novemberborn
Copy link
Member

Hi @StarpTech sorry for the delay. I think that function is supposed to detect and ignore changes to files in the src/ directory. The problem may be in the filePath.startsWith(from) call. We shouldn't have to negate the outcome of the .some().

@StarpTech
Copy link
Author

I'd be grateful for any help.

@novemberborn
Copy link
Member

Would be good to log the values passed to ignoreChange(), as well as the rewritePaths, to see what stands out. I don't think the answer is the snipped you shared above.

@alebianco
Copy link

I bumped into the same issue and I mostly agree with @StarpTech on the cause

when the compilation step is enabled, you want to monitor changes on the .ts files and to do so, the current check on the rewritePaths must be reversed. You want to trigger on changes in the "from" paths and ignore changes in the "to" paths.

on the other hand, if the compilation is done externally, you don't want to trigger the test then the .ts file change, because the compiled output probably isn't ready yet. In this case the current check on the rewritePaths is correct: it ignores the "from" paths and trigger for changes in the "to" path.

Also, the current behaviour does not match with what's described in the main README file.

@novemberborn
Copy link
Member

Thanks for the clarification @alebianco. Would appreciate some PRs to fix.

alebianco pushed a commit to alebianco/avajs-typescript that referenced this issue Nov 19, 2021
alebianco added a commit to alebianco/avajs-typescript that referenced this issue Nov 19, 2021
alebianco added a commit to alebianco/avajs-typescript that referenced this issue Nov 19, 2021
@alebianco
Copy link

@novemberborn let me know if I have to do something about those pending checks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants