Skip to content
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

Code is not modified correctly with delete variable?.[index] syntax #4741

Closed
b-levinger opened this issue Feb 19, 2024 · 2 comments · Fixed by #4742
Closed

Code is not modified correctly with delete variable?.[index] syntax #4741

b-levinger opened this issue Feb 19, 2024 · 2 comments · Fixed by #4742
Labels
🐛 Bug Something isn't working

Comments

@b-levinger
Copy link

b-levinger commented Feb 19, 2024

Summary

Stryker is not instrumenting "delete with nullable indexer" syntax correctly.
Example source code delete myVariable?.[indexer] is instrumented as

delete (stryMutAct_9fa48("3390") ? myVariable[indexer] : (stryCov_9fa48("3390"), myVariable?.[indexer]));

This generated code does not operate the same as the original source causing the initial dry run test to fail.

One possible correct instrumentation would be the following:

if (stryMutAct_9fa48("3391") ? false : stryMutAct_9fa48("3390") ? true : (stryCov_9fa48("3390", "3391"), myVariable)) {
     if (stryMutAct_9fa48("3392")) {
       {}
     } else {
       stryCov_9fa48("3392");
       delete myVariable[indexer];
     }
   }

Stryker config

{
  "$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
  "_comment": "This config was generated using 'stryker init'. Please take a look at: https://stryker-mutator.io/docs/stryker-js/configuration/ for more information.",
  "packageManager": "npm",
  "checkers": ["typescript"],
  "tsconfigFile": "tsconfig.json",
  "typescriptChecker": {
    "prioritizePerformanceOverAccuracy": false
  },
  "dryRunTimeoutMinutes": 25,
  "reporters": [
    "html",
    "clear-text",
    "progress",
    "dashboard"
  ],  
  "commandRunner": {
    "command": "npm run test:stryker"
  },
  "cleanTempDir": true,
  "tempDirName": "stryker-tmp",
  "mutate": [ "src/**/*.ts" ],
  "testRunner": "jest",
  "testRunner_comment": "Take a look at https://stryker-mutator.io/docs/stryker-js/jest-runner for information about the jest plugin.",
  "coverageAnalysis": "all"
}

Test runner config

Stryker environment

+-- @stryker-mutator/core@8.2.4
+-- @stryker-mutator/jest-runner@8.2.3
+-- @stryker-mutator/typescript-checker@8.2.3
+-- jest@29.7.0

Your Environment

software version(s)
node 21.5
npm 10.2.4
Operating System mac
@nicojs
Copy link
Member

nicojs commented Feb 20, 2024

Thanks! I will try to release a fix asap.

@nicojs
Copy link
Member

nicojs commented Feb 20, 2024

Released in 8.2.5 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants