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
Angular library support ? #23677
Comments
Given source code here I try add But i got below error when compile
|
https://github.com/davidNHK/cypress-reproduce-ISSUE-23677 Turn out i can get it working by add dummy application to the workspace. I not closing the issue coz it not ideal |
Hi! Agreed, not ideal... going to tag @jordanpowell88, resident Angular expert. I wonder why not having a defaultProject leads to this 🤔 |
Because we are sourcing the information needed to configure webpack from the |
Any ideas on a recommended fix @jordanpowell88? This seems like it might be a good first issue for an external contributor, if the CT team doesn't have the bandwidth to fix this one before the next release. |
We allow the user to pass in custom project configuration options #23161. @davidNHK have you tried this? |
@ZachJW34 I haven't tried and I think ideally it should support angular library out of box. |
Hello @jordanpowell88, |
I think we should also support workspaces where we mix applications and libraries.
Or maybe we add it to the options object?
With this information we can resolve the correct webpack config instead of always going for the default project. What do you think? |
At the moment instead of passing a With that being said we certainly "could" source the correct config from the |
For me it feels unnecessary to duplicate the config which is already available within tha |
In our case we have one project in workspace and this is an angular library. So we don't need to pass project name, we just want to run tests without creating application |
If think we can just use the config from the angular.json if there is only a single project. So what do you think @jordanpowell88 ? |
Currently it requires your angular project to have a configured application, because we rely on the The caveat is that it does it using the app's globals since the lib does not . Internally, we need to determine how we want to handle scenarios like this because libraries target the |
Does this mean that cypress does not support testing of a library only setup? Is there a workaround we can use (without creating a dummy application in the same project)? |
It seems we found a workaround. After going through the normal setup procedures you have to change cypress.config.ts to the following: cypress.config.ts
You then need to create the entrypoint-cypress.ts in projects/LIBRARY-NAME/src/entrypoint-cypress.ts entrypoint-cypress.ts
The entrypoint-cypress.ts file can also be empty and it seems to work just fine. After this we are able to atleast run a test on a component. Just found this workaround, unsure if it has other side effects. |
Sorry for reviving this thread however we just cant make this work with very strange errors all over the place. Is it possible to get a sample repo of this working (preferably with Angular 13)? |
I followed the instructions on the Angular webpage to make an app, I installed Cypress and opened it with I then added a spec and it worked as expected: import { AppComponent } from '../src/app/app.component'
describe('App', () => {
it('playground', () => {
cy.mount(AppComponent)
})
}) Here is my repository: https://github.com/lmiller1990/cypress-angular-starter Angular is supported out of the box - if you find a bug, please log a new issue with a minimal reproduction and we can take a look. If we cannot reproduce the error, it's will be difficult to help. For debugging, you can do |
@lmiller1990 |
@lmiller1990 your example doesn't solve the problem. The question is specifically for a library, and your example uses an application: In the linked angular.json: This problem still exists as far as I am aware. Can this be re-opened please? |
Thank you! @geraintanderson okay, sounds like it is still an issue. I am not working on Cypress anymore, I don't think I'll be able to look into this one, maybe @jordanpowell88 has some ideas. |
The Angular project you are using will require an application because we use the Angular builder from that application along with other options from the With that being said, it should work for your libraries given it has an application. You can also try using the options API to manually configure the options we will source to configure. |
@jordanpowell88, thanks for your reply. You're right - I created a new repo to try and isolate the problem when I found this ticket, and that just had a library. When I went back to the original repo with an application & library following your comment I was eventually able to get it working on the library project. |
@geraintanderson , could you kindly provide an sample repo? I'm struggling to manage it |
Current behavior
I got
Error: Could not find a project with projectType "application" in "angular.json". Visit https://docs.cypress.io/guides/references/configuration#Options-API to see how to pass in a custom project configuration
when start cypressDesired behavior
Run test
Test code to reproduce
Follow guides to create angular library
https://angular.io/guide/creating-libraries
Follow
https://docs.cypress.io/guides/component-testing/quickstart-angular#Configuring-Component-Testing
Got the error.
Cypress Version
10.7.0
Node version
16
Operating System
Mac
Debug Logs
Other
No response
The text was updated successfully, but these errors were encountered: