stryker-mutator / stryker-js

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

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

Closed b-levinger closed 4 months ago

b-levinger commented 4 months ago

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 commented 4 months ago

Thanks! I will try to release a fix asap.

nicojs commented 4 months ago

Released in 8.2.5 🚀