Skip to content

Switch to using globalThis instead of eval? #4035

@vlovich

Description

@vlovich

Summary

Today in the instrumented code there's new Function('return this') all over the place. This isn't compatible with some environments that disable eval (e.g. Cloudflare workers). Is it possible to leverage globalThis instead (even if there's reason for it not to be a default, maybe for it to be a configurable option?).

Today if you load a Stryker mutation under Workers it fails with

Stryker config

// @ts-check
/** @type {import('@stryker-mutator/api/core').PartialStrykerOptions} */

process.env.STRYKER = '1'

const config = {
  _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",
  reporters: ["html", "clear-text", "progress"],
  checkers: ["typescript"],
  tsconfigFile: "tests/tsconfig.json",
  coverageAnalysis: "perTest",
  commandRunner: { command: "npm run tests" },
};
export default config;

Test runner config

N/A

Stryker environment

npm ls | grep stryker
├── @stryker-mutator/[email protected]
├── @stryker-mutator/[email protected]

Using mocha 10 but that's not really relevant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions