-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix(webpack-dev-server): add typeRoots to generated tsconfig for angular #27117
Conversation
6 flaky tests on run #48898 ↗︎
Details:
commands/net_stubbing.cy.ts • 3 flaky tests • 5x-driver-webkitcypress/cypress.cy.js • 3 flaky tests • 5x-driver-webkit
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like two things are happening here:
- the actual fix, which is to add
types: ["cypress"]
to thetsconfig.json
- write the
tsconfig.cypress.json
to the local repo
In the interest of getting this fixed asap, I wonder if we want a PR that just adds the fix, not any changes to the behavior?
My concern with the change is the tsconfig.json
we generate will contain hard coded paths, which include the user's username:
{
"extends": "/Users/lachlanmiller/code/dump/angular-app/tsconfig.app.json",
"compilerOptions": {
"outDir": "/Users/lachlanmiller/code/dump/angular-app/out-tsc/cy",
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"types": [
"cypress"
]
},
"include": [
"/Users/lachlanmiller/code/dump/angular-app/**/*.cy.ts",
"/Users/lachlanmiller/code/dump/angular-app/cypress/support/component.ts"
]
Which means the committed files will only work on the original developer's machine. This is a blocker.
Happy to work towards having a local file, but we will need to fix this issue. In the meantime, how about a separate patch that addresses the core issue, and figure out the path issue separately (unless you know a fix right now).
@@ -256,11 +254,11 @@ const expectGeneratesTsConfig = async (devServerConfig: AngularWebpackDevServerC | |||
outDir: toPosix(path.join(projectRoot, 'out-tsc/cy')), | |||
allowSyntheticDefaultImports: true, | |||
skipLibCheck: true, | |||
types: ['cypress'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So just to confirm, this is the fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually that is not the fix. The issue is because we are using a temp file for the tsconfig
any types that get added to the extended tsconfig
types
array aren't able to resolve. Currently we manually add the Cypress types to the includes
array. But with this option we don't need to do this and we just just cypress
to that types
array.
We could potentially resolve those paths sourcing typeRoots
from the extended tsconfig
but it still doesn't allow users to make any additional changes to the tsconfig. Having a tsconfig.cypress.json
follows the same ergonomics of a typical Angular project tsconfig.app.json
, tsconfig.spec.json
, etc
…cypress-io/cypress into jordanpowell88/angular-tsconfig
Good call out, I changed the generated |
…cypress-io/cypress into jordanpowell88/angular-tsconfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is 1 issue with the setup for nx workspaces which is an invalided path in the generated tsconfig, that would require some change to land the PR behavior as is without breaking existing Nx workspaces. though I personally think the behavior could be tweaked some to work better with existing Nx workspaces.
Talking with @jordanpowell88 I understand why the change is warranted, but is there a way to instead use the tsconfig in the cypress
directory if it is present in the projectRoot
or a way to tell Cypress Angular CT to generate/use a specific file instead of just defaulting to <projectRoot>/tsconfig.cypress.json
Couple of reasons for this.
- this adds another tsconfig in the project root for nx workspaces which can already be a lot, ideally we can tell cypress to generate in a sub directory 'cypress' folder to help keep things tidy. not a cypress specific issue but something that would be nice to help prevent config overload on our (Nx) side.
- Cypress already recommends using a tsconfig.json in the cypress directory so it would be advantageous to keep it there for consistency (if directory is present in the projectRoot) IMO.
thanks for giving me the heads up and letting me check out the changes before hand. helps a lot!
includePaths.push(toPosix(cypressConfig.supportFile)) | ||
const supportPath = toPosix(path.relative(workspaceRoot, cypressConfig.supportFile)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This path being generated in an nx workspace creates a wrong path.
in an nx workspace we setup cypress in a sub directory of the project root.
i.e.
./ (git root)
└──
apps/
└── angular-app/
├── cypress/
│ └── tsconfig.json
├── src/
├── cypress.config.ts
├── project.json
├── tsconfig.app.json
├── tsconfig.cypress.json
├── tsconfig.editor.json
├── tsconfig.json
└── tsconfig.spec.json
the current impl, creates this tsconfig
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/cy",
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"types": ["cypress"]
},
"include": [
"src/**/*.cy.ts",
"src/**/*.cy.js",
"apps/angular-app/cypress/support/component.ts"
]
}
which is invalid causing type errors when building form the missing component.ts
file
The value would need to be
"cypress/support/component.ts"
I believe in angular cli workspace the workspaceRoot and projectRoot are the same values, but in nx they are not. So maybe using projectRoot here instead.
I agree having one less To loop back to the actual problem
I'm actually a bit confused now - why does changing the location of the @barbados-clemens it would be great if we could use the |
We should be able to resolve it by keeping it temporary and adding The other option is what this PR introduces which is the ability for others to just manage the tsconfig themselves. It's a trade off each case. |
To the
Is this intended behavior? Just to clarify, a minimal reproduction would be: {
"extends": "/tmp/tsconfig.json
} ^^^^^^^^ will not resolve (Could be misunderstanding your comment) |
Co-authored-by: Stokes Player <stokes@cypress.io>
Any thoughts on this @jordanpowell88 ? |
…cypress-io/cypress into jordanpowell88/angular-tsconfig
}, | ||
include: includePaths, | ||
}) | ||
}, null, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this was just to get pretty formatting? Still needed since this is dumping to a temp dir?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed, but makes it "pretty"er 🤣
Co-authored-by: Stokes Player <stokes@cypress.io> Co-authored-by: Chris Breiding <chrisbreiding@users.noreply.github.com> Co-authored-by: Jordan <jordan@jpdesigning.com> Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net> Co-authored-by: Matt Henkes <mjhenkes@gmail.com> Co-authored-by: Chris Breiding <chrisbreiding@gmail.com> fix: Fix web worker creation within spec frame (#27313) fix: Handle privileged commands arg mutation (#27282) fix(webpack-dev-server): add typeRoots to generated tsconfig for angular (#27117) fix memory import (#27324)
Additional details
Currently in order to generate a webpack config for Angular Component Testing we pass configuration options from the
angular.json
file or thedevServer.options
and atsconfig
file to the angular compiler. Currently we generate a newtsconfig.json
file and writes to a temp directory on your machine every time theanglerHandler
is called. Because the generatedtsconfig
file is located in a temp directorytypes
from the extendedtsconfig.app.json
file are unable to resolve without definingtypeRoots
. This PR adds the project roottypeRoots
to the generatedtsconfig
.Steps to test
yarn dev
and open an angular project that has a type in to thetsconfig.app.json
types array.How has the user experience changed?
PR Tasks
cypress-documentation
?type definitions
?