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

feat(testing): Support default Webstorm test runner #1467

Conversation

dopsonbr
Copy link

@dopsonbr dopsonbr commented Jun 6, 2019

feat(testing): Support default Webstorm test runner

This change adds additional jest options to builder's schema.json and maps them in jest.impl.ts.

Expected Behavior

Webstorm is able to run jest tests without updating the configuration.
Webstorm should be able to open a spec file, click the play icon for the relevant test, and the test should run without an error.

Current Behavior

Webstorm attempts to run the tests with options supported by jest but the builder.
The unknown options cause the IDE test runner to error with out running the tests.
The specific options are config, colors, reporters, verbose, and testPathPattern.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. yarn create nx-workspace my-workspace
  2. webstorm my-workspace
  3. open app.component.spec.ts
  4. click play icon

@dopsonbr dopsonbr force-pushed the feat/support-webstorm-test-runner-for-jest-builder branch 3 times, most recently from b2863fb to a6b5ae2 Compare June 10, 2019 01:29
@FrozenPandaz
Copy link
Collaborator

Hey thanks for the contribution!

How did you setup Webstorm exactly? The default test runner for me runs jest directly which works fine for React and Node apps but does not work for Angular Apps because it needs more configuration which is handled within the builder.

@dopsonbr
Copy link
Author

Hey thanks for the contribution!

How did you setup Webstorm exactly? The default test runner for me runs jest directly which works fine for React and Node apps but does not work for Angular Apps because it needs more configuration which is handled within the builder.

The default settings settings correctly configure the test runner as ng. Setting the runner directly to jest causes a different set of issues.

The specific issue is Webstorm passes arguments that are supported by jest but not implemented by the builder. The unsupported arguments result in the command failing due to unknown options.

My pull request implements the additional arguments that are supported by jest.

/Users/bxd5017/.nvm/versions/node/v12.2.0/bin/node
--require "/Users/bxd5017/Library/Application Support/JetBrains/Toolbox/apps/WebStorm/ch-1/191.7479.14/WebStorm.app/Contents/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-stdin-fix.js"
/Users/bxd5017/tmp/usom-client/node_modules/@angular/cli/bin/ng test
test-project
--colors
--reporters "/Users/bxd5017/Library/Application Support/JetBrains/Toolbox/apps/WebStorm/ch-1/191.7479.14/WebStorm.app/Contents/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-reporter.js" --verbose "
--testPathPattern='^/Users/bxd5017/tmp/test-workspace/apps/test-app/src/app/app.component\.spec\.ts$'

Unknown option: '--colors'
Unknown option: '--reporters /Users/bxd5017/Library/Application Support/JetBrains/Toolbox/apps/WebStorm/ch-1/191.7479.14/WebStorm.app/Contents/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-reporter.js'
Unknown option: '--verbose'
Unknown option: '--testPathPattern'

The exact webstorm and node version is in the above output. I used the default setup and was able to reproduce with multiple different versions of webstorm. The versions were installed with the jetbrains toolbox and the license comes from an enterprise license server. This means each install is defaults only and no settings were transferred from my personal jetbrains account.

@dartavion
Copy link

One way that allows webstorm to debug properly and not continue with the zonejs issue:

  1. Add the following jest config to the package.json and adjust where necessary:
 "jest": {
    "preset": "jest-preset-angular",
    "setupFilesAfterEnv": [
      "<rootDir>/apps/nx-jest-example/src/test-setup.ts"
    ],
    "testPathIgnorePatterns": [
      "<rootDir>/node_modules/",
      "<rootDir>/dist/",
      "<rootDir>/src/test.ts",
      "<rootDir>/apps/nx-jest-example-e2e/"
    ],
    "globals": {
      "ts-jest": {
        "diagnostics": false,
        "tsConfig": "<rootDir>/apps/nx-jest-example/tsconfig.spec.json",
        "stringifyContentPathRegex": "\\.html$",
        "astTransformers": [
          "<rootDir>/node_modules/jest-preset-angular/InlineHtmlStripStylesTransformer"
        ]
      }
    }
  }
  1. Click on the green debug icon in the WebStorm IDE gutter and select Debug.

image

  1. Change the configuration in the Edit Configurations to use the package.json instead of the jest.config

image

  1. Run debug and you should be able to debug a single test.

The test config object was also deleted from the angular.json. That is probably not be necessary since we're using the package.json to setup jest.

For now...hope this helps others that have run into this.

@mehrad-rafigh mehrad-rafigh mentioned this pull request Jul 26, 2019
4 tasks
@@ -76,6 +91,13 @@
"description": "Run only tests with a name that matches the regex pattern. (https://jestjs.io/docs/en/cli#testnamepattern-regex)",
"type": "string"
},
"testPathPattern": {
"description": "A regexp pattern string that is matched against all tests paths before executing the test.",
"type": "array",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must be type string

@@ -110,6 +128,12 @@ Type: `string`

Run only tests with a name that matches the regex pattern. (https://jestjs.io/docs/en/cli#testnamepattern-regex)

### testPathPattern

Type: `array`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must be type string

@vsavkin
Copy link
Member

vsavkin commented Aug 16, 2019

@dopsonbr could you rebase?

@vsavkin vsavkin force-pushed the master branch 2 times, most recently from 3569a53 to 54d5826 Compare August 21, 2019 15:53
@dopsonbr dopsonbr force-pushed the feat/support-webstorm-test-runner-for-jest-builder branch from a6b5ae2 to 4db3049 Compare August 25, 2019 19:10
Update jest builer to support the options config, colors, reporters, verbose, and testPathPattern.
@dopsonbr dopsonbr force-pushed the feat/support-webstorm-test-runner-for-jest-builder branch from 4db3049 to fbf3e8d Compare August 25, 2019 19:25
@dopsonbr
Copy link
Author

@vsavkin after rebasing it looks like my changes were already merged/made in a different branch. I'll check the webstorm later today with a clean project, but I'm closing the PR for now.

@dopsonbr dopsonbr closed this Aug 25, 2019
@PhilippeMorier
Copy link

Because I landed here via google... #1439 (comment) was the solution which worked for me.

  1. Add setupFilesAfterEnv: ['./src/test-setup.ts'] into you jest.config.js
  2. Run Test directly in WebStorm (first failed)
  3. Edit Configurations.. and select the proper jest.config.js as Configuration file of your app/lib

@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants