When generating an angular app via nx-cli, either as part of an initial workspace setup, or to add to an existing ng-cli generated workspace, I expect to get all of the angular options, such as configure routing, and which testing framework to use.
When generating a new nx workspace, and choose either the angular or the angular + nest options to pre-populate an application, the nx-cli no longer asks the user which testing framework to use. It also does not ask about configuring routing.
Additionally, when adding an app to an nx-cli generated workspace, same issue. It defaults to jest, but does ask to configure routing.
Creating an empty workspace, but using nx-cli, and then adding an angular app = same result.
Creating an empty workspace, but using angular-cli to run it, and then adding an angular app works as expected.
Note: It did previously ask for the testing option before I upgraded nx-cli. I do not recall exactly what version I was running before upgrading.
Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
Please provide detailed steps for reproducing the issue.
Please provide any relevant information about your setup:
No errors reported.
Any other relevant information that will help us help you.
Per docs, you can pass the --unit-test-runner flag to specify which test runner you'd like to set up.
Using Karma
To use Karma instead of Jest, run
ng g @nrwl/angular:application frontend --unit-test-runner=karma.
Hopefully that will work for adding an application to an existing nx-generated workspace. But what about when you're generating a workspace and initializing an app at that time? I'd still consider that a bug.
The thinking is that new workspaces will want to use Jest as the default, so there isn't an option when creating new workspaces.
@FrozenPandaz @vsavkin Any thoughts? We could prompt for this when creating an app.
In angular.json, I have the following section:
// ...
"schematics": {
"@nrwl/schematics:component": {
"styleext": "scss"
},
"@nrwl/schematics:library": {
"unitTestRunner": "karma",
"framework": "angular"
},
"@nrwl/schematics:application": {
"unitTestRunner": "karma",
"e2eTestRunner": "protractor"
},
"@nrwl/schematics:node-application": {
"framework": "express"
}
}
}
However, ng g lib still uses jest. Is there something wrong with my configuration? If not, what is the point of this configuration in angular.json if the schematics don't honor it?
EDIT:
So, it seems the above configuration is outdated. It should use @nrwl/angular instead of @nrwl/schematics. This fixes my issues.
@Sharondio the guideline we use is the following:
Using a non-empty preset should ask the min number of questions possible and create a workspace with "good" defaults. Presets are great for building POC and quickly putting together projects. For anything else you should start with "empty".
So if you want to have a custom angular setup, do the following:
npx create-nx-workspace myorg --preset=empty --cli=angular
ng add @nrwl/angular
ng g app myapp --unit-test-runner=karma
If you don't want to pass unit-test-runner every time you generate an app, add the following to your angular.json:
"schematics": {
"@nrwl/angular:application": {
"unitTestRunner": "karma"
}
}
}
Does it make sense?
@vsavkin Yeah, it makes sense as a workaround, and that's ultimately what I did. But what is the difference between that approach and creating an angular-cli generated app and adding @nrwl/schematics after the fact (which also worked)?
I can accept the "good" defaults argument, but locking all future apps into the same defaults is a bit heavy-handed. I was even more confused when further apps generated in the workspace by the angular-cli defaulted to jest as well, as @adgonal mentioned above. At the very least, this could be made more clear in the documentation.
@Sharondio Agree about the docs. We should add a guide, maybe on configuring Karma and Protractor. If you would like to do it, I'll be happy to merge it.
Another thing we could do is to print a message after ng-add executes saying that the test runners are defaulted to Jest and Cypress, and pointing to the guide showing how to change to Karma and Protractor.
Folks. I"m going to close this issue.
We will use this one to track the docs update: https://github.com/nrwl/nx/issues/1903
Most helpful comment
@Sharondio Agree about the docs. We should add a guide, maybe on configuring Karma and Protractor. If you would like to do it, I'll be happy to merge it.
Another thing we could do is to print a message after
ng-addexecutes saying that the test runners are defaulted to Jest and Cypress, and pointing to the guide showing how to change to Karma and Protractor.