avajs / ava

Node.js test runner that lets you develop with confidence 🚀

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transpile source files in the main process

novemberborn opened this issue · comments

To improve startup time (#78) we could provide a framework where source files are optimistically transpiled and cached in the main process. No require hooks would be required in the test files avoiding the Babel startup penalty. Thanks @tomazzaman for the suggestion.

  • --require hooks won't do, we should support plugins and wrap them like how caching-precompiler wraps Babel
  • The watcher needs to recompile changed source files before tests are rerun
  • The test worker won't know which cache misses should have been precompiled, so tests may blow up. This would probably be due to insufficient --source patterns so would require useful error messaging somehow

Am I confused or we already do this via #390?

#390 transpiles tests files. This is suggesting infrastructure to transpile source files in the main process as well.

Yeah, but we don't transpile source files at all now. So we may start with that.

Yes, that's the point of this issue. We'd have to use the approach from caching-precompiler to get the compiled sources into the child processes, and we have to use glob patterns to match all potential sources before tests run so they're available synchronously.

we have to use glob patterns to match all potential sources ...

Or use babel-detective which is probably more performant (the AST is being scanned already, so it should be faster than a regexp). I created it with this idea in mind.

Either way this won't do much good for dynamic requires. I did experiment with this, which could be used as a fallback for dynamic require calls.

I think a first step should be supporting transpilation of helper files (files in the test directory prefixed with _, or in test/helpers). Sources would get a different Babel transform without power-assert, so helpers seems like an easier place to start.

For "non-Babel" transpilers (typescript, etc), we would have to create a plugin ecosystem. We would still need to finish up with Babel for powerAssert support.

Conceivably, users may want to chain custom transforms.

See transform-chain. It could help with all this.

This will be tackled through RFC 001. See the project here: https://github.com/avajs/ava/projects/1.

@novemberborn link is dead so I'm not sure where to look

Yea, I pulled the RFC recently. #1908 is probably the best issue to track for now.