-
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: Use tsconfig from build if exists (closes #23673) #23696
Conversation
Thanks for taking the time to open a PR!
|
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.
Generally we wants tests for anything - especially a regression like this.
You could modify one of the projects in system-tests/angular*
to regress, than ensure it passes. Eg this one: https://github.com/cypress-io/cypress/tree/develop/system-tests/projects/angular-14.
To run that test, you would add systemTests.it.only
(otherwise it'll take a long time) then do:
cd system-tests
yarn test component_testing_spec
It should run the tests.
If you could add this, it'd be great - this could be in the next release. Otherwise, it'll still get added by someone internally, but might take a little longer.
Let me know if you need any more help to get the test working.
I did amend an existing test to ensure it uses the correct tsconfig.json. Can add an additional test to ensure it falls back to |
I could be missing something (don't know this part of the code base really well) but it looks like the test would pass either way, since if Eg, if I remove your commit, will something fail? Here's what I was thinking (just thinking out loud here): We could copy+paste The way the Then we could add an empty This way, it'll use the valid one from Let me know if 1) this makes sense (Cypress test infrastructure is pretty big and complex) or 2) I'm missing something and we don't actually need this extra test to cover the regression. |
It kind of makes sense, but as you say the test infra is pretty complex. If my commit is removed, nothing will stop working and tests will still pass (due to falling back to old behaviour w/ tsconfig.json to avoid regressions). It seems pretty straight forward to write a test like you mentioned though, so I can give that a spin :)
So the reason I decided not to write a test originally was simply that I didn't see a value to the test. Previously there were no test to verify that the user-defined tsConfig was used, but after my changes to angularHandler.spec.ts it now verifies that it uses whichever file is passed in, but still falls back to the previous behaviour (i.e using the root tsconfig.json). That doesn't necessarily mean we dont need a specific test for this, I just didn't see any value from it (and if Cypress has taught me anything, we should write valuable tests :) ) |
Changes look good! Would be good to modify |
I tried to add at test but no luck - are we sure this is working as expected? It still generated a I did buildOptions: {
projectConfig: {
tsConfig: "custom.config.json"
}
} My custom config had: {
"compilerOptions": {
"target": "es5"
}
} I think in additional to adding a test, we need to document how it behaves. Maybe in |
Eeh, it works as it should, yes. It doesnt change the generated tsconfig aside from the filename it references (since it extends it). I began writing a test myself but I never got the test to actually make any sense, since it already tests for the exact behaviour expected. @jordanpowell88 do you have any input here (I believe you did the buildOptions themselves)? |
It does, I think? |
Here is a modified version of const expectGeneratesTsConfig = async (devServerConfig: AngularWebpackDevServerConfig, buildOptions: any) => {
const { projectRoot } = devServerConfig.cypressConfig
let tsConfigPath = await generateTsConfig(devServerConfig, buildOptions)
const tempDir = await getTempDir()
expect(tsConfigPath).to.eq(path.join(tempDir, 'tsconfig.json'))
let tsConfig = JSON.parse(await fs.readFile(tsConfigPath, 'utf8'))
expect(tsConfig).to.deep.eq({
// verifies the default `tsconfig.app.json` is extended
extends: toPosix(path.join(projectRoot, 'tsconfig.app.json')),
compilerOptions: {
outDir: toPosix(path.join(projectRoot, 'out-tsc/cy')),
allowSyntheticDefaultImports: true,
skipLibCheck: true,
},
include: [
toPosix(path.join(projectRoot, 'src/**/*.cy.ts')),
toPosix(path.join(projectRoot, 'src/polyfills.ts')),
toPosix(path.join(projectRoot, 'node_modules/cypress/types/index.d.ts')),
],
})
const modifiedBuildOptions = cloneDeep(buildOptions)
delete modifiedBuildOptions.polyfills
modifiedBuildOptions.tsConfig = 'tsconfig.cy.json'
const modifiedDevServerConfig = cloneDeep(devServerConfig)
const supportFile = path.join(projectRoot, 'cypress', 'support', 'component.ts')
modifiedDevServerConfig.cypressConfig.supportFile = supportFile
tsConfigPath = await generateTsConfig(modifiedDevServerConfig, modifiedBuildOptions)
tsConfig = JSON.parse(await fs.readFile(tsConfigPath, 'utf8'))
expect(tsConfig).to.deep.eq({
// verifies the custom `tsconfig.cy.json` is extended
extends: toPosix(path.join(projectRoot, 'tsconfig.cy.json')),
compilerOptions: {
outDir: toPosix(path.join(projectRoot, 'out-tsc/cy')),
allowSyntheticDefaultImports: true,
skipLibCheck: true,
},
include: [
toPosix(path.join(projectRoot, 'src/**/*.cy.ts')),
toPosix(supportFile),
toPosix(path.join(projectRoot, 'node_modules/cypress/types/index.d.ts')),
],
}) |
Nice, let's add that test and merge this up - it can go into the next release (Tue 13th Sep). |
Falls back to tsconfig.json if one is not passed in
Added it in :) I was a bit worried originally about changing the existing tests to much, but makes sense like this :) |
Nice job! |
* chore: release @cypress/angular-v1.1.0 [skip ci] * chore: release @cypress/schematic-v2.1.0 [skip ci] * chore: release @cypress/mount-utils-v2.1.0 [skip ci] * chore: release @cypress/react-v6.2.0 [skip ci] * chore: release @cypress/react18-v1.1.0 [skip ci] * chore: release @cypress/svelte-v1.0.0 [skip ci] * chore: release @cypress/vue-v4.2.0 [skip ci] * chore: release @cypress/vue2-v1.1.0 [skip ci] * chore: release @cypress/webpack-dev-server-v2.3.0 [skip ci] * fix(cypress-schematic): suffix template files so they are not ignored (#23645) * chore: release @cypress/schematic-v2.1.1 [skip ci] * fix: Use tsconfig from build if exists (closes #23673) (#23696) Falls back to tsconfig.json if one is not passed in * feat: add support for generating angular component * feat: skip default test generation * feat: generate ct tests only if component was generated * feat: add @cypress/schematic to schematicCollections * feat: add documentation * docs: document component generation * add test * fix generate from component with dir * fix CI * add variable to job defaults * remove v13 support Co-authored-by: Mike Plummer <[email protected]> Co-authored-by: semantic-release-bot <[email protected]> Co-authored-by: Zachary Williams <[email protected]> Co-authored-by: Ronnie Laugen <[email protected]> Co-authored-by: Emily Rohrbough <[email protected]> Co-authored-by: Jordan <[email protected]> Co-authored-by: Mark Noonan <[email protected]> Co-authored-by: astone123 <[email protected]> Co-authored-by: Lachlan Miller <[email protected]> Co-authored-by: Blue F <[email protected]>
User facing changelog
Change that allows passing in a default tsConfig flag in buildOptions to angularHandler
Additional details
Allow users to pass in a specific tsconfig.json (e.g to avoid collisions with jest and similar)
Steps to test
N/A
How has the user experience changed?
N/A
PR Tasks
As a quick note - I was wondering if I should add any tests for this, but seemed like such a small change it should not warrant one. However if it seems necessary, I can look into adding a test for it.
cypress-documentation
?type definitions
?