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

Invalid regular expression in initial test run on Node 18 #3579

Closed
ericcornelissen opened this issue Jun 15, 2022 · 2 comments · Fixed by #3642
Closed

Invalid regular expression in initial test run on Node 18 #3579

ericcornelissen opened this issue Jun 15, 2022 · 2 comments · Fixed by #3642
Labels
🐛 Bug Something isn't working

Comments

@ericcornelissen
Copy link

Summary

When running Stryker on one of my projects using Node 18 (using this branch) I'm getting an unexpected error during the initial test run. In particular, I'm getting the following error:

SyntaxError: Invalid regular expression: /\u/: Invalid Unicode escape

This error is related to the use of a regular expression of the form /\u{0}/gu in several places (example). Inspecting the files in Stryker's temp directory does reveal regular expressions of the form /\u/gu, which is indeed invalid syntax. However, it is not clear to me how such an invalid regular expression ends up in the code generated by Stryker.

A notable detail, I'm encountering this bug only on Node 18 (I tried 18.0.0 and 18.13.0) but not earlier versions (I tried 16.13.1, but I've been using Stryker on Node 16 in this project for a while now).

Stryker config

{
  "$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
  "coverageAnalysis": "perTest",
  "inPlace": false,
  "mutate": ["src/**/*.js"],
  "commandRunner": {
    "command": "npm run test:unit"
  },
  "timeoutMS": 10000,
  "reporters": ["clear-text", "dashboard", "html", "progress"],
  "htmlReporter": {
    "fileName": "_reports/mutation/index.html"
  },
  "thresholds": {
    "high": 100,
    "low": 100,
    "break": 100
  },
  "tempDirName": ".temp/stryker",
  "cleanTempDir": false
}

Test runner config

I'm using AVA without any configuration.

Stryker environment

├── @stryker-mutator/core@6.0.1
├── ava@4.3.0

Test runner environment

ava test/unit/**/*.test.js

Your Environment

software version(s)
node v18.3.0
npm v8.11.0
Operating System Ubuntu 20.04.4 LTS (64 bit)

Add stryker.log

stryker.log

@nicojs
Copy link
Member

nicojs commented Jun 23, 2022

Hi @ericcornelissen 🙋‍♂️ thanks for opening this issue.

This is a neat little bug. Apparently the Regex mutator we use (⚔ weapon-regex) is mutating this incorrectly. I've opened an issue there.

In the meantime, you can workaround it by disabling mutating these regexes with a comment:

export function escapeArgBash(arg) {
    // Stryker disable next-line Regex: Results in invalid mutant
    return arg.replace(/\u{0}/gu, "");
}

@ericcornelissen
Copy link
Author

ericcornelissen commented Jun 27, 2022

In the meantime, you can workaround it by disabling mutating these regexes with a comment:

export function escapeArgBash(arg) {
    // Stryker disable next-line Regex: Results in invalid mutant
    return arg.replace(/\u{0}/gu, "");
}

After reading through stryker-mutator/weapon-regex#163 I think a better workaround is to switch from a unicode regex to a "normal" regex and use \u0000:

  export function escapeArgBash(arg) {
-     // Stryker disable next-line Regex: Results in invalid mutant
-     return arg.replace(/\u{0}/gu, "");
+     return arg.replace(/\u0000/g, "");
  }

hugo-vrijswijk added a commit that referenced this issue Jul 18, 2022
hugo-vrijswijk added a commit that referenced this issue Jul 18, 2022
@nicojs nicojs linked a pull request Jul 25, 2022 that will close this issue
1 task
nicojs pushed a commit that referenced this issue Jul 26, 2022
This PR adds support for unicode regexes. I.e.: `/\u{0}/gu` isn't mutated to `/\u/gu` (which is invalid).

* update dependency weapon-regex to v1 to support unicode regexes, see stryker-mutator/weapon-regex#165
* pass regex flags argument to weapon-regex.

Closes #3579

Co-authored-by: Hugo van Rijswijk <git@hugovr.nl>
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