stryker-mutator / stryker-js

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

Dry run fails with "Error: Unexpected value declared by the module 'DynamicTestModule'" #3430

Closed ohoward2001 closed 2 years ago

ohoward2001 commented 2 years ago

Summary

Stryker will run fine locally but in our Jenkins Pipeline the initial test run fails everytime with dozens of tests failing with the above error. The number of tests failing differs each run, it has been as low as 5 and gone up to 50, 100+. All unit tests pass when running 'ng test' separate from stryker.

Stryker config

{ "$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json", "_comment": "This config was generated using 'stryker init'. Please see the guide for more information: https://stryker-mutator.io/docs/stryker-js/guides/angular", "mutate": [ "!src/*/.spec.ts", "!src/test.ts", "!src/environments/*.ts" ], "testRunner": "karma", "karma": { "configFile": "karma.conf.js", "projectType": "angular-cli", "config": { "browsers": ["ChromeHeadlessNoSandbox"], "customLaunchers": { "ChromeHeadlessNoSandbox": { "base": "ChromeHeadless", "flags": ["--no-sandbox", "--disable-gpu"] } } } }, "reporters": ["progress", "clear-text", "html"], "concurrency": 4, "concurrency_comment": "Recommended to use about half of your available cores when running stryker with angular", "coverageAnalysis": "perTest", "timeoutMS": 120000, "dryRunTimeoutMinutes": 30, "checkers": ["typescript"], "tsconfigFile": "tsconfig.json" }

Test runner config

karma.conf.js

module.exports = config => { const IS_NOT_HEADLESS = config.browsers.length;

config.set({ frameworks: ['jasmine', '@angular-devkit/build-angular'], plugins: [ 'karma-jasmine', 'karma-chrome-launcher', 'karma-coverage', 'karma-junit-reporter', 'karma-spec-reporter', 'karma-jasmine-html-reporter', '@angular-devkit/build-angular/plugins/karma', ], client: { clearContext: IS_NOT_HEADLESS ? false : true, // when false, leaves Jasmine Spec Runner output visible in browser jasmine: { random: false }, // (Angular v10 revisit) tests run synchronously }, mime: { 'text/x-typescript': ['ts', 'tsx'] }, coverageReporter: { dir: require('path').join(dirname, 'coverage'), subdir: '.', reporters: [{ type: 'html' }, { type: 'lcovonly' }], fixWebpackSourcePaths: true, thresholds: { statements: 78, lines: 77, branches: 57, functions: 68, }, }, browserNoActivityTimeout: 100000, // allow more time before Karma disconnects browserDisconnectTimeout: 10000, junitReporter: { outputDir: require('path').join(dirname, 'coverage', 'junit') }, specReporter: { suppressSkipped: true, showSpecTiming: true }, reporters: IS_NOT_HEADLESS ? ['spec', 'kjhtml'] : ['spec', 'junit'], logLevel: config.LOG_ERROR, browsers: IS_NOT_HEADLESS ? [] : ['CustomHeadlessChrome'], customLaunchers: IS_NOT_HEADLESS ? {} : { CustomHeadlessChrome: { base: 'ChromeHeadless', flags: [ '--disable-web-security', '--disable-gpu', '--no-sandbox', // required to run without privileges in docker '--remote-debugging-port=9222', // without a remote debugging port, Google Chrome exits immediately '--js-flags=--max-old-space-size=5048', ], }, }, }); };

Stryker environment

????????? @stryker-mutator/core@5.6.1 ????????? @stryker-mutator/karma-runner@5.6.1 ????????? @stryker-mutator/typescript-checker@5.6.1

"karma": "^6.3.6",

Test runner environment

ng test -- --watch=false --code-coverage

angular.json

{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "#####": { "root": "", "sourceRoot": "src", "projectType": "application", "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "allowedCommonJsDependencies": ["highcharts"], "baseHref": "#####", "outputPath": "dist", "index": "src/index.html", "main": "src/main.ts", "tsConfig": "src/tsconfig.app.json", "polyfills": "src/polyfills.ts", "assets": [ "src/assets", { "glob": "/*.min.css", "input": "node_modules/material-design-iconic-font/dist/css", "output": "/assets/css" }, { "glob": "*/.min.css", "input": "node_modules/font-awesome/css", "output": "/assets/css" }, { "glob": "/*", "input": "node_modules/material-design-iconic-font/dist/fonts", "output": "/assets/fonts" }, { "glob": "*/", "input": "node_modules/font-awesome/fonts", "output": "/assets/fonts" }, "src/favicon.ico", "src/ngsw-manifest.json" ], "styles": [ "#####" ], "scripts": [], "#####" }, "configurations": {

      "defaultConfiguration": ""
    },
    "serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "#####:build",
        "proxyConfig": "proxy.conf.json"
      },
      "configurations": {
        "localapi": {
          "browserTarget": "#####"
        },
        "production": {
          "browserTarget": "#####"
        }
      }
    },
    "extract-i18n": {
      "builder": "@angular-devkit/build-angular:extract-i18n",
      "options": {
        "browserTarget": "#####"
      }
    },
    "test": {
      "builder": "@angular-devkit/build-angular:karma",
      "options": {
        "main": "src/test.ts",
        "karmaConfig": "./karma.conf.js",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.spec.json",
        "codeCoverage": true,
        "scripts": [],
        "styles": [],
        "assets": []
      }
    },
    "lint": {
      "builder": "@angular-eslint/builder:lint",
      "options": {
        "lintFilePatterns": ["src/**/*.ts", "src/**/*.html"]
      }
    },
    "server": {
      "builder": "@angular-devkit/build-angular:server",
      "options": {
        "outputPath": "dist-server",
        "main": "main.server.ts",
        "tsConfig": "tsconfig.server.json",
        "sourceMap": true,
        "optimization": false
      },
      "defaultConfiguration": ""
    }
  }
}

}, "defaultProject": "#####", "schematics": { "@schematics/angular:component": { "prefix": "app", "style": "scss" }, "@schematics/angular:directive": { "prefix": "app" } }, "cli": { "analytics": false, "defaultCollection": "@angular-eslint/schematics" } }

Your Environment

software version(s)
node v16.13.1
npm 8.1.2
Operating System Windows 10

Add stryker.log

stryker.log

nicojs commented 2 years ago

Hi @ohoward2001 thanks for opening this issue.

If it is working locally, it should also work in the CI pipeline. Are there any differences between the 2? Do you check in your package-lock.json file? Is there a difference in OS? What version of Angular are you running?

Can you maybe try to first run tests normally before running Stryker? I've noticed that the first time running tests with the angular cli, it does some first-time setup.

npm test
npm run stryker 
ohoward2001 commented 2 years ago

Hi @nicojs thanks for responding so quickly. The suggestion to run tests normally beforehand has worked! Thanks for the help

nicojs commented 2 years ago

Glad that works. I've noticed it before for angular projects. Very strange. I think ng build works to. Might be faster. If you want to help others, feel free to add this to our troubleshooting guide: https://stryker-mutator.io/docs/stryker-js/troubleshooting/ (edit button below ✏️ 👇)