Skip to content

"Create from Component" with special characters in component filename can scaffold incorrect spec name and non-working import/mount #23492

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

Closed
marktnoonan opened this issue Aug 22, 2022 · 3 comments · Fixed by #24864
Assignees
Labels
CT Issue related to component testing

Comments

@marktnoonan
Copy link
Contributor

marktnoonan commented Aug 22, 2022

Current behavior

Currently if I choose the catchall route component named [...all].vue we scaffold the spec as normal, but with the name l.spec.ts, and our import statements are (pretty naturally) non-functional because the filename happens to include a [.

Later I noticed this also happens with filenames like new-component.vue where we generate import new-component from './components/new-component.vue' and cy.mount(new-component), which are invalid JavaScript. Hyphens in filenames seem very common so we should handle them gracefully.

Screen Shot 2022-08-22 at 10 47 38 AM
Screen Shot 2022-08-22 at 10 31 31 AM
Screen Shot 2022-08-22 at 10 33 03 AM

Desired behavior

For the internal import name, Cypress should

  • strip all characters from the file name that are not valid in JS variable names before generating import ${filename}, or
  • name the import component or something predictable so that the filename will never be used as JS, and we don't have to think it about it.

This version of the spec is valid and runs:

import component from './pages/[...all].vue'

describe('<[...all] />', () => {
  it('renders', () => {
    // see: https://test-utils.vuejs.org/guide/
    cy.mount(component)
  })
})

Screen Shot 2022-08-22 at 10 49 05 AM

For the filename, [...all].spec.ts is a valid spec name, and we should preserve the literal name of the component. Seems possible the extra periods are running afoul of some regex we use for the extensions maybe.

We have lots of tests around spec filenames displaying correctly in the Specs List with various characters and languages (e.g. d~e(f)g.spec.js), we could use some component files with those same non-English word names to test generating specs.

In general I think there are filename conventions using special characters beyond this specific case, so it would be good to handle them predictably, even if it's not possible to do it elegantly right away.

Test code to reproduce

In the app package, open Cypress component testing and choose "New Spec" then "Create from Component", and attempt to create a spec from [...all].vue.

Cypress Version

develop

Node version

16.14.2

Operating System

MacOS

Debug Logs

No response

Other

No response

@marktnoonan marktnoonan changed the title "Create from Component" edge case - with special characters in component filename can scaffold incorrect spec name and non-working import/mount "Create from Component" with special characters in component filename can scaffold incorrect spec name and non-working import/mount Nov 16, 2022
@baus
Copy link

baus commented Nov 22, 2022

@rockindahizzy rockindahizzy added the CT Issue related to component testing label Nov 22, 2022
@mike-plummer mike-plummer self-assigned this Nov 28, 2022
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: review and removed stage: product backlog stage: needs review The PR code is done & tested, needs review labels Nov 28, 2022
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 30, 2022

The code for this is done in cypress-io/cypress#24864, 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 Dec 6, 2022

Released in 12.0.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Dec 6, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants