-
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
feat: Enable create from Vue component for projects with custom spec patterns #23298
feat: Enable create from Vue component for projects with custom spec patterns #23298
Conversation
Thanks for taking the time to open a PR!
|
@@ -0,0 +1,5 @@ | |||
module.exports = { |
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.
The diff looks really big because I added a new project to system-tests. I needed a project that had a custom spec pattern but was a Vue project.
You should be safe to ignore any changed files under system-tests/projects/
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.
Gave it a thorough test and it worked great! Just a few comments
- Remove test project - Break tests into new spec file - Move getDefaultSpecFileName to util module
|
||
return componentPath.startsWith('.') ? componentPath : `./${componentPath}` | ||
return `./${this.parsedPath.base}` |
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.
Would ./
cause any issues for Windows?
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.
Would using path.join('./', componentPath)
resolve any issue with os specifics?
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 is for the component import path in the component e.g. import App from '<relative-path>'.js
. These should always be forward slashes, but still something we should check on Windows since we might be putting backslashes in the path where they shouldn't be.
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 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.
Yeah this should be fine on Windows because this is the path we're using to import the component in the tests. Mark tested my last PR on Windows that had similar logic and he said it worked well.
I'll try this out on my Windows VM before I merge it, anyone feel free to do the same
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.
Empty-generator is what's happening now, so that sounds OK.
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.
Gave it a try on my Windows and a spec that is generated using a custom spec-pattern
@ZachJW34 yeah I think this is happening because when I use path
in spec-options
it takes the OS into account, so the path it gives me has backslashes in it on Windows 🤔
Kind of hacky, but what do we think about just replacing \
with /
for these relative paths? I still need to use Node path
to get the relative path of the component module compared to the spec directory, but I don't want it to use OS-specific slashes because this is a relative import being written to a file
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.
Maybe we can use this function
cypress/packages/data-context/src/util/file.ts
Lines 3 to 5 in c40a120
export function toPosix (file: string, sep: string = path.sep) { | |
return file.split(sep).join(path.posix.sep) | |
} |
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.
Thanks Lachlan, this should fix the issue on Windows
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.
Yeah the replacement makes sense, we have a few examples of posixify
-ing paths in the codebase
Test summaryRun details
View run in Cypress Dashboard ➡️ FlakinessThis comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
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.
- Use object for getPathFromSpecPattern params - Use single quotes for file import in generated spec - Remove unnecessary async keyword
… github.com:cypress-io/cypress into astone123/23071-create-from-vue-custom-spec-pattern
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.
Found a bug while creating a spec from a component that already has an existing spec when using a custom spec pattern. The copy
gets appended after the .cy
, causing the spec to not match.
Screen.Recording.2022-08-15.at.10.08.27.AM.mov
@ZachJW34 it looks like that issue already exists currently for create empty spec. If you try to create a file with the same name, we append "copy" and it ends up not matching the spec pattern. We don't give a warning there either. I wonder if we could push this bug fix off into a separate issue since it already exists and is common logic between the two cards. |
What is the reproduction for the empty spec bug? I gave it a try and it seemed to be working. I ran through empty-spec generation twice for
This is the expected output and it matches the specPattern. For the create-from-component, the output was Also, I posted a comment regarding Windows import paths: #23298 (comment) |
@ZachJW34 Oh right, you wouldn't be able to see the bug with that spec pattern. I was using So in order to see it with empty, you need a custom suffix for your file names. I see that it's a different issue for create from component though, so I'll check it out |
My changes were responded to! |
I found another edge case:
|
Dismissing my review since I found a bug. |
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.
May need a mini brief around the edge cases, I am not sure the expected filename and path is clear (above behavior is expected based on current code, but certainly not what you'd want).
I found an edge case. Here's my expected output when creating a new spec:
Case 2 is problematic. I think it's because we use https://github.com/cypress-io/cypress/pull/23298/files#diff-c351c3ec7e69c56e8c57fdf49babbece37086dbb43b9fc07a386f3cd33e508c9R52. When I created a spec in a new project where the spec pattern is |
…3/23071-create-from-vue-custom-spec-pattern
sinon.restore() | ||
}); | ||
|
||
[{ testName: 'src/specs-folder/*.cy.{js,jsx}', componentPath: 'ComponentName.vue', specs: [], pattern: 'src/specs-folder/*.cy.{js,jsx}', expectedPath: 'src/specs-folder/ComponentName.cy.js' }, |
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.
Nice way to cover all the cases
Just checking if we need a re-review or should this go back to in progress? Also might be good to clarify the test plan for the various edge cases (eg what we will do for |
Okay, after looking at this some more I updated the assertions for the unit tests and fixed a couple things with extensions. This doesn't match the table that @lmiller1990 put in an earlier comment, but these do match the default file name for the empty spec generator. I'm hoping that this is good enough for now, as the plan for this wasn't to change the underlying To get an idea of the different cases that we have test coverage for and which file paths they result in, check out this test block @ZachJW34 can you verify that you can create duplicate files and the |
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.
My comments have been addressed!
One last thing I'd like to throw out, would it make sense to create the sibling path first and check to see if it matches the specPattern before calling the getDefaultSpecFileName
? This would reduce the likelihood that a spec gets generated away from it's sibling component when using a specPattern like **/*.cy.js
Just a thought, going to ✅
I also verified, copy naming bug is gone, I think this is good for now - I do expect this feature to receive lots of updates moving forward, we can address/rejig/rethink more when we get the next requirement/stories. Nice job, this one sure turned out to have some hidden complexity. |
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.
LGTM
Will leave merging to @astone123 since I think there's one more potential (optional) change that @ZachJW34 pointed out that you may or may not want to do - I'm thinking we ship this and focus on Studio/other stuff for now, though?
Yeah, I started on this but it ended up being more complicated than I originally thought, so I decided that for now we should just go with the behavior of the existing spec generator card. Will open an issue to improve this |
User facing changelog
This is a part of the create from Vue component effort. It shouldn't have its own changelog entry
Additional details
In the last create from Vue component PR, I excluded projects with custom spec patterns to separate out complexity. In order to release the feature, this also needs to work for projects with custom spec patterns.
Steps to test
How has the user experience changed?
Users will now see the "Create from component" generator card when adding a new spec to a Vue project using component testing when the project has a custom spec pattern defined in its configuration.
PR Tasks
cypress-documentation
?type definitions
?