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

Trouble configuring project with angular + jest + typescript #672

Closed
borsini opened this issue Mar 30, 2018 · 5 comments
Closed

Trouble configuring project with angular + jest + typescript #672

borsini opened this issue Mar 30, 2018 · 5 comments
Assignees
Labels
🚀 Feature request New feature request

Comments

@borsini
Copy link

borsini commented Mar 30, 2018

Summary

Hi !

I'm having trouble configuring stryker on an angular + yarn + jest + typescript project.
My test suite works well using yarn jest. Here is the commit if you want to reproduce : borsini/simple-home-accounting@c685cbe
Any help would be fantastic ☺️

I first met this error :

[2018-03-30 13:33:23.655] [INFO] ConfigReader - Using stryker.conf.js in the current working directory.
[2018-03-30 13:33:23.889] [INFO] TypescriptConfigEditor - Loading tsconfig file C:\...\simple-home-accounting\tsconfig.json
[2018-03-30 13:33:53.320] [INFO] InputFileResolver - Found 19 of 63 file(s) to be mutated.
[2018-03-30 13:33:53.324] [INFO] InitialTestExecutor - Starting initial test run. This may take a while.
[2018-03-30 13:33:59.035] [ERROR] InitialTestExecutor - One or more tests resulted in an error:
        : ● Validation Error:

  Module <rootDir>/node_modules/jest-preset-angular/preprocessor.js in the transform option was not found.

  Configuration Documentation:
  https://facebook.github.io/jest/docs/configuration.html

● Validation Error:

  Module <rootDir>/node_modules/jest-preset-angular/preprocessor.js in the transform option was not found.

  Configuration Documentation:
  https://facebook.github.io/jest/docs/configuration.html

[2018-03-30 13:33:59.036] [ERROR] StrykerCli - an error occurred Error: Something went wrong in the initial test run
    at InitialTestExecutor.validateResult (C:\...\simple-home-accounting\node_modules\stryker\src\process\InitialTestExecutor.js:98:15)
...

My jest configuration uses an angular preset. I added the preprocessor.js file into stryker.conf.js, but now I have the following error. It seems stryker tries to transpile it. It is clearly not the solution...

[2018-03-30 13:31:54.611] [INFO] ConfigReader - Using stryker.conf.js in the current working directory.
[2018-03-30 13:31:54.868] [INFO] TypescriptConfigEditor - Loading tsconfig file C:\...\simple-home-accounting\tsconfig.json
[2018-03-30 13:32:48.518] [INFO] InputFileResolver - Found 19 of 64 file(s) to be mutated.
[2018-03-30 13:32:48.522] [INFO] InitialTestExecutor - Starting initial test run. This may take a while.
[2018-03-30 13:32:54.443] [ERROR] StrykerCli - an error occurred Error: Could not find file: 'C:\...\simple-home-accounting\node_modules\jest-preset-angular\preprocessor.js'.
    at getValidSourceFile (C:\...\simple-home-accounting\node_modules\typescript\lib\typescript.js:91389:23)
    at Object.getSemanticDiagnostics (C:\...\simple-home-accounting\node_modules\typescript\lib\typescript.js:91620:36)
    at C:\...\simple-home-accounting\node_modules\stryker-typescript\src\transpiler\TranspilingLanguageService.js:54:92
    at arrayMap (C:\...\simple-home-accounting\node_modules\lodash.flatmap\index.js:140:21)
    at map (C:\...\simple-home-accounting\node_modules\lodash.flatmap\index.js:1928:10)
    at flatMap (C:\...\simple-home-accounting\node_modules\lodash.flatmap\index.js:1881:22)
    at TranspilingLanguageService.getSemanticDiagnostics (C:\...\simple-home-accounting\node_modules
...

Stryker config

module.exports = function(config){
  config.set({
    files: [
      { pattern: "**/node_modules/jest-preset-angular/preprocessor.js"  }, // Commenting this line results in a jest error
      {
        pattern: "**/components/**/*.ts",
        mutated: true,
        included: false
      }
    ],
    tsconfigFile: 'tsconfig.json',
    mutator: 'typescript',
    transpilers: [
        'typescript'
    ],
    testRunner: 'jest',
    reporter: ['progress', 'clear-text', 'dots', 'html', 'event-recorder'],
    coverageAnalysis: 'off',
    plugins: ['stryker-jest-runner', 'stryker-html-reporter', 'stryker-typescript']
  });
}

Jest config (package.json)

{
...
  "jest": {
    "preset": "jest-preset-angular",
    "roots": [
      "<rootDir>/src/"
    ],
    "setupFiles": [
      "<rootDir>/src/polyfills.ts"
    ],
    "testRegex": "/__tests__/.*test.ts$"
  }
}

Stryker environment

Your Environment

software version(s)
node 8.9.4
npm 5.6.0
Operating System Windows 64 bits
@nicojs
Copy link
Member

nicojs commented Mar 30, 2018

Hi @Benlemen thanks for trying out stryker!

The challenge with Jest is that it needs the node_modules folder directly located next to your sourcefiles. In a Stryker sandbox, this is not the case. The stryker sandbox can be found under <project-root>/.stryker-tmp/sandbox123/. Normal require('...') (or import) statements work as expected because NodeJS will look for node_modules in any of the parent directories as well. The way to fix it for now is to add your plugins to your test sandbox (include them in the files globbing patterns).

We're thinking of a solution for this problem by symlinking the node_modules into the sandbox directories. @simondel did an test with this setup and it seems to work for jest. We're just not sure if it might have side effects for other setups so we might not enable it by default, but via a config setting. @simondel what do you think?

@nicojs
Copy link
Member

nicojs commented Apr 3, 2018

How about symlinkNodeModulesInSandboxes (true by default). It's a long name, but explains what it does.

@simondel
Copy link
Member

simondel commented Apr 4, 2018

@nicojs that config setting sounds good! It's long but if you read it, you may know what it does. Making it shorter will make it more complex.

@simondel
Copy link
Member

simondel commented Apr 6, 2018

As discussed with @nicojs symlinkNodeModules may also be descriptive enough. We may want to swap the name around so the default value would be false, for example using noSymlinkNodeModules. That way users should enable the feature instead of disabling it.

Let's not support this using the commandline for now, only using the config.

@simondel simondel added 🚀 Feature request New feature request backlog and removed backlog labels Apr 6, 2018
@nicojs
Copy link
Member

nicojs commented Apr 6, 2018

We may want to swap the name around so the default value would be false, for example using noSymlinkNodeModules

Well... Let's leave the default to indeed symlink. I see this solution helping more people that way. We'll leave the option to not symlink node modules.

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

No branches or pull requests

3 participants