Closed ohoward2001 closed 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
Hi @nicojs thanks for responding so quickly. The suggestion to run tests normally beforehand has worked! Thanks for the help
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 ✏️ 👇)
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": {
}, "defaultProject": "#####", "schematics": { "@schematics/angular:component": { "prefix": "app", "style": "scss" }, "@schematics/angular:directive": { "prefix": "app" } }, "cli": { "analytics": false, "defaultCollection": "@angular-eslint/schematics" } }
Your Environment
Add stryker.log
stryker.log