nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.55k stars 2.35k forks source link

Single Karma tests cannot be started in Webstorm #14874

Closed konstantinschuette closed 1 year ago

konstantinschuette commented 1 year ago

Current Behavior

image

When I wan't to run a test via the GUI of Webstorm, this error shows up:

/Users/konstantinschutte/.nvm/versions/node/v16.18.1/bin/node /Users/konstantinschutte/Desktop/Github/my-monorepo/node_modules/@angular/cli/bin/ng test --karma-config /Applications/WebStorm.app/Contents/plugins/js-karma/js_reporter/karma-intellij/lib/intellij.conf.js --source-map
Error: This command is not available when running the Angular CLI outside a workspace.

Process finished with exit code 1

Expected Behavior

The test should start without any error

GitHub Repo

No response

Steps to Reproduce

  1. npx create-nx-workspace --cli=angular --defaultBase=main --name=my-monorepo --nxCloud --packageManager=npm --preset=empty
  2. cd my-monorepo
  3. npm install @nrwl/angular
  4. nx generate @nrwl/angular:app foobar --style=scss --unitTestRunner=karma

Nx Report

Node : 16.18.1
   OS   : darwin arm64
   npm  : 8.19.2

   nx : 15.6.3
   @nrwl/angular : 15.6.3
   @nrwl/cypress : 15.6.3
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.6.3
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.6.3
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.6.3
   @nrwl/js : 15.6.3
   @nrwl/linter : 15.6.3
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : 15.0.3
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/webpack : 15.6.3
   @nrwl/workspace : 15.6.3
   @nrwl/vite : Not Found
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

Failure Logs

No response

Additional Information

No response

peterblazejewicz commented 1 year ago

For Angular 15 or newer there is no angular.json in NX workspace (and no support for Angular workspace concept). We have the very same issue in our team for folks using WebStorm, my bet is JetBrains plugin does not support anything else as of now (so that's not NX specific problem). The same problem with VSCode plugins for Karma tests, if they resolve project by looking for angular.json:

The NX setup/migration:

Splits your angular.json into project.json files for each project with updated paths.

https://nx.dev/recipes/adopting-nx/migration-angular

WS: https://youtrack.jetbrains.com/issue/WEB-58994/Karma-allow-choosing-nx-as-karma-package-to-run-unit-tests-in-NX-Mono-repos

konstantinschuette commented 1 year ago

For Angular 15 or newer there is no angular.json in NX workspace (and no support for Angular workspace concept). We have the very same issue in our team for folks using WebStorm, my bet is JetBrains plugin does not support anything else as of now (so that's not NX specific problem). The same problem with VSCode plugins for Karma tests, if they resolve project by looking for angular.json:

The NX setup/migration:

Splits your angular.json into project.json files for each project with updated paths.

https://nx.dev/recipes/adopting-nx/migration-angular

WS: https://youtrack.jetbrains.com/issue/WEB-58994/Karma-allow-choosing-nx-as-karma-package-to-run-unit-tests-in-NX-Mono-repos

Thank you! How do you start single tests then?

peterblazejewicz commented 1 year ago

We do not have a simple solution, for now just CLI (can be automated wtihin WS I think with shortucts for currently focused file, same in VSCode):

nx test admin --include=**/page.component.spec.ts
Coly010 commented 1 year ago

Hey all!

We no longer support using the Angular CLI as your CLI. Nx is it's own CLI.

The issue in question around Webstorm not running the single karma tests is due to lack of feature support on the IDE's part.

There is potential that you could set up a Run Configuration that uses a node script to do this for you, however, as previous comment has linked a feature request to add better Nx support to Webstorm. This issue discussion should be continued there.

Thank you for raising this!

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.