stryker-mutator / stryker-js

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

Tried to check a file, but no watcher is registered for it. Changes would go unnoticed. This probably means that you need to expand the files that are included in your project. #3026

Closed QuantariusRay closed 2 years ago

QuantariusRay commented 3 years ago

Summary

Getting an error in a large Angular project that states

Error: Tried to check file "/Users/jisaecx/WebstormProjects/-/projects/-/src/app/app-routing.module.ts" (which is part of your typescript project), but no watcher is registered for it. Changes would go unnoticed. This probably means that you need to expand the files that are included in your project.

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": [
    "projects/-/-/**/*.ts",
    "!projects/-/-/**/*.spec.ts",
    "!projects/-/-/test.ts",
    "!projects/-/-/environments/*.ts"
  ],
  "disableTypeChecks": "projects/**/*.ts",
  "testRunner": "karma",
  "karma": {
    "configFile": "./projects/-/karma.conf.js",
    "projectType": "angular-cli",
    "ngConfig": {
      "testArguments": {
        "project": "-"
      }
    },
    "config": {
      "browsers": [
        "ChromeHeadless"
      ]
    }
  },
  "reporters": [
    "progress",
    "clear-text",
    "html"
  ],
  "htmlReporter": {
    "baseDir": "stryker/reports/loads"
  },
  "concurrency": 4,
  "concurrency_comment": "Recommended to use about half of your available cores when running stryker with angular",
  "coverageAnalysis": "perTest",
  "checkers": [
    "typescript"
  ],
  "tsconfigFile": "./projects/-/tsconfig.app.json"
}

Test runner config

Karma

module.exports = function (config) {
  config.set({
    basePath: '',

    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    specReporter: {
      maxLogLines: 5, // limit number of lines logged per test
      suppressWarnSummary: true, // do not print warn summary
      suppressErrorSummary: false, // do not print error summary
      suppressFailed: false, // do not print information about failed tests
      suppressPassed: true, // do not print information about passed tests
      suppressSkipped: true, // do not print information about skipped tests
      showSpecTiming: false, // print the time elapsed for each spec
    },
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-mocha-reporter'),
      require('karma-verbose-reporter'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('karma-junit-reporter'),
      require('@angular-devkit/build-angular/plugins/karma'),
      require('karma-phantomjs-launcher'),
      require('puppeteer'),
    ],

    client: {
      clearContext: false, // leave Jasmine Spec Runner output visible in browser
      jasmine: {
        random: false,
      },
    },

    files: [],
    preprocessors: {},
    mime: {
      'text/x-typescript': ['ts', 'tsx'],
    },

    junitReporter: {
      outputDir: '../../coverage', // results will be saved as $outputDir/$browserName.xml
      useBrowserName: false, // add browser name to report and classes names
      outputFile: 'TEST-app-report.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile
    },

    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../../coverage'),
      reports: ['html', 'lcovonly', 'cobertura'],
      fixWebpackSourcePaths: true,
    },

    reporters:
      config.angularCli && config.angularCli.codeCoverage
        ? ['progress', 'coverage-istanbul', 'junit', 'mocha']
        : ['progress', 'kjhtml', 'junit', 'mocha'],

    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome_without_security'],
    // you can define custom flags
    customLaunchers: {
      Chrome_without_security: {
        base: 'ChromeHeadless',
        flags: [
          '--disable-gpu',
          '--no-sandbox',
          '--disable-translate',
          '--disable-extensions',
        ],
      },
    },
    singleRun: false,
    captureTimeout: 2100000,
    browserDisconnectTimeout: 210000,
    browserDisconnectTolerance: 3,
    browserNoActivityTimeout: 2100000,
    reportSlowerThan: 100,
    browserConsoleLogOptions: { level: 'debug', terminal: false },
  });
};

Stryker environment

    "@stryker-mutator/core": "^5.2.2",
    "@stryker-mutator/karma-runner": "^5.2.2",
    "@stryker-mutator/typescript-checker": "^5.2.2"
+-- angular-cli@9.1.13
+-- karma@6.3.2
+-- jasmine-core@3.7.1

Your Environment Running on Mac

stryker.log

I may have missed some things. But I feel like there isn't anything out of the ordinary here. The tests run, but the stryker portion isn't actually running.

