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

typescript-stryker: Compilation fails, but tsc through npm does not #394

Closed unlight closed 7 years ago

unlight commented 7 years ago

tsconfig

{
  "compilerOptions": {
    "target": "es5",
    "allowJs": true,
    "module": "commonjs",
    "importHelpers": true,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "declaration": false,
    "pretty": true,
    "removeComments": false,
    "skipLibCheck": true,
    "strictNullChecks": true,
    "suppressExcessPropertyErrors": true,
    "suppressImplicitAnyIndexErrors": false,
    "isolatedModules": false,
    "outDir": "dist",
    "lib": [
      "dom",
      "esnext"
    ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

part of stryker.conf

    config.set({
        files: [
            { pattern: 'src/spec.module.js', mutated: false, included: true },
            { pattern: 'src/**/app.component.ts', mutated: true, included: false },
            { pattern: 'src/**/*.service.ts', mutated: false, included: false },
            { pattern: 'src/**/*.{ts,scss,html,json,png}', included: false, mutated: false },
            { pattern: 'src/app/testing/**/*.ts', included: true, mutated: false },
        ],
        testRunner: 'karma',
        testFramework: 'jasmine',
        coverageAnalysis: 'off',
        // coverageAnalysis: 'perTest',
        mutator: 'typescript',
        transpilers: ['typescript'],
        tsconfigFile: 'tsconfig.json',
        reporter: ['progress', 'html'],
        htmlReporter: {
            baseDir: '.testresults/mutation'
        },
        logLevel: 'trace',
        // maxConcurrentTestRunners: 1,
        clearTextReporter: {
            maxTestsToLog: 0
        },

When I run tsc Everything compiled ok, without errors.

When stryker run it produce a tons of errors:

core.module.ts(26,12): error TS2304: Cannot find name 'window'.
core.module.ts(30,12): error TS2304: Cannot find name 'localStorage'.
x.service.ts(35,129): error TS2339: Property 'includes' does not exist on type 'Type[]'.

In tsconfig lib dom, esnext is specified, but looks like stryker ignores it.

unlight commented 7 years ago

In trace mode, I do not see message that lib.dom.d.ts is loaded by TranspilingLanguageService Like

[DEBUG] TranspilingLanguageService - Pulling file into memory...
nicojs commented 7 years ago

@unlight thanks very much for testing out our new TypeScript support.

Your assumption is correct in that you should see a Pulling file into memory message. Take Stryker itself as an example:

[2017-09-25 22:48:40.943] [DEBUG] TranspilingLanguageService - Resolving lib file lib.es5.d.ts to C:\z\github\stryker-mutator\stryker\node_modules\typescript\lib\lib.es5.d.ts
[2017-09-25 22:48:40.943] [DEBUG] TranspilingLanguageService - Pulling file into memory: lib.es5.d.ts
[2017-09-25 22:48:40.962] [DEBUG] TranspilingLanguageService - Resolving lib file lib.es2015.promise.d.ts to C:\z\github\stryker-mutator\stryker\node_modules\typescript\lib\lib.es2015.promise.d.ts
[2017-09-25 22:48:40.963] [DEBUG] TranspilingLanguageService - Pulling file into memory: lib.es2015.promise.d.ts

Do you see any lib files at all?

Could you run in debug once more and look at the top for "[DEBUG] Stryker - Using config:". There you should also see your typescript config (read using the stryker-typescript ConfigEditor plugin). Could you verify that the lib file is displayed there?

Finally: what versions are you using for typescript and stryker?

unlight commented 7 years ago

Versions:

stryker@0.10.3
stryker-typescript@0.0.2
typescript@2.5.2

I see only this typescript related definition files:

[DEBUG] TranspilingLanguageService - Pulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.d.ts
[DEBUG] TranspilingLanguageService - Pulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.core.d.ts
[DEBUG] TranspilingLanguageService - Pulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.collection.d.ts
[DEBUG] TranspilingLanguageService - Pulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.generator.d.ts
[DEBUG] TranspilingLanguageService - Pulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.promise.d.ts
[DEBUG] TranspilingLanguageService - Pulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.iterable.d.ts
[DEBUG] TranspilingLanguageService - Pulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.symbol.d.ts
[DEBUG] TranspilingLanguageService - Pulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.proxy.d.ts
[DEBUG] TranspilingLanguageService - Pulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.reflect.d.ts
[DEBUG] TranspilingLanguageService - Pulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts
[DEBUG] TranspilingLanguageService - Pulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es5.d.ts

No esnext which is specified in tsconfig. But es2015 was specified explicitly in one of the my spec file by triple comment reference

/// <reference path="../../../node_modules/typescript/lib/lib.es2015.d.ts" />

This pushed me to an idea, and finally I was able to solve it by creating empty ts file with content:

/// <reference path="../node_modules/typescript/lib/lib.dom.d.ts" />
/// <reference path="../node_modules/typescript/lib/lib.esnext.d.ts" />

But initial run still fails for me, but for another reason.

nicojs commented 7 years ago

@unlight ok, so the finger clearly points to Stryker not loading lib files correctly. I tried to reproduce the problem in this small sample: https://github.com/nicojs/stryker-typescript-issue394

I did come across an other bug #396 , but other than that the lib files seems to be loaded fine.

Could you try out this small sample and try to reproduce the problem there?

unlight commented 7 years ago

I've just tried and issue is not reproducible there, esnext definition is loading ok. I will continue investigation in my project.

unlight commented 7 years ago

Figure out the problem. Need remove all 'path' triple reference <reference path="node_modules/typescript/lib/lib.es2015.d.ts" due to <reference no-default-lib="true"/> it prevents loading what is defined in tsconfig.lib

nicojs commented 6 years ago

@unlight ok, cool you found the problem. Just to be clear, you had <reference no-default-lib="true"/> somewhere in your code? If so, how could typescript itself compile?

Are you now able to run stryker on typescript code? Or is there some other issue your running into?

unlight commented 6 years ago

I had several references to 'lib.es2015' in my code. 'lib.es2015' contains 'reference no-default-lib' directive. I suspect that it was the reason.