stryker-mutator / stryker-js

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

Error thrown when run in a project built with Angularjs, typescript, karma, jasmine #669

Closed rexmq closed 6 years ago

rexmq commented 6 years ago

Summary

The stryker run command is giving me errors.

[2018-03-26 22:53:38.540] [DEBUG] Sandbox - Creating a sandbox for files in /Users/jack/workspace/alphala/disney/.stryker-tmp/sandbox8533728
[2018-03-26 22:53:38.806] [DEBUG] Sandbox - Creating test runner 0 using settings {port: 9234}
[2018-03-26 22:53:38.853] [ERROR] TestRunnerChildProcessAdapter - TypeError: Serializing native function: bound apply
    at /Users/jack/workspace/alphala/disney/node_modules/serialize-javascript/index.js:112:19
    at RegExp.[Symbol.replace] (native)
    at RegExp.[Symbol.replace] (native)
    at String.replace (native)
    at Object.serialize (/Users/jack/workspace/alphala/disney/node_modules/serialize-javascript/index.js:99:16)
    at TestRunnerChildProcessAdapter.send (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/IsolatedTestRunnerAdapter.js:156:51)
    at TestRunnerChildProcessAdapter.sendStartCommand (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/IsolatedTestRunnerAdapter.js:164:14)
    at TestRunnerChildProcessAdapter.startWorker (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/IsolatedTestRunnerAdapter.js:59:14)
    at new TestRunnerChildProcessAdapter (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/IsolatedTestRunnerAdapter.js:50:15)
    at TimeoutDecorator.testRunnerProducer (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/ResilientTestRunnerFactory.js:9:72)
    at TimeoutDecorator.TestRunnerDecorator.createInnerRunner (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/TestRunnerDecorator.js:22:33)
    at TimeoutDecorator.TestRunnerDecorator [as constructor] (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/TestRunnerDecorator.js:10:15)
    at new TimeoutDecorator (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/TimeoutDecorator.js:15:42)
    at RetryDecorator.testRunnerProducer (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/ResilientTestRunnerFactory.js:9:20)
    at RetryDecorator.TestRunnerDecorator.createInnerRunner (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/TestRunnerDecorator.js:22:33)
    at RetryDecorator.TestRunnerDecorator [as constructor] (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/TestRunnerDecorator.js:10:15)
    at new RetryDecorator (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/RetryDecorator.js:16:42)
    at Object.create (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/ResilientTestRunnerFactory.js:8:16)
    at Sandbox.initializeTestRunner (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/Sandbox.js:141:64)
    at Sandbox.<anonymous> (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/Sandbox.js:42:52)
    at step (/Users/jack/workspace/alphala/disney/node_modules/tslib/tslib.js:129:27)
    at Object.next (/Users/jack/workspace/alphala/disney/node_modules/tslib/tslib.js:110:57)
    at fulfilled (/Users/jack/workspace/alphala/disney/node_modules/tslib/tslib.js:100:62)
[2018-03-26 22:53:38.863] [ERROR] StrykerCli - an error occurred TypeError: Cannot read property 'reject' of undefined
    at TestRunnerChildProcessAdapter.send (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/IsolatedTestRunnerAdapter.js:160:29)
    at TestRunnerChildProcessAdapter.sendStartCommand (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/IsolatedTestRunnerAdapter.js:164:14)
    at TestRunnerChildProcessAdapter.startWorker (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/IsolatedTestRunnerAdapter.js:59:14)
    at new TestRunnerChildProcessAdapter (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/IsolatedTestRunnerAdapter.js:50:15)
    at TimeoutDecorator.testRunnerProducer (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/ResilientTestRunnerFactory.js:9:72)
    at TimeoutDecorator.TestRunnerDecorator.createInnerRunner (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/TestRunnerDecorator.js:22:33)
    at TimeoutDecorator.TestRunnerDecorator [as constructor] (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/TestRunnerDecorator.js:10:15)
    at new TimeoutDecorator (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/TimeoutDecorator.js:15:42)
    at RetryDecorator.testRunnerProducer (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/ResilientTestRunnerFactory.js:9:20)
    at RetryDecorator.TestRunnerDecorator.createInnerRunner (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/TestRunnerDecorator.js:22:33)
    at RetryDecorator.TestRunnerDecorator [as constructor] (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/TestRunnerDecorator.js:10:15)
    at new RetryDecorator (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/RetryDecorator.js:16:42)
    at Object.create (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/isolated-runner/ResilientTestRunnerFactory.js:8:16)
    at Sandbox.initializeTestRunner (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/Sandbox.js:141:64)
    at Sandbox.<anonymous> (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/Sandbox.js:42:52)
    at step (/Users/jack/workspace/alphala/disney/node_modules/tslib/tslib.js:129:27)
    at Object.next (/Users/jack/workspace/alphala/disney/node_modules/tslib/tslib.js:110:57)
    at fulfilled (/Users/jack/workspace/alphala/disney/node_modules/tslib/tslib.js:100:62)

Stryker config

module.exports = function(config) {
  config.set({
    files: [

      // Exclude files so we can include only particular files later on.
      '!./**/*.ts',
      '!./**/*.js',

      // Include source files and flag them for mutation.
      { pattern: './src/**/*.ts', included: false, mutated: true },
      '!src/**/*.spec.ts',

      { pattern: './src/**/*.html', included: false, mutated: false, transpiled: false },
      { pattern: './src/**/*.scss', included: false, mutated: false, transpiled: false },
      { pattern: './src/**/*.spec.ts', included: true, mutated: false },

      '!./bs-config.js',
      '!./config/*.js',
      '!./coverage/**/*',
      '!./dist/**/*',
      '!./scripts/**/*',
      '!./node_modules/**/*',

      { pattern: './src/assets/images/**/*', included: true, mutated: false, transpiled: false },
      { pattern: './config/*.js', included: true, mutated: false, transpiled: false },
      { pattern: './package.json', included: true, mutated: false, transpiled: false },
      { pattern: './*.js', included: true, mutated: false, transpiled: false },

      { pattern: './src/assets/fonts/**/*', included: false, mutated: false, transpiled: false }

    ],
    testRunner: "karma",
    mutator: "typescript",
    transpilers: ["typescript"],
    reporter: ["clear-text", "progress"],
    testFramework: "jasmine",
    coverageAnalysis: "off",
    karmaConfigFile: "karma.conf.js",
    tsconfigFile: "tsconfig.json",
    mutate: ["src/**/*.ts"],
    logLevel: 'trace'
  });
};

Stryker environment

├─┬ stryker@0.20.1
├─┬ stryker-api@0.14.0
├─┬ stryker-html-reporter@0.12.4
├── stryker-jasmine@0.7.8
├─┬ stryker-karma-runner@0.12.5
├─┬ stryker-typescript@0.9.4

Your Environment

software version(s)
node 6.12.2
npm 5.6.0
typescript . 2.5.3
Operating System macos
nicojs commented 6 years ago

Hi @rexmq thanks for trying out Stryker!

Could you please also share your karma configuration?

My best guess is that your karma.conf.js uses a plugins: [require('some/plugin')] that results in a native function being added to the stryker config object. During the creation a child process for the test runner, that function is serialized (using serialize-javascript) to a string. Native functions are not supported here.

rexmq commented 6 years ago

Hi Nico,

Thanks for help. I think we do have the 'require' keyword used. Below are config details of the karma assuming that it is based on NODE_DEV=dev. ./karma.conf.js

var env = process.env.NODE_ENV;
console.log('Karma: using environment: ' + env);
module.exports = require('./config/karma.' + env + '.conf');

./config/karma.dev.conf.js

module.exports = function (config) {
  var configuration = require('./karma.common').karmaConfig;
  configuration.logLevel = config.LOG_ERROR;
  configuration.singleRun = false;

  config.set(configuration);
};

./config/karma.common.conf.js

var webpackConfig = require('./webpack.test');
exports.karmaConfig = {
  autoWatch: true,
  frameworks: ['jasmine', 'karma-typescript'],
  ngHtml2JsPreprocessor: {
    stripPrefix: 'src',
    moduleName: 'vrum'
  },
  browserDisconnectTolerance: 2,
  browsers: ['PhantomJS2'],
  files: [
    {pattern: './config/spec-bundle.js', watched: true}
  ],
  preprocessors: {
    'config/spec-bundle.js': ['webpack'],
    'src/app/**/*.ts': ['karma-typescript', 'webpack']
  },
  reportSlowerThan: 5000,
  reporters: ['progress', 'karma-typescript'],

  //Only show tests which fail.
  specReporter: {
    suppressSkipped: true,
    suppressPassed: true,
    showSpecTiming: true
  },
  singleRun: true,
  karmaTypescriptConfig: {
    reports: {
      'html': {
        directory: 'coverage',
        subdirectory: '../coverage',
        filename: '../coverage'
      },
      'text-summary': ''
    },
    coverageOptions: {
      threshold: {
        global: {
          statements: 98,
          branches: 98,
          functions: 98,
          lines: 98
        }
      }
    }
  },
  webpack: webpackConfig,
  webpackMiddleware: {
    stats: 'errors-only'
  }
};
nicojs commented 6 years ago

This is what I figured. I will mark this issue as Feature as we don't support complex javascript objects in karma configuration yet. We have an idea on how to implement it though.

We should remove the KarmaConfigEditor plugin from the stryker-karma-runner package. Instead just read the config from the KarmaTestRunner spawned in the child process.

ConfigEditor plugins are executed in the main Stryker process. Any configuration they add to the stryker configuration (in this case the karma configuration) needs to be serialized to be send to one of the child processes ("sandbox" process). As your karma configuration contains your entire webpack config object (which includes a wide range of functions, class instances and native method calls), we will never be able to serialize and deserialize it. Better to just read your karma config file from the sandbox processes.

The reason why we initially decided on this way of working is to allow the KarmaConfigEditor to mutate the files array of stryker, but we will remove that functionality when #589 is implemented.

rexmq commented 6 years ago

Hi Nico,

Thanks for that. I am wondering if you can guide me on a workaround to make the stryker run in my project? Quite keen to see how it helps improve the testing.

Regards

nicojs commented 6 years ago

@rexmq as a workaround you could try to remove the webpack config from your karma configuration. Instead you can use the stryker-webpack-transpiler to create the test bundles for you.

As a test to see of it is serializable you could use:

var serialize = require('serialize-javascript');
serialize(require('./config/karma.common.conf.js');
rexmq commented 6 years ago

Hi Nico

You were right. I tried the test script by removing below lines related to webpack in the karma conf file and it didn't give any errors.

var webpackConfig = require('./webpack.test');
.......
webpack: webpackConfig,
  webpackMiddleware: {
    stats: 'errors-only'
  }

Then I tried to run stryker run with below config but got another error.

module.exports = function(config) {
  config.set({
    files: [

      // Exclude files so we can include only particular files later on.
      '!./**/*.ts',
      '!./**/*.js',

      // Include source files and flag them for mutation.
      { pattern: './src/**/*.ts', included: false, mutated: true },
      '!src/**/*.spec.ts',

      { pattern: './src/**/*.html', included: false, mutated: false, transpiled: false },
      { pattern: './src/**/*.scss', included: false, mutated: false, transpiled: false },
      { pattern: './src/**/*.spec.ts', included: true, mutated: false },

      '!./bs-config.js',
      '!./config/*.js',
      '!./coverage/**/*',
      '!./dist/**/*',
      '!./scripts/**/*',
      '!./node_modules/**/*',

      { pattern: './src/assets/images/**/*', included: true, mutated: false, transpiled: false },
      { pattern: './config/*.js', included: true, mutated: false, transpiled: false },
      { pattern: './package.json', included: true, mutated: false, transpiled: false },
      { pattern: './*.js', included: true, mutated: false, transpiled: false },

      { pattern: './src/assets/fonts/**/*', included: false, mutated: false, transpiled: false }

    ],
    testRunner: "karma",
    mutator: "typescript",
    transpilers: ["webpack"],
    reporter: ["clear-text", "progress"],
    testFramework: "jasmine",
    coverageAnalysis: "off",
    karmaConfigFile: "karma.conf.js",
    tsconfigFile: "tsconfig.json",
    mutate: ["src/**/*.ts"],
    logLevel: 'trace'
  });
};

The error is like below. Any possible workaround to overcome this? Many thanks for your help.

[at-loader] Checking started in a separate process...

[at-loader] Ok, 2.188 sec. [2018-03-30 00:39:16.845] [ERROR] StrykerCli - an error occurred Error: Could not transpile input files: Execute webpack: Error: ENOENT: no such file or directory, open '/Users/jack/workspace/alphala/disney/dist/vendor.bundle.js' at InitialTestExecutor. (/Users/jack/workspace/alphala/disney/node_modules/stryker/src/process/InitialTestExecutor.js:54:31) at step (/Users/jack/workspace/alphala/disney/node_modules/tslib/tslib.js:129:27) at Object.next (/Users/jack/workspace/alphala/disney/node_modules/tslib/tslib.js:110:57) at fulfilled (/Users/jack/workspace/alphala/disney/node_modules/tslib/tslib.js:100:62)

nicojs commented 6 years ago

It seems like you didn't specify the webpack config file in stryker configuration. If you don't do that it uses defaults. See the stryker-webpack-transpiler readme for more information.

That being said: I don't really understand the error you have. I hope this helps. I suggest to first test your webpack configuration yourself using the cli: https://webpack.js.org/api/cli/

webpack --config webpack.conf.js
nicojs commented 6 years ago

@rexmq could you try to see if version 0.14.0 of the stryker-karma-runner fixes your issue?

rexmq commented 6 years ago

@nicojs Thanks for the help. I just had a quick check. I assumed only source files and corresponding test files should be added in the files block. Am I correct? Anyway, I got different errors with different config.

module.exports = function(config) {
  config.set({
    files: [
      './**/*.ts',
      '!./**/*.js',
      'src/**/*.spec.ts'
    ],
    testRunner: "karma",
    mutator: "typescript",
    transpilers: ["typescript"],
    reporter: ["html", "clear-text", "progress"],
    testFramework: "jasmine",
    coverageAnalysis: "off",
    karmaConfigFile: "karma.conf.js",
    tsconfigFile: "tsconfig.json",
    mutate: ["src/**/*.ts"],
    logLevel: 'trace'
  });
};
[2018-04-09 21:52:16.978] [TRACE] TestRunnerChildProcessAdapter - [2018-04-09 21:52:16.978] [DEBUG] PluginLoader - Loading plugins stryker-jasmine

[2018-04-09 21:52:16.980] [TRACE] TestRunnerChildProcessAdapter - [2018-04-09 21:52:16.980] [DEBUG] PluginLoader - Loading plugins stryker-karma-runner

[2018-04-09 21:52:17.992] [TRACE] TestRunnerChildProcessAdapter - [2018-04-09 21:52:17.992] [DEBUG] PluginLoader - Loading plugins stryker-typescript

[2018-04-09 21:52:18.024] [TRACE] TestRunnerChildProcessAdapter - [2018-04-09 21:52:18.023] [DEBUG] IsolatedTestRunnerAdapterWorker - Changing current working directory for this process to /Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox1860436

[2018-04-09 21:52:18.025] [TRACE] TestRunnerChildProcessAdapter - [2018-04-09 21:52:18.025] [INFO] KarmaConfigReader - Importing config from "/Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox1860436/karma.conf.js"

[2018-04-09 21:52:18.027] [TRACE] TestRunnerChildProcessAdapter - [2018-04-09 21:52:18.026] [DEBUG] config - Loading config /Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox1860436/karma.conf.js

[2018-04-09 21:52:18.027] [TRACE] TestRunnerChildProcessAdapter - [2018-04-09 21:52:18.027] [ERROR] config - File /Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox1860436/karma.conf.js does not exist!

[2018-04-09 21:52:18.047] [ERROR] TestRunnerChildProcessAdapter - Child process exited with non-zero exit code 1. Last 10 message from the child process were: 
    [2018-04-09 21:52:16.954] [DEBUG] PluginLoader - Loading stryker-* from /Users/jack/workspace/disney/myproject/node_modules

    [2018-04-09 21:52:16.961] [DEBUG] PluginLoader - Loading plugins stryker-html-reporter (matched with expression stryker-*)
[2018-04-09 21:52:16.962] [DEBUG] PluginLoader - Loading plugins stryker-jasmine (matched with expression stryker-*)
[2018-04-09 21:52:16.962] [DEBUG] PluginLoader - Loading plugins stryker-karma-runner (matched with expression stryker-*)
[2018-04-09 21:52:16.962] [DEBUG] PluginLoader - Loading plugins stryker-typescript (matched with expression stryker-*)
[2018-04-09 21:52:16.962] [DEBUG] PluginLoader - Loading plugins stryker-html-reporter

    [2018-04-09 21:52:16.978] [DEBUG] PluginLoader - Loading plugins stryker-jasmine

    [2018-04-09 21:52:16.980] [DEBUG] PluginLoader - Loading plugins stryker-karma-runner

    [2018-04-09 21:52:17.992] [DEBUG] PluginLoader - Loading plugins stryker-typescript

    [2018-04-09 21:52:18.023] [DEBUG] IsolatedTestRunnerAdapterWorker - Changing current working directory for this process to /Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox1860436

    [2018-04-09 21:52:18.025] [INFO] KarmaConfigReader - Importing config from "/Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox1860436/karma.conf.js"

    [2018-04-09 21:52:18.026] [DEBUG] config - Loading config /Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox1860436/karma.conf.js

    [2018-04-09 21:52:18.027] [ERROR] config - File /Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox1860436/karma.conf.js does not exist!

[2018-04-09 21:52:18.047] [ERROR] StrykerCli - an error occurred Test runner child process exited with non-zero exit code 1
rexmq commented 6 years ago

Another try with error.

module.exports = function(config) { config.set({ files: [ '!./**/*.ts', './**/*.js', 'src/**/*.spec.ts' ], testRunner: "karma", mutator: "typescript", transpilers: ["typescript"], reporter: ["html", "clear-text", "progress"], testFramework: "jasmine", coverageAnalysis: "off", karmaConfigFile: "karma.conf.js", tsconfigFile: "tsconfig.json", mutate: ["src/**/*.ts"], logLevel: 'trace' }); };

[2018-04-09 21:55:54.315] [DEBUG] TranspilingLanguageService - Pulling file into memory: /Users/jack/workspace/disney/myproject/node_modules/@types/q/index.d.ts [2018-04-09 21:55:54.318] [DEBUG] TranspilingLanguageService - Pulling file into memory: /Users/jack/workspace/disney/myproject/node_modules/@types/recaptcha/index.d.ts [2018-04-09 21:55:54.321] [DEBUG] TranspilingLanguageService - Resolving lib file lib.dom.d.ts to /Users/jack/workspace/disney/myproject/node_modules/typescript/lib/lib.dom.d.ts [2018-04-09 21:55:54.321] [DEBUG] TranspilingLanguageService - Pulling file into memory: lib.dom.d.ts [2018-04-09 21:55:54.414] [DEBUG] TranspilingLanguageService - Resolving lib file lib.scripthost.d.ts to /Users/jack/workspace/disney/myproject/node_modules/typescript/lib/lib.scripthost.d.ts [2018-04-09 21:55:54.415] [DEBUG] TranspilingLanguageService - Pulling file into memory: lib.scripthost.d.ts [2018-04-09 21:55:54.416] [DEBUG] TranspilingLanguageService - Resolving lib file lib.es5.d.ts to /Users/jack/workspace/disney/myproject/node_modules/typescript/lib/lib.es5.d.ts [2018-04-09 21:55:54.416] [DEBUG] TranspilingLanguageService - Pulling file into memory: lib.es5.d.ts [2018-04-09 21:55:54.442] [DEBUG] TranspilingLanguageService - Resolving lib file lib.es2015.iterable.d.ts to /Users/jack/workspace/disney/myproject/node_modules/typescript/lib/lib.es2015.iterable.d.ts [2018-04-09 21:55:54.442] [DEBUG] TranspilingLanguageService - Pulling file into memory: lib.es2015.iterable.d.ts [2018-04-09 21:55:54.445] [DEBUG] TranspilingLanguageService - Resolving lib file lib.es2015.symbol.d.ts to /Users/jack/workspace/disney/myproject/node_modules/typescript/lib/lib.es2015.symbol.d.ts [2018-04-09 21:55:54.445] [DEBUG] TranspilingLanguageService - Pulling file into memory: lib.es2015.symbol.d.ts [2018-04-09 21:55:54.445] [DEBUG] TranspilingLanguageService - Resolving lib file lib.es2015.promise.d.ts to /Users/jack/workspace/disney/myproject/node_modules/typescript/lib/lib.es2015.promise.d.ts [2018-04-09 21:55:54.445] [DEBUG] TranspilingLanguageService - Pulling file into memory: lib.es2015.promise.d.ts [2018-04-09 21:55:57.678] [ERROR] StrykerCli - an error occurred Error: Emit error! Could not emit file /Users/jack/workspace/disney/myproject/bs-config.js at TranspilingLanguageService.emit (/Users/jack/workspace/disney/myproject/node_modules/stryker-typescript/src/transpiler/TranspilingLanguageService.js:76:19) at /Users/jack/workspace/disney/myproject/node_modules/stryker-typescript/src/TypescriptTranspiler.js:53:60 at arrayMap (/Users/jack/workspace/disney/myproject/node_modules/lodash.flatmap/index.js:140:21) at map (/Users/jack/workspace/disney/myproject/node_modules/lodash.flatmap/index.js:1928:10) at flatMap (/Users/jack/workspace/disney/myproject/node_modules/lodash.flatmap/index.js:1881:22) at TypescriptTranspiler.transpileFiles (/Users/jack/workspace/disney/myproject/node_modules/stryker-typescript/src/TypescriptTranspiler.js:46:16) at TypescriptTranspiler.transpile (/Users/jack/workspace/disney/myproject/node_modules/stryker-typescript/src/TypescriptTranspiler.js:29:36) at TranspilerFacade. (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/transpiler/TranspilerFacade.js:30:65) at step (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:129:27) at Object.next (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:110:57) at /Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:103:75 at Object.__awaiter (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:99:16) at TranspilerFacade.performTranspileChain (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/transpiler/TranspilerFacade.js:23:24) at TranspilerFacade.transpile (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/transpiler/TranspilerFacade.js:19:21) at InitialTestExecutor. (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/process/InitialTestExecutor.js:78:63) at step (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:129:27) at Object.next (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:110:57) at /Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:103:75 at Object.awaiter (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:99:16) at InitialTestExecutor.transpileInputFiles (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/process/InitialTestExecutor.js:72:24) at InitialTestExecutor. (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/process/InitialTestExecutor.js:31:51) at step (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:129:27) at Object.next (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:110:57) at /Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:103:75 at Object.awaiter (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:99:16) at InitialTestExecutor.run (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/process/InitialTestExecutor.js:25:24) at Stryker. (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/Stryker.js:53:68) at step (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:129:27) at Object.next (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:110:57) at fulfilled (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:100:62)

nicojs commented 6 years ago

stryker-karma-runner v0.14.0 is compatible with the latest version of stryker (0.21.1). You should also upgrade that version (and all other plugins). After that you should be able to just leave out files entirely, Stryker will discover them automatically.

Right now, it seems that your karma.conf.js is missing from the sandbox.

rexmq commented 6 years ago

@nicojs I got some different errors.

Stryker installation done. [2018-04-12 23:16:09.657] [INFO] ConfigReader - Using stryker.conf.js in the current working directory. [2018-04-12 23:16:11.153] [INFO] TypescriptConfigEditor - Loading tsconfig file /Users/jack/workspace/disney/myproject/tsconfig.json [2018-04-12 23:16:11.716] [INFO] InputFileResolver - Found 407 of 877 file(s) to be mutated. [2018-04-12 23:16:11.720] [INFO] InitialTestExecutor - Starting initial test run. This may take a while. [2018-04-12 23:16:17.800] [ERROR] StrykerCli - an error occurred Error: Emit error! Could not emit file /Users/jack/workspace/disney/myproject/stryker.conf.js at TranspilingLanguageService.emit (/Users/jack/workspace/disney/myproject/node_modules/stryker-typescript/src/transpiler/TranspilingLanguageService.js:76:19) at /Users/jack/workspace/disney/myproject/node_modules/stryker-typescript/src/TypescriptTranspiler.js:53:60 at arrayMap (/Users/jack/workspace/disney/myproject/node_modules/lodash.flatmap/index.js:140:21) at map (/Users/jack/workspace/disney/myproject/node_modules/lodash.flatmap/index.js:1928:10) at flatMap (/Users/jack/workspace/disney/myproject/node_modules/lodash.flatmap/index.js:1881:22) at TypescriptTranspiler.transpileFiles (/Users/jack/workspace/disney/myproject/node_modules/stryker-typescript/src/TypescriptTranspiler.js:46:16) at TypescriptTranspiler.transpile (/Users/jack/workspace/disney/myproject/node_modules/stryker-typescript/src/TypescriptTranspiler.js:29:36) at TranspilerFacade. (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/transpiler/TranspilerFacade.js:30:65) at step (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:129:27) at Object.next (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:110:57) at /Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:103:75 at Object.__awaiter (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:99:16) at TranspilerFacade.performTranspileChain (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/transpiler/TranspilerFacade.js:23:24) at TranspilerFacade.transpile (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/transpiler/TranspilerFacade.js:19:21) at InitialTestExecutor. (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/process/InitialTestExecutor.js:78:63) at step (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:129:27) at Object.next (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:110:57) at /Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:103:75 at Object.awaiter (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:99:16) at InitialTestExecutor.transpileInputFiles (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/process/InitialTestExecutor.js:72:24) at InitialTestExecutor. (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/process/InitialTestExecutor.js:31:51) at step (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:129:27) at Object.next (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:110:57) at /Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:103:75 at Object.awaiter (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:99:16) at InitialTestExecutor.run (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/process/InitialTestExecutor.js:25:24) at Stryker. (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/Stryker.js:53:68) at step (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:129:27) at Object.next (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:110:57) at fulfilled (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:100:62)

├─┬ stryker@0.22.0 ├─┬ UNMET PEER DEPENDENCY stryker-api@0.16.0 ├─┬ stryker-html-reporter@0.13.1 ├── stryker-jasmine@0.8.1 ├─┬ stryker-karma-runner@0.14.2 ├─┬ stryker-typescript@0.10.1

.gitignore file
node_modules/
npm-debug.log
.sass-cache/
dist/
*.iml
complexity-report/
coverage/
.idea/
.DS_Store
.travis.yml.bak
.dockerignore
df-app
nginx.conf
startnginx.sh
stryker.conf.js
module.exports = function(config) {
  config.set({
    testRunner: "karma",
    mutator: "typescript",
    transpilers: ["typescript"],
    reporter: ["html", "clear-text", "progress"],
    testFramework: "jasmine",
    coverageAnalysis: "perTest",
    karmaConfigFile: "karma.conf.js",
    tsconfigFile: "tsconfig.json",
    mutate: ["src/**/*.ts"]
  });
};
nicojs commented 6 years ago

Apparently, the stryker.conf.js itself is included in your typescript project. Do you have the --allowJS option turned on?

In any case, the TypescriptTranspiler shouldn't crash here. That is definitely a bug.

A few work arounds on the top of my mind:

  1. Set --allowJS to false.
  2. Add a files array to your stryker.conf.js file with only the files in your typescript project.
  3. Add stryker.conf.js to the excluded files in your tsconfig.json.
nicojs commented 6 years ago

sorry, reopening was a mistake, better to create a separate issue for it

nicojs commented 6 years ago

I assumed only source files and corresponding test files should be added in the files block. Am I correct? Anyway, I got different errors with different config.

Not entirely true. In files you specify which files need to end up in your sandbox directory (in this case /.stryker-tmp/sandbox1860436 for example). Stryker makes copies of your project in order to be able to run in isolation. So for example: karma.conf.js would also be needed in your sandbox directory. Too bad the typescript transpiler is wrong in assuming that a js file needs to emit output.

I might have some time tomorrow to fix that issue. In the mean time, could you try to add all js files to excluded files in your tsconfig.json?

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#examples

rexmq commented 6 years ago

I tried below and found another weird error. I had to delete the .stryker-tmp folder every time after an execution of 'stryker run'. It failed otherwise. Below result was trying with the tsconfig suggested by you before.

tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "allowJs": true,
    "alwaysStrict": true,
    "sourceMap": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "scripthost",
      "es5",
      "es2015.iterable",
      "es2015.promise"
    ]
  },
  "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts",
        "config/*.js",
        "*.js"
    ]
}

The result is below.

[2018-04-14 00:33:39.379] [TRACE] TestRunnerChildProcessAdapter - webpack: wait until bundle finished: 

[2018-04-14 00:33:46.663] [TRACE] TestRunnerChildProcessAdapter - 
[at-loader] Using typescript@2.5.3 from typescript and "tsconfig.json" from /Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox2596306/tsconfig.json.

[2018-04-14 00:34:56.335] [TRACE] TestRunnerChildProcessAdapter - 
[at-loader] Checking started in a separate process...

[2018-04-14 00:34:57.544] [ERROR] TestRunnerChildProcessAdapter - 
[at-loader] Checking finished with 20 errors

[2018-04-14 00:34:58.008] [ERROR] TestRunnerChildProcessAdapter - 
ERROR in Entry module not found: Error: Can't resolve './vendor.ts' in '/Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox2596306/src'

ERROR in Entry module not found: Error: Can't resolve './app.ts' in '/Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox2596306/src'

ERROR in ./src/app.js
Module not found: Error: Can't resolve './app/app.ts' in '/Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox2596306/src'
 @ ./src/app.js 3:0-23
 @ ./config/spec-bundle.js

ERROR in [at-loader] ./src/app/common/directives/search/search-box.directive.spec.ts:597:31 
    TS2304: Cannot find name 'SearchBoxMessage'.

ERROR in [at-loader] ./src/app/common/directives/sub-nav/sub-nav.component.spec.ts:17:14 
    TS2304: Cannot find name 'SubNavComponent'.

ERROR in [at-loader] ./src/app/common/directives/sub-nav/sub-nav.component.spec.ts:18:17 
    TS2304: Cannot find name 'SubNavItem'.

ERROR in [at-loader] ./src/app/common/directives/sub-nav/sub-nav.component.spec.ts:19:18 
    TS2304: Cannot find name 'SubNavItem'.

ERROR in [at-loader] ./src/app/common/directives/variant-select/variant-select.component.spec.ts:14:14 
    TS2304: Cannot find name 'VariantSelectComponent'.

ERROR in [at-loader] ./src/app/compare/compare.component.spec.ts:26:14 
    TS2304: Cannot find name 'CompareComponent'.

ERROR in [at-loader] ./src/app/compare/compare.component.spec.ts:364:33 
    TS2304: Cannot find name 'SearchBoxMessage'.

ERROR in [at-loader] ./src/app/compare/ratings/ratings.component.spec.ts:15:14 
    TS2304: Cannot find name 'CompareRatingsComponent'.

ERROR in [at-loader] ./src/app/compare/replace/compare-replace.component.spec.ts:12:14 
    TS2304: Cannot find name 'CompareReplaceComponent'.

ERROR in [at-loader] ./src/app/compare/review-panel/review-panel.component.spec.ts:11:14 
    TS2304: Cannot find name 'CompareReviewPanelComponent'.

ERROR in [at-loader] ./src/app/compare/specifications/specifications.component.spec.ts:5:31 
    TS2306: File '/Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox2596306/src/app/compare/specifications/specifications.js' is not a module.

ERROR in [at-loader] ./src/app/compare/specifications/specifications.component.spec.ts:17:22 
    TS2304: Cannot find name 'CarDetailsModel'.

ERROR in [at-loader] ./src/app/compare/specifications/specifications.component.spec.ts:18:23 
    TS2304: Cannot find name 'CarDetailsModel'.

ERROR in [at-loader] ./src/app/compare/specifications/specifications.component.spec.ts:19:18 
    TS2304: Cannot find name 'CompareSpecificationsComponent'.

ERROR in [at-loader] ./src/app/compare/variant-select/compare-variant-select.component.spec.ts:10:14 
    TS2304: Cannot find name 'CompareVariantSelectComponent'.

ERROR in [at-loader] ./src/app/footer/footer.component.spec.ts:7:13 
    TS2304: Cannot find name 'VrumFooterComponent'.

ERROR in [at-loader] ./src/app/get-a-quote/get-a-quote.controller.spec.ts:73:28 
    TS2304: Cannot find name 'UserDetails'.

ERROR in [at-loader] ./src/app/home/home-search.controller.spec.ts:48:31 
    TS2304: Cannot find name 'SearchBoxMessage'.

ERROR in [at-loader] ./src/app/navbar/navbar.directive.spec.ts:98:31 
    TS2304: Cannot find name 'SearchBoxMessage'.

ERROR in [at-loader] ./src/app/similar-cars/search/similar-cars-search.controller.spec.ts:42:31 
    TS2304: Cannot find name 'SearchBoxMessage'.

[2018-04-14 00:34:58.008] [TRACE] TestRunnerChildProcessAdapter - webpack: Failed to compile.

[2018-04-14 00:34:58.119] [TRACE] TestRunnerChildProcessAdapter - webpack: Compiling...

[2018-04-14 00:35:01.016] [TRACE] TestRunnerChildProcessAdapter - 
[at-loader] Checking started in a separate process...

[2018-04-14 00:35:01.020] [ERROR] TestRunnerChildProcessAdapter - 
[at-loader] Checking finished with 20 errors

[2018-04-14 00:35:01.149] [ERROR] TestRunnerChildProcessAdapter - 
ERROR in Entry module not found: Error: Can't resolve './vendor.ts' in '/Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox2596306/src'

ERROR in Entry module not found: Error: Can't resolve './app.ts' in '/Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox2596306/src'

ERROR in ./src/app.js
Module not found: Error: Can't resolve './app/app.ts' in '/Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox2596306/src'
 @ ./src/app.js 3:0-23
 @ ./config/spec-bundle.js

ERROR in [at-loader] ./src/app/common/directives/search/search-box.directive.spec.ts:597:31 
    TS2304: Cannot find name 'SearchBoxMessage'.

ERROR in [at-loader] ./src/app/common/directives/sub-nav/sub-nav.component.spec.ts:17:14 
    TS2304: Cannot find name 'SubNavComponent'.

ERROR in [at-loader] ./src/app/common/directives/sub-nav/sub-nav.component.spec.ts:18:17 
    TS2304: Cannot find name 'SubNavItem'.

ERROR in [at-loader] ./src/app/common/directives/sub-nav/sub-nav.component.spec.ts:19:18 
    TS2304: Cannot find name 'SubNavItem'.

ERROR in [at-loader] ./src/app/common/directives/variant-select/variant-select.component.spec.ts:14:14 
    TS2304: Cannot find name 'VariantSelectComponent'.

ERROR in [at-loader] ./src/app/compare/compare.component.spec.ts:26:14 
    TS2304: Cannot find name 'CompareComponent'.

ERROR in [at-loader] ./src/app/compare/compare.component.spec.ts:364:33 
    TS2304: Cannot find name 'SearchBoxMessage'.

ERROR in [at-loader] ./src/app/compare/ratings/ratings.component.spec.ts:15:14 
    TS2304: Cannot find name 'CompareRatingsComponent'.

ERROR in [at-loader] ./src/app/compare/replace/compare-replace.component.spec.ts:12:14 
    TS2304: Cannot find name 'CompareReplaceComponent'.

ERROR in [at-loader] ./src/app/compare/review-panel/review-panel.component.spec.ts:11:14 
    TS2304: Cannot find name 'CompareReviewPanelComponent'.

ERROR in [at-loader] ./src/app/compare/specifications/specifications.component.spec.ts:5:31 
    TS2306: File '/Users/jack/workspace/disney/myproject/.stryker-tmp/sandbox2596306/src/app/compare/specifications/specifications.js' is not a module.

ERROR in [at-loader] ./src/app/compare/specifications/specifications.component.spec.ts:17:22 
    TS2304: Cannot find name 'CarDetailsModel'.

ERROR in [at-loader] ./src/app/compare/specifications/specifications.component.spec.ts:18:23 
    TS2304: Cannot find name 'CarDetailsModel'.

ERROR in [at-loader] ./src/app/compare/specifications/specifications.component.spec.ts:19:18 
    TS2304: Cannot find name 'CompareSpecificationsComponent'.

ERROR in [at-loader] ./src/app/compare/variant-select/compare-variant-select.component.spec.ts:10:14 
    TS2304: Cannot find name 'CompareVariantSelectComponent'.

ERROR in [at-loader] ./src/app/footer/footer.component.spec.ts:7:13 
    TS2304: Cannot find name 'VrumFooterComponent'.

ERROR in [at-loader] ./src/app/get-a-quote/get-a-quote.controller.spec.ts:73:28 
    TS2304: Cannot find name 'UserDetails'.

ERROR in [at-loader] ./src/app/home/home-search.controller.spec.ts:48:31 
    TS2304: Cannot find name 'SearchBoxMessage'.

ERROR in [at-loader] ./src/app/navbar/navbar.directive.spec.ts:98:31 
    TS2304: Cannot find name 'SearchBoxMessage'.

ERROR in [at-loader] ./src/app/similar-cars/search/similar-cars-search.controller.spec.ts:42:31 
    TS2304: Cannot find name 'SearchBoxMessage'.

[2018-04-14 00:35:01.149] [TRACE] TestRunnerChildProcessAdapter - webpack: Failed to compile.

[2018-04-14 00:35:01.174] [DEBUG] TimeoutDecorator - Starting timeout timer (300000 ms) for a test run
[2018-04-14 00:35:01.643] [TRACE] TestRunnerChildProcessAdapter - PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  Error: Cannot find module "./app/app.ts"
  at undefined:3

[2018-04-14 00:35:01.698] [TRACE] TestRunnerChildProcessAdapter - 
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  Error: Cannot find module "./app/app.ts"
  at undefined:3

[2018-04-14 00:35:01.648] [INFO] KarmaTestRunner - karma run done with  1

[2018-04-14 00:35:01.700] [ERROR] InitialTestExecutor - One or more tests resulted in an error:
    Error: Cannot find module "./app/app.ts"
at undefined:3
[2018-04-14 00:35:01.700] [ERROR] StrykerCli - an error occurred Error: Something went wrong in the initial test run
    at InitialTestExecutor.validateResult (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/process/InitialTestExecutor.js:123:15)
    at InitialTestExecutor.<anonymous> (/Users/jack/workspace/disney/myproject/node_modules/stryker/src/process/InitialTestExecutor.js:42:30)
    at step (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:129:27)
    at Object.next (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:110:57)
    at fulfilled (/Users/jack/workspace/disney/myproject/node_modules/tslib/tslib.js:100:62)
    at process._tickCallback (internal/process/next_tick.js:109:7)
simondel commented 6 years ago

@nicojs If .stryker-tmp is not in your .gitignore file Stryker will add it to the files that have been copied to the sandbox.

We could:

  1. Add .stryker-tmp to the gitignore file if they have one
  2. Always delete the .stryker-tmp folder whenever we start Stryker
  3. Filter out the .stryker-tmp folder when we get the files from Git

EDIT: I cannot confirm the error related to the stryker-tmp folder in the robobar example, but then again that's just JavaScript and not TypeScript