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

Allow Angular CT configuration to accept custom project configurations #23161

Closed
ZachJW34 opened this issue Aug 5, 2022 · 5 comments · Fixed by #23494
Closed

Allow Angular CT configuration to accept custom project configurations #23161

ZachJW34 opened this issue Aug 5, 2022 · 5 comments · Fixed by #23494
Assignees
Labels
CT Issue related to component testing type: enhancement Requested enhancement of existing feature

Comments

@ZachJW34
Copy link
Contributor

ZachJW34 commented Aug 5, 2022

What would you like?

Angular CT setup should support custom build options to accommodate projects that don't follow the Angular CLI conventions.

Why is this needed?

To support projects that use Angular but don't adhere to Angular CLI conventions (particularly apps created with @nrwl/nx)

Other

We developed Angular CT for projects utilizing @angular/cli. There are conventions with Angular CLI created projects that we rely on, such as sourcing a project's build options via their angular.json. Nx is a popular monorepo tooling solution that supports Angular projects but don't follow the same conventions. The build options are the same, but their source can differ (configurations can be stored in workspace.json or project level project.json configuration files).

We can extend support by allowing these build options to be passed in explicitly (in the cypress.config.ts). Support could look like:

export const defineConfig({
  component: {
    devServer: {
      framework: 'angular',
      bundler: 'webpack',
      // New Options object
      options: {
        projectConfig: { ... }
      },
    },
  },
})

We will probably have to normalize what the projectConfig contains. For Angular CLI projects, the type we expect is:

export type AngularJsonProjectConfig = {
  projectType: string
  root: string
  sourceRoot: string
  architect: {
    build: {
      options: { [key: string]: any } & { polyfills?: string }
      configurations?: {
        [configuration: string]: {
          [key: string]: any
        }
      }
    }
  }
}

We need the root, sourceRoot, options and configuration['<key>'] information, but the json for Nx's workspace.json/project.json might differ so we can condense it to:

type ProjectConfig = {
  root: string
  sourceRoot: string
  buildOptions: Record<key, any>
}

where we assume the buildOptions conform to the Angular builder schema. Rough outline but should fit the bill.

We also assume a tsconfig.json that we extend from, but this might need to be configurable as well.

@ZachJW34 ZachJW34 added the CT Issue related to component testing label Aug 5, 2022
@nagash77 nagash77 added the type: enhancement Requested enhancement of existing feature label Aug 8, 2022
@jordanpowell88 jordanpowell88 self-assigned this Aug 9, 2022
@ruimonteiro88
Copy link

ruimonteiro88 commented Aug 17, 2022

Hi guys, were are using nx and we are having problems configuring component testing (angular).
Is there an ETA on this issue?
Thanks :)

@NicBright
Copy link

Hi @ZachJW34

We also assume a tsconfig.json that we extend from, but this might need to be configurable as well.

It seems you're assuming the tsconfig.json is sitting around in the root directory. However, in my project, the path is src/tsconfig.app.json. This can be configured in angular.json, so I suggest you try to get it from there:

{
    ...
    "projects": {
        "project-name": {
            ...
            "architect": {
                "build": {
                    "builder": "@angular-devkit/build-angular:browser",
                    "options": {
                        ....
                        "tsConfig": "src/tsconfig.app.json",
                        ...

A workaround I'm currently using is having a "forwarding tsconfig.json" in my root folder extending from src/tsconfig.app.json.

Best Regards,
Nic

@ZachJW34
Copy link
Contributor Author

@ruimonteiro88 we are prioritizing this issue so we should be getting around to it this week or the next

@NicBright we should be able to extend the provided tsconfig (which would eliminate the need to assume where it is). I think we decided on the root due to not wanting to include certain files in the compilation but we could override the tsconfig.files property so that it suites our purposes

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 25, 2022

The code for this is done in cypress-io/cypress#23494, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 30, 2022

Released in 10.7.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v10.7.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Aug 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CT Issue related to component testing type: enhancement Requested enhancement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants