-
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
Stryker v4 Instrumentor breaks enzyme snapshots #2362
Comments
Hi @Garethp thanks a lot for opening this issue. Are you still planning to add a e2e test with enzyme snapshots? It's optional of course, but it would help us a lot with solving this issue. It's also fine if you just add the files a new |
Yes I am, I just didn't find the time this weekend. I should have a PR in the next day or so |
The problem is a little bit more broad even, as you can see here:
|
I've been thinking about this and I think I know of a solution that works for most use cases. I want to instrument these: const foo = function () { }
const bar = () => {}
const Baz = class { } Like this: const foo = true? function foo () { }: ...;
const bar = true? (() => { const bar = () =>{}; return bar } {})() : ...;
const Baz = true? class Baz { } : ...; What do you think of this? I don't like your approach @Garethp, because it changes the functionality of the code too much and will be difficult to maintain. |
That looks like it works quite well. I'll test it on my work project when it's been pushed up |
Do a best-effort attempt to minimize side effects from instrumentation by maintaining the `fn.name` property when placing mutants in code. Instrument these: ```ts const foo = function () { } const bar = () => {} const Baz = class { } const foo = { bar: function () { } } ``` Like this: ```ts const foo = true? function foo () { }: ...; const bar = true? (() => { const bar = () =>{}; return bar } {})() : ...; const Baz = true? class Baz { } : ...; const foo = true? function bar() {} ``` Fixes #2362
I've just released |
This is strange, but there are some cases where you might not want to be doing this? Take the following case: export const SomeItem = () => <div></div>; For some reason in non-mutated code this gets exported without a name. In the mutated code it now does have a name? I didn't even notice this before. Also, it looks like there's a bug where having a string that starts with |
Summary
When using Stryker v4, my snapshots (using enzyme) break because where in the main run it recognizes the component name, in the mutant run it just calls it
Component
.Example:
In the main run it will return the snapshot
While in the mutant it'll render
The difference being that
ErrorMessage
has been replaced withComponent
. This is because the instrumentor replaced the main definition ofErrorMessage
with a ternary, and it appears that enzyme (or react, not sure) is looking for the variable name of the original variable that the component is assigned to.If you replaced ErrorMessage with
Then the snapshot would also fail in the same way it does during mutation tests.
One possible fix is to temporarily assign the component to a variable with the original name inside the ternary. That way the component maintains its original variable name. Here's an example below:
The text was updated successfully, but these errors were encountered: