stryker-mutator / stryker-js

Mutation testing for JavaScript and friends
https://stryker-mutator.io
Apache License 2.0
2.59k stars 251 forks source link

More control over context where mutations should apply #4141

Open rolandjohann opened 1 year ago

rolandjohann commented 1 year ago

Context After introducing mutation tests at the backend with PIT we now move on to the frontend and are doing some PoCs on a small react TypeScript code base. At the component unit tests we discovered that some styling relevant JSX attributes will be mutated, which we don't care at the unit tests and affect the mutation score negatively. The comments to disable mutations for the next line are not working at JSX - even if, the component implementation would be polluted with comments to ignore certain things.

Questions

Our current approach would be to don't mutate *.{jsx,tsx} to prevent JSX attribute literas from being mutated. We are happy to get feedback, also from others how they incorporate mutation testing at a react implementation an their experience.

Thanks in advance, and a big thanks to the Stryker OSS community for this tool πŸ‘Œ.

Stryker environment

❯ yarn list | grep stryker ```bash β”œβ”€ @stryker-mutator/api@6.4.2 β”œβ”€ @stryker-mutator/core@6.4.2 β”‚ β”œβ”€ @stryker-mutator/api@6.4.2 β”‚ β”œβ”€ @stryker-mutator/instrumenter@6.4.2 β”‚ β”œβ”€ @stryker-mutator/util@6.4.2 β”œβ”€ @stryker-mutator/instrumenter@6.4.2 β”‚ β”œβ”€ @stryker-mutator/api@6.4.2 β”‚ β”œβ”€ @stryker-mutator/util@6.4.2 β”œβ”€ @stryker-mutator/jest-runner@6.4.2 β”‚ β”œβ”€ @stryker-mutator/api@6.4.2 β”‚ β”œβ”€ @stryker-mutator/util@6.4.2 β”œβ”€ @stryker-mutator/typescript-checker@6.4.2 β”‚ β”œβ”€ @stryker-mutator/api@6.4.2 β”‚ β”œβ”€ @stryker-mutator/util@6.4.2 β”œβ”€ @stryker-mutator/util@6.4.2 ```
❯ yarn list | grep jest ``` β”œβ”€ @happy-dom/jest-environment@9.9.2 β”‚ β”œβ”€ @jest/environment@^29.4.0 β”‚ β”œβ”€ @jest/fake-timers@^29.4.0 β”‚ β”œβ”€ @jest/types@^29.4.0 β”‚ β”œβ”€ jest-mock@^29.4.0 β”‚ └─ jest-util@^29.4.0 β”œβ”€ @jest/console@29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-message-util@^29.5.0 β”‚ β”œβ”€ jest-util@^29.5.0 β”œβ”€ @jest/core@29.5.0 β”‚ β”œβ”€ @jest/console@^29.5.0 β”‚ β”œβ”€ @jest/reporters@^29.5.0 β”‚ β”œβ”€ @jest/test-result@^29.5.0 β”‚ β”œβ”€ @jest/transform@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-changed-files@^29.5.0 β”‚ β”œβ”€ jest-config@^29.5.0 β”‚ β”œβ”€ jest-haste-map@^29.5.0 β”‚ β”œβ”€ jest-message-util@^29.5.0 β”‚ β”œβ”€ jest-regex-util@^29.4.3 β”‚ β”œβ”€ jest-resolve-dependencies@^29.5.0 β”‚ β”œβ”€ jest-resolve@^29.5.0 β”‚ β”œβ”€ jest-runner@^29.5.0 β”‚ β”œβ”€ jest-runtime@^29.5.0 β”‚ β”œβ”€ jest-snapshot@^29.5.0 β”‚ β”œβ”€ jest-util@^29.5.0 β”‚ β”œβ”€ jest-validate@^29.5.0 β”‚ β”œβ”€ jest-watcher@^29.5.0 β”œβ”€ @jest/environment@29.5.0 β”‚ β”œβ”€ @jest/fake-timers@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ └─ jest-mock@^29.5.0 β”œβ”€ @jest/expect-utils@29.5.0 β”‚ └─ jest-get-type@^29.4.3 β”œβ”€ @jest/expect@29.5.0 β”‚ └─ jest-snapshot@^29.5.0 β”œβ”€ @jest/fake-timers@29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-message-util@^29.5.0 β”‚ β”œβ”€ jest-mock@^29.5.0 β”‚ └─ jest-util@^29.5.0 β”œβ”€ @jest/globals@29.5.0 β”‚ β”œβ”€ @jest/environment@^29.5.0 β”‚ β”œβ”€ @jest/expect@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ └─ jest-mock@^29.5.0 β”œβ”€ @jest/reporters@29.5.0 β”‚ β”œβ”€ @jest/console@^29.5.0 β”‚ β”œβ”€ @jest/test-result@^29.5.0 β”‚ β”œβ”€ @jest/transform@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-message-util@^29.5.0 β”‚ β”œβ”€ jest-util@^29.5.0 β”‚ β”œβ”€ jest-worker@^29.5.0 β”œβ”€ @jest/schemas@29.4.3 β”œβ”€ @jest/source-map@29.4.3 β”œβ”€ @jest/test-result@29.5.0 β”‚ β”œβ”€ @jest/console@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”œβ”€ @jest/test-sequencer@29.5.0 β”‚ β”œβ”€ @jest/test-result@^29.5.0 β”‚ β”œβ”€ jest-haste-map@^29.5.0 β”œβ”€ @jest/transform@29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-haste-map@^29.5.0 β”‚ β”œβ”€ jest-regex-util@^29.4.3 β”‚ β”œβ”€ jest-util@^29.5.0 β”œβ”€ @jest/types@29.5.0 β”‚ β”œβ”€ @jest/schemas@^29.4.3 β”‚ β”œβ”€ eslint-plugin-jest-dom@^4.0.2 β”‚ β”œβ”€ eslint-plugin-jest@^26.9.0 β”‚ β”œβ”€ @jest/transform@^29.3.1 β”‚ β”œβ”€ @jest/types@27.5.1 β”‚ β”œβ”€ jest-mock@^27.0.6 β”‚ β”œβ”€ jest-mock@27.5.1 β”‚ β”‚ β”œβ”€ @jest/types@^27.5.1 β”œβ”€ @stryker-mutator/jest-runner@6.4.2 β”œβ”€ @testing-library/jest-dom@5.16.5 β”‚ β”œβ”€ @types/testing-library__jest-dom@^5.9.1 β”œβ”€ @types/jest@29.5.1 β”œβ”€ @types/testing-library__jest-dom@5.14.5 β”‚ └─ @types/jest@* β”œβ”€ babel-jest@29.5.0 β”‚ β”œβ”€ @jest/transform@^29.5.0 β”‚ β”œβ”€ babel-preset-jest@^29.5.0 β”œβ”€ babel-plugin-jest-hoist@29.5.0 β”œβ”€ babel-preset-jest@29.5.0 β”‚ β”œβ”€ babel-plugin-jest-hoist@^29.5.0 β”œβ”€ eslint-plugin-jest-dom@4.0.3 β”œβ”€ eslint-plugin-jest@26.9.0 β”‚ β”œβ”€ @jest/expect-utils@^29.5.0 β”‚ β”œβ”€ jest-get-type@^29.4.3 β”‚ β”œβ”€ jest-matcher-utils@^29.5.0 β”‚ β”œβ”€ jest-message-util@^29.5.0 β”‚ └─ jest-util@^29.5.0 β”œβ”€ jest-changed-files@29.5.0 β”œβ”€ jest-circus@29.5.0 β”‚ β”œβ”€ @jest/environment@^29.5.0 β”‚ β”œβ”€ @jest/expect@^29.5.0 β”‚ β”œβ”€ @jest/test-result@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-each@^29.5.0 β”‚ β”œβ”€ jest-matcher-utils@^29.5.0 β”‚ β”œβ”€ jest-message-util@^29.5.0 β”‚ β”œβ”€ jest-runtime@^29.5.0 β”‚ β”œβ”€ jest-snapshot@^29.5.0 β”‚ β”œβ”€ jest-util@^29.5.0 β”œβ”€ jest-cli@29.5.0 β”‚ β”œβ”€ @jest/core@^29.5.0 β”‚ β”œβ”€ @jest/test-result@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-config@^29.5.0 β”‚ β”œβ”€ jest-util@^29.5.0 β”‚ β”œβ”€ jest-validate@^29.5.0 β”œβ”€ jest-config@29.5.0 β”‚ β”œβ”€ @jest/test-sequencer@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ babel-jest@^29.5.0 β”‚ β”œβ”€ jest-circus@^29.5.0 β”‚ β”œβ”€ jest-environment-node@^29.5.0 β”‚ β”œβ”€ jest-get-type@^29.4.3 β”‚ β”œβ”€ jest-regex-util@^29.4.3 β”‚ β”œβ”€ jest-resolve@^29.5.0 β”‚ β”œβ”€ jest-runner@^29.5.0 β”‚ β”œβ”€ jest-util@^29.5.0 β”‚ β”œβ”€ jest-validate@^29.5.0 β”œβ”€ jest-diff@29.5.0 β”‚ β”œβ”€ jest-get-type@^29.4.3 β”œβ”€ jest-docblock@29.4.3 β”œβ”€ jest-each@29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-get-type@^29.4.3 β”‚ β”œβ”€ jest-util@^29.5.0 β”œβ”€ jest-environment-jsdom@29.5.0 β”‚ β”œβ”€ @jest/environment@^29.5.0 β”‚ β”œβ”€ @jest/fake-timers@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-mock@^29.5.0 β”‚ β”œβ”€ jest-util@^29.5.0 β”œβ”€ jest-environment-node@29.5.0 β”‚ β”œβ”€ @jest/environment@^29.5.0 β”‚ β”œβ”€ @jest/fake-timers@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-mock@^29.5.0 β”‚ └─ jest-util@^29.5.0 β”œβ”€ jest-get-type@29.4.3 β”œβ”€ jest-haste-map@29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-regex-util@^29.4.3 β”‚ β”œβ”€ jest-util@^29.5.0 β”‚ β”œβ”€ jest-worker@^29.5.0 β”œβ”€ jest-leak-detector@29.5.0 β”‚ β”œβ”€ jest-get-type@^29.4.3 β”œβ”€ jest-matcher-utils@29.5.0 β”‚ β”œβ”€ jest-diff@^29.5.0 β”‚ β”œβ”€ jest-get-type@^29.4.3 β”œβ”€ jest-message-util@29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”œβ”€ jest-mock@29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ └─ jest-util@^29.5.0 β”œβ”€ jest-pnp-resolver@1.2.3 β”œβ”€ jest-regex-util@29.4.3 β”œβ”€ jest-resolve-dependencies@29.5.0 β”‚ β”œβ”€ jest-regex-util@^29.4.3 β”‚ └─ jest-snapshot@^29.5.0 β”œβ”€ jest-resolve@29.5.0 β”‚ β”œβ”€ jest-haste-map@^29.5.0 β”‚ β”œβ”€ jest-pnp-resolver@^1.2.2 β”‚ β”œβ”€ jest-util@^29.5.0 β”‚ β”œβ”€ jest-validate@^29.5.0 β”œβ”€ jest-runner@29.5.0 β”‚ β”œβ”€ @jest/console@^29.5.0 β”‚ β”œβ”€ @jest/environment@^29.5.0 β”‚ β”œβ”€ @jest/test-result@^29.5.0 β”‚ β”œβ”€ @jest/transform@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-docblock@^29.4.3 β”‚ β”œβ”€ jest-environment-node@^29.5.0 β”‚ β”œβ”€ jest-haste-map@^29.5.0 β”‚ β”œβ”€ jest-leak-detector@^29.5.0 β”‚ β”œβ”€ jest-message-util@^29.5.0 β”‚ β”œβ”€ jest-resolve@^29.5.0 β”‚ β”œβ”€ jest-runtime@^29.5.0 β”‚ β”œβ”€ jest-util@^29.5.0 β”‚ β”œβ”€ jest-watcher@^29.5.0 β”‚ β”œβ”€ jest-worker@^29.5.0 β”œβ”€ jest-runtime@29.5.0 β”‚ β”œβ”€ @jest/environment@^29.5.0 β”‚ β”œβ”€ @jest/fake-timers@^29.5.0 β”‚ β”œβ”€ @jest/globals@^29.5.0 β”‚ β”œβ”€ @jest/source-map@^29.4.3 β”‚ β”œβ”€ @jest/test-result@^29.5.0 β”‚ β”œβ”€ @jest/transform@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-haste-map@^29.5.0 β”‚ β”œβ”€ jest-message-util@^29.5.0 β”‚ β”œβ”€ jest-mock@^29.5.0 β”‚ β”œβ”€ jest-regex-util@^29.4.3 β”‚ β”œβ”€ jest-resolve@^29.5.0 β”‚ β”œβ”€ jest-snapshot@^29.5.0 β”‚ β”œβ”€ jest-util@^29.5.0 β”œβ”€ jest-snapshot@29.5.0 β”‚ β”œβ”€ @jest/expect-utils@^29.5.0 β”‚ β”œβ”€ @jest/transform@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-diff@^29.5.0 β”‚ β”œβ”€ jest-get-type@^29.4.3 β”‚ β”œβ”€ jest-matcher-utils@^29.5.0 β”‚ β”œβ”€ jest-message-util@^29.5.0 β”‚ β”œβ”€ jest-util@^29.5.0 β”œβ”€ jest-util@29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”œβ”€ jest-validate@29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-get-type@^29.4.3 β”œβ”€ jest-watcher@29.5.0 β”‚ β”œβ”€ @jest/test-result@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ β”œβ”€ jest-util@^29.5.0 β”œβ”€ jest-worker@29.5.0 β”‚ β”œβ”€ jest-util@^29.5.0 β”œβ”€ jest@29.5.0 β”‚ β”œβ”€ @jest/core@^29.5.0 β”‚ β”œβ”€ @jest/types@^29.5.0 β”‚ └─ jest-cli@^29.5.0 β”‚ β”œβ”€ @jest/schemas@^29.4.3 ```
nicojs commented 1 year ago

is it possible to disable mutations with comments at JSX?

Yes, you can use // Stryker disable comments. See https://stryker-mutator.io/docs/stryker-js/disable-mutants/#using-a--stryker-disable-comment for details.

(even better) is it possible to define rules at which context mutations should not apply?

3229 is probably what you want. Please upvote that one.

Thanks in advance, and a big thanks to the Stryker OSS community for this tool πŸ‘Œ.

You're welcome :)