Skip to content

Allow mutating of es decorators with mutation switching #2415

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

Closed
nicojs opened this issue Aug 24, 2020 · 5 comments
Closed

Allow mutating of es decorators with mutation switching #2415

nicojs opened this issue Aug 24, 2020 · 5 comments
Labels
🚀 Feature request New feature request ☠ stale Marked as stale by the stale bot, will be removed after a certain time.

Comments

@nicojs
Copy link
Member

nicojs commented Aug 24, 2020

Is your feature request related to a problem? Please describe.

Currently, in Stryker 4 beta (3), we're not mutating decorators.

https://github.com/stryker-mutator/stryker/blob/cd439522650fe59c1607d00d58d331b5dc45fe39/packages/instrumenter/src/transformers/babel-transformer.ts#L19

The reason for this, is that angular projects can't handle mutating in their decorators with mutation switches in them.

For example:

// @ts-nocheck
import { Component } from '@angular/core';

@Component({
  selector: global.test === 3 ? 'app-root' : '',
  styleUrls: global.test === 4 ? ['./app.component.css'] : [],
  templateUrl:global.test === 5 ? './app.component.html' : ''
})
export class AppComponent {
  public title = 'angular' + '-project';
}

Running ng test results in failed tests:

Chrome 84.0.4147 (Windows 10.0.0) AppComponent should render title in a h1 tag FAILED
        Failed: Cannot read property 'textContent' of null
            at <Jasmine>
            at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/src/app/app.component.spec.ts:25:40)

This happens (I think) because angular uses it's own (pre) compiler (Ivy). This compiler uses the decorators in a precompile step. They need to have constant values.

I don't like the fact that we're ignoring all decorators because of a problem in angular projects.

Describe the solution you'd like

I think we should make the skipping of decorators optional. For example:

{
  "mutator": {
    "ignoreNodes": [
      "decorator" // node name
    ]
  }
}

I think the default for ignoreNodes should be [] (no nodes should be ignored).

When someone uses stryker init and chooses angular, we should make sure to add decorator to the ignore nodes.

Describe alternatives you've considered

  • We could keep it like it is now (always skip decorators), but I don't like the fact we're not mutating decorators because of one setup that isn't working.
  • We could also implement Ignore specific mutations #1472, but that would mean that everyone should ignore decorators with a comment stryker ignore next. That's a lot of work.
@nicojs nicojs added the 🚀 Feature request New feature request label Aug 24, 2020
@nicojs nicojs added this to the 4.0 milestone Aug 24, 2020
@nicojs nicojs changed the title Allow mutating of decorators with mutation switching Allow mutating of es decorators with mutation switching Aug 25, 2020
@nicojs
Copy link
Member Author

nicojs commented Sep 18, 2020

Maybe it's better to allow for a custom ignore plugin syntax. This way we can support other use cases as well, instead of making an exception for checking on node type. Related use cases are specified in these issues: #2400 , #2257

It might look like this:

{
  "mutator": {
    "ignorePlugins": [
      "angularDecorators" // ignore plugin name here
    ]
  }
}

We can start with a private mutant ignore plugin api and make it public if it turns out this is a much requested feature. The "angularDecorators" plugin would ignore angular decorators.

We should add the Ignored state to the list of states a mutant can have. That way, we will still generate the mutants, but give them the Ignored state and not place them in the code (this last part is important). I'm also convinced that ignored mutants should ALWAYS have a reason message. In this case it could be "Mutating angular decorators is not supported in Stryker".

We could choose to fix this after the 4.0 milestone if we really wanted to and later have a small (breaking for angular users) change to fix this.

@simondel @hugo-vrijswijk and others. what do you think of this approach?
@Garethp you might also be interested, since this looks a lot like your "ignore-checker" idea. I think this solution might better fit your use case.

@nicojs
Copy link
Member Author

nicojs commented Sep 25, 2020

Discussed with @simondel and we feel like moving this outside of the 4.0 milestone. If someone disagrees let me know.

@nicojs nicojs removed this from the 4.0 milestone Sep 25, 2020
@nicojs
Copy link
Member Author

nicojs commented Oct 6, 2020

Duplicate of #1681

@nicojs nicojs marked this as a duplicate of #1681 Oct 6, 2020
@stale
Copy link

stale bot commented Oct 6, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the ☠ stale Marked as stale by the stale bot, will be removed after a certain time. label Oct 6, 2021
@stale stale bot closed this as completed Nov 5, 2021
@sanderblijlevens
Copy link

Hi @nicojs, we are using Stryker in a nestjs project and would like Stryker to also mutate our decorators. Is this something that is already possible now (can't find it in the documentation)?

Is there still an issue for Angular (which could be solved with an ignore plugin) or could we enable mutations on decorators?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 Feature request New feature request ☠ stale Marked as stale by the stale bot, will be removed after a certain time.
Projects
None yet
Development

No branches or pull requests

2 participants