-
Notifications
You must be signed in to change notification settings - Fork 250
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
support ES6 modules (and support custom compilers/parsers e.g. babel/espree) #133
Comments
Hey Will, Thank you very much for the extensive description of your issue! As you have noticed, compilers are not supported in Stryker right now but we may have to do something about that in the future because I expect that you won't be the last person who wants support for a language feature we don't support by default. As of right now I have a few questions:
|
Thanks a lot for this wealth of information! I've been thinking of supporting transpilers for a while now. As you can see, Stryker uses TypeScript, so it would be awesome to support this (and all transpilers) more natively. To expand on @simondel 's comments:
I think we might have an other option here. We could leave the transpiling/compiling up to your build system of choice. We would instead support
Yes it is and you can have a crack at it :)
|
Any progress on this one? The config option for esPrima sounds like a quick win. Shall I do that? |
@jeznag give it a shot 👍 |
👍 would love this functionality. using create-react-app with jest built in. would love to use this out of the box by adding a simple .conf.js and running stryker. (no preference on compiled code or not for a v1) |
I am extra excited to see this working in a babel/webpack pipeline. I am using es6 and react plugins in babel and have no luck getting version 0.6.0 working with the mutations turned on. It does run the dry-tests successfully... I recognize that there is significant challenges to fully parsing and mutating the raw source code no matter what stage-? features the user is adding into their babel plugins. It would be great if this plugin didn't care at all and just registered to the output of babel and mutated the compiled code with coverage to help guide it (is that a thing?). You have your work cut out for you and I if this feature is successful, it will be the standard include in every client project I do. Keep up the good work! |
Is there any progress on this? My use case is basically |
@FezVrasta do you mean an app created using Webpack support will probably be a lot harder as you will have to bundle the files before testing and support a lot of different webpack configurations. This will probably require us to alter the process of Stryker. So this will take some more time unfortunately. |
Yes I mean an app created with create-react-app (and later, ejected actually). I would need support for es2015, stage2, flow and react presets. Why would someone need webpack support? The tests aren't usually ran with webpack, but with Jest or Karma or similar. |
@FezVrasta It's pretty common to have webpack handle the dependency loading and in your karma configuration. @simondel Hard news to swallow. I was really looking forward to adding stryker into my webpack/babel/karma stack. It sounds like there will be some basic lifecycle problems to solve to support the modern javascript stack. Potentially a webpack plugin or module of some type to couple stryker mutation in with the compilation process. However, if Styker doesn't really care what karma does to execute it's tests and if stryker can handle the source code in it's un-babeled form and feed those results back through whatever karma/webpack/babel pipeline is in place and report the results of the tests back to stryker, then we may be in business anyway. Perhaps a hook to supply Stryker's babel configuration additional options? |
- Typescript is not currently supported - Open PRs in the project indicate that it may be supported soon: stryker-mutator/stryker-js#133 stryker-mutator/stryker-js#258
With |
Firstly - I love this project! This is going to be hugely useful.
The problem:
Esprima will reject 'import' statements if the sourceType is not explicitly set to 'module':
from https://github.com/jquery/esprima/blob/master/src/parser.ts#L1643
This requires Stryker to provide it with
sourceType: 'module'
as seen here:from https://github.com/stryker-mutator/stryker/blob/master/src/utils/parserUtils.ts#L9
Prototype pull req to illustrate:
#136
Unfortunately, currently there's no way to tell Stryker this is what you want.
This is the code I am testing:
with this test:
and Stryker cleverly realises that
However there's more - because I'm using ES6 module syntax in my actual mocha tests too, I need to use
babel-core/register
and some transforms to compile them as they'rerequire
d. This works totally fine with Stryker too - I just make the first file it looks at one withbabel-core/register
, where I have one or two babel plugins beavering away magically transpiling stuff.This should be the end of it - but I'm also a big fan of the new object rest spread syntax:
https://github.com/sebmarkbage/ecmascript-rest-spread
(https://babeljs.io/docs/plugins/syntax-object-rest-spread/)
I want to use it in the code I'm mutating (not just the tests) in this contrived example:
so I modify my babel-core register hook to use the transform:
But it doesn't work - because Stryker loads the files it is going to mutate into Esprima, it doesn't require them directly so Babel can't transpile it.
To fix this, I need to go into:
https://github.com/stryker-mutator/stryker/blob/master/src/MutatorOrchestrator.ts#L45
and add babel to transform the file:
(I tried doing this later (just before Esprima parses it) but it caused weird issues where Stryker wouldn't generate any mutations, or claim that all mutations passed - I think probably because it meant
reportFileRead
and other functions had differing opinions about the state of the source code.)We need both these transforms because with just the first, it adds a lot of extra code into the file which gets Stryker over excited:
and it generates over 14 mutants, all mostly meaningless variations on Babel's polyfill.
"transform-runtime" extracts the polyfill out into a separate file so Stryker only sees a single function call and isn't tempted to mutate anything.
With Babel:
That's more like it!
Prototype pull req to illustrate: #134
There is an alternative to using Babel, which is to use Espree instead of Esprima:
https://github.com/eslint/espree
Espree is based on Esprima but has support for more experimental features (among them object rest spread).
It was a pretty simple swap - in https://github.com/stryker-mutator/stryker/blob/master/src/utils/parserUtils.ts#L30
I just swap out
esprima
forespree
and addas an option and it just works.
With Espree:
Prototype pull req to illustrate: #135
As you can see, Espree is not transforming the code, just correctly parsing it, so the mutation snippet is a bit truer to life.
Babel is a lot more powerful in the sense that you can transform pretty much anything you like into anything else, but you'd need Stryker to understand sourcemaps in order to provide perfect feedback, and you'd need to make sure any Babel transform left only the minimum amount of 'mutative noise' left over (or otherwise wrap any mutative noise in comments that Stryker could ignore - sounds messy).
So there are several options here - hacking it in like in my pull reqs is not ideal, so perhaps there needs to be a way to expose a callback to the config whenever a file is read or parsed so, at the very least, people can provide their own compilers.
Alternatively or alongside which, should it be possible to provide compilers as Stryker plugins?
What do you guys think? Is this kind of configurability on the roadmap, and if so do you mind if I take a crack at it?
Apologies - I didn't use the correct commit style (https://github.com/stryker-mutator/stryker/blob/master/CONTRIBUTING.md) on the pull reqs - they're just prototypes to illustrate the issue, I don't expect they'll be merged!
Thanks,
Will
The text was updated successfully, but these errors were encountered: