Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
unlight opened this issue Sep 24, 2017 · 8 comments
Closed

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

unlight opened this issue Sep 24, 2017 · 8 comments

Comments

@unlight
Copy link

unlight commented Sep 24, 2017

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
Copy link
Author

unlight commented Sep 24, 2017

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
Copy link
Member

nicojs commented Sep 25, 2017

@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
Copy link
Author

unlight commented Sep 26, 2017

Versions:

I see only this typescript related definition files:

[DEBUG] TranspilingLanguageService - �[39mPulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.d.ts
[DEBUG] TranspilingLanguageService - �[39mPulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.core.d.ts
[DEBUG] TranspilingLanguageService - �[39mPulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.collection.d.ts
[DEBUG] TranspilingLanguageService - �[39mPulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.generator.d.ts
[DEBUG] TranspilingLanguageService - �[39mPulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.promise.d.ts
[DEBUG] TranspilingLanguageService - �[39mPulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.iterable.d.ts
[DEBUG] TranspilingLanguageService - �[39mPulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.symbol.d.ts
[DEBUG] TranspilingLanguageService - �[39mPulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.proxy.d.ts
[DEBUG] TranspilingLanguageService - �[39mPulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.reflect.d.ts
[DEBUG] TranspilingLanguageService - �[39mPulling file into memory: C:/xxx/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts
[DEBUG] TranspilingLanguageService - �[39mPulling 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
Copy link
Member

nicojs commented Sep 27, 2017

@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
Copy link
Author

unlight commented Sep 27, 2017

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

@unlight
Copy link
Author

unlight commented Oct 1, 2017

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

@unlight unlight closed this as completed Oct 1, 2017
@nicojs
Copy link
Member

nicojs commented Oct 1, 2017

@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
Copy link
Author

unlight commented Oct 1, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants