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

fix: do not cache module resolution during launchpad dependency detection #26726

Merged
merged 7 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
## 12.13.0
lmiller1990 marked this conversation as resolved.
Show resolved Hide resolved

_Released 05/23/2023 (PENDING)_

**Bugfixes:**

- Fixed an issue where newly installed dependencies are not correct detected during Component Testing setup. Addresses [#26685](https://github.com/cypress-io/cypress/issues/26685).
lmiller1990 marked this conversation as resolved.
Show resolved Hide resolved

## 12.12.0

_Released 05/09/2023_
Expand Down
41 changes: 40 additions & 1 deletion packages/launchpad/cypress/e2e/scaffold-component-testing.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,20 @@ describe('scaffolding component testing', {
// should detect correctly
cy.get('button').should('be.visible').contains('React.js(detected)')
cy.get('button').contains('Next step').click()
cy.findByRole('button', { name: 'Continue' }).click()

for (const dep of ['vite', 'react', 'typescript']) {
cy.findByTestId(`dependency-${dep}`).within(() => {
cy.get('[aria-label="installed"]').should('exist')
})
}

// this project is intentionally missing this dependency
cy.findByTestId('dependency-react-dom').within(() => {
cy.get('[aria-label="pending installation"]').should('exist')
})

cy.get('button').contains('Skip').click()

verifyConfigFile(`cypress.config.ts`)
})

Expand All @@ -102,6 +115,32 @@ describe('scaffolding component testing', {
cy.get(`[data-testid="select-framework"]`)

cy.get('button').should('be.visible').contains('React.js(detected)')

cy.get('button').contains('Next step').click()

// react-dom dependency is missing
cy.findByTestId('dependency-react-dom').within(() => {
cy.get('[aria-label="pending installation"]').should('exist')
})

// fake install
cy.withCtx(async (ctx) => {
await ctx.fs.mkdirp(ctx.path.join(ctx.currentProject!, 'node_modules', 'react-dom'))
await ctx.actions.file.writeFileInProject(
ctx.path.join('node_modules', 'react-dom', 'package.json'),
JSON.stringify({
'version': '17.0.0',
}),
)
})

// Wait for new dependency detection polling
cy.wait(3000)
lmiller1990 marked this conversation as resolved.
Show resolved Hide resolved

// now it is installed, launchpad should detect it and update the UI
cy.findByTestId('dependency-react-dom').within(() => {
cy.get('[aria-label="installed"]').should('exist')
})
})
})

Expand Down
1 change: 1 addition & 0 deletions packages/launchpad/src/setup/ManualInstall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
v-for="dep in props.gql.wizard.packagesToInstall"
:key="dep.package"
class="border-b border-b-gray-100 py-[16px] last-of-type:border-b-0"
:data-cy="`dependency-${dep.package}`"
>
<i-cy-status-download-done_x24
v-if="dep.satisfied"
Expand Down
2 changes: 1 addition & 1 deletion packages/scaffold-config/src/frameworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function isDependencyInstalled (dependency: Cypress.CypressComponen
// for module resolution.
const resolvePackagePath = require('resolve-package-path')

const packageFilePath = resolvePackagePath(dependency.package, projectPath)
const packageFilePath = resolvePackagePath(dependency.package, projectPath, false)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix, the third arg is whether to cache or not - we don't want caching, or it won't find the dependency, even if the user adds it.


if (!packageFilePath) {
debug('unable to resolve dependency %s', dependency.package)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"preview": "vite preview"
},
"dependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally removed to reproduce issue in End to End test.

"react": "^18.0.0"
},
"devDependencies": {
"@types/react": "^18.0.0",
Expand Down