This seems to be coming from the @stryker-mutator/typescrpt-checker.

nicojs commented 3 years ago

Hi @QuantariusRay , can you also share your tsconfig file? ./projects/-/tsconfig.app.json

QuantariusRay commented 3 years ago

Hey! Thanks for the quick response time! Here is the tsconfig.app as well as the tsconfig.

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "downlevelIteration": true,
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "esnext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "resolveJsonModule": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ],
    "paths": {
      "@-/loads-shared": [
        "dist/shared"
      ],
      "@-/-": [
        "dist/messaging-shared"
      ],
      "@-/-/*": [
        "dist/messaging-shared/*"
      ],
      "@-/-": [
        "dist/support"
      ],
      "@-/-": [
        "dist/driver-messaging"
      ]
    }
  },
  "editor.codeActionsOnSave": {
    "source.fixAll.tslint": true
  },
  "angularCompilerOptions": {
    "disableTypeScriptVersionCheck": true
  },
  "exclude": ["./cypress"]
}
nicojs commented 3 years ago

Hmmm interesting. the file should be included if I follow normal "tsc practices". Could you try to run this command? Does that work?

npx tsc -b ./projects/-/tsconfig.app.json

QuantariusRay commented 3 years ago

Seems to work. It blinks for a few and then opens a new command line.

QuantariusRay commented 3 years ago

Let me post-face this. We are just adding this to a very large project. Instead of focusing all tests, I'm focusing it on a single directory through my test.ts file. Is there a better way of isolating this instead of mutating a particular directory?

nicojs commented 3 years ago

To focus on a small part, try to change the "mutate" property. Try to focus that on a couple of files first. Without checkers, just to see if that works.

After that, you should be able to add the "checkers": ["typescript"]. If you get the same error, try to see if you can run tsc with --listFilesOnly (https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options). I haven't tried this myself, but it seems to come in handy here.

npx tsc --listFilesOnly -p ./projects/-/tsconfig.app.json

It should list all included files. See I the file the TypeScript checker is complaining about missing a watcher is in the list. If so, please try to create a small reproduction project (the smaller the better) and upload it here.

QuantariusRay commented 3 years ago

Okay, running it without "checkers": ["typescript"] worked as great as I could expect, I think. I think it still attempted to test everything? I can't really make out what happened, but it did print out a report.

I then added the checkers and got the same error, so I did the --listFilesOnly and got a print out of all of the files and sure enough, the file does show up in the list. I'm not sure how I'd be able to upload the project. It's massive. Would it be possible to do a zoom share or something or any other snippet I could potentially upload?

nicojs commented 3 years ago

I think it still attempted to test everything? I can't really make out what happened, but it did print out a report.

Stryker will run an initial test run (dry run) to figure out which tests are covering which mutant. But during actual mutation testing, it will only run the exact tests needed for each mutant (and skip mutants without any coverage). This works because you've configured "coverageAnalysis": "perTest" (also the default), which is the most performant approach you always want to use.

I'm not sure how I'd be able to upload the project. It's massive.

Could you try to create a new angular project and then create some of the files that you now have? For example, create ./projects/-/tsconfig.app.json and projects/-/src/app/app-routing.module.ts. The implementation can be a dummy one. Try if that reproduces the issue. If not, start copy over more (tsconfig.json config, etc) until it can be reproduced. Once you're done you can zip the project (without node_modules) and upload it here.

Sorry to ask that from you, but without being able to reproduce an issue, it is really difficult to fix it.

QuantariusRay commented 3 years ago

Okay sounds good. I'll try to get as much of it copied over as possible.

nicojs commented 3 years ago

I'll try to get as much of it copied over as possible.

The idea is to copy as little as possible 😉. Just enough to reproduce this issue is fine.

EDIT: I'm assuming this is a closed source project. If it is open source, a URL to the repo is enough for me.

QuantariusRay commented 3 years ago

It is closed, but I did get the green light to share with you as long as there is no security stuff passed off. But I think just picking apart the things that are causing my issue is easy enough.

QuantariusRay commented 3 years ago

I haven't knocked this out yet, but its still coming!

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

CamilaQueiroz commented 9 months ago

I had this error, in my case it was because I deleted the reports folder where stryker-incremental.json is located. I was able to grab it from my repository and include it back in the project and then it worked