-
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: add codegen utility #18708
feat: add codegen utility #18708
Conversation
Thanks for taking the time to open a PR!
|
Test summaryRun details
View run in Cypress Dashboard ➡️ Flakiness
This 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.
Left a few questions.
The actual infrastructure, which is the point of this PR, seems to work fine - I tried it out.
The actual codegen snippets need work - guessing that is outside the scope of this PR? For example I generated this for the launchpad project:
import { mount } from "@cypress/vue"
import App from "./App.vue"
describe('<App />', () => {
it('renders', () => {
// see: https://reactjs.org/docs/test-utils.html
mount(App, { props: {} })
})
})
Several weird things:
- empty props object doesn't seem very useful
- has link to react docs for my Vue component?
Might be good to make an issue to go over the snippets. Having snapshots for these would help greatly, since we wouldn't need to generate them manually to test them.
Do you plan to add snapshot tests as well (either here or later?)
}, | ||
vue: { | ||
imports: [ | ||
'import { mount } from "@cypress/vue"', | ||
'import { composeStories } from "@storybook/testing-vue3"', | ||
`import * as stories from "./${this.parsedPath.name}"`, | ||
], | ||
mount: (StoryName: string) => `mount(${StoryName}())`, | ||
stories: csf.stories.map((story) => { |
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.
Will the above imports
eventually move to a codegen file as well? (as opposed to inlined here?)
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.
They could be. Right now we're not looping within ejs.
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 was mostly wiring it up to the old way of generating specs. I agree, a lot of the options could and should be moved into the template files. We could even have a vue-component
and a react-component
template if we didn't want to muddy the templates with too much logic. I'll create an issue for cleaning up the templates.
const isBinary = await isBinaryFile(file) | ||
const parsedFile = path.parse(file) | ||
|
||
const processBinaryFile = async () => { |
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.
What is the use case for this? Are we ever generated a binary file? What kind of 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.
pngs
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.
380c277
to
e28a986
Compare
@lmiller1990 Fixed the vue docs link. Snapshot testing and cleaner templates will be nice so I'll create an issue for it. |
Looks like #18714 will fix the failing |
4c60d41
to
979960a
Compare
…ve-activeProject * unified-desktop-gui: (57 commits) chore: Add e2e tests for global mode (#18719) chore: add percy to app and launchpad package (#18781) chore: update test refactor: move settings in app (#18729) feat: setup launchpad lifecycle (#18734) feat(app): decouple event manager from driver (#18695) chore: Force single resolution for core modules, infinite loop guard (#18764) fix(driver): Sticky elements within a fixed container will not prevent an element from being scrolled to (#18441) chore: cleaning up the runner container pattern (#18741) feat: Use .config files (#18578) chore(app): basic style and example to stop scrollIntoView bug (#18736) chore: make `create` function on server.ts obsolete (#18615) feat: add codegen utility (#18708) docs: Add instructions to squash commits to develop in Contributing (#18728) fix(@cypress/react): throw if using Next.js swc-loader without nodeVersion=system (#18686) refactor: remove Ramda (#18723) fix: support using create-cypress-tests as part of build process (#18714) chore: Increase paralleled machines for desktop-gui tests (#18725) fix(app): do not cache graphql (#18716) chore: Update Chrome (stable) to 95.0.4638.69 (#18696) ...
Details
This PR adds the ability to generate files from ejs templates as well as normal text/binary files. Given a directory, the
codeGenerator
function will recursively grab all files within the specified directory and move them to the specified destination whilst preserving the folder structure. Any values passed will be interpolated into the files if the file is using standard ejs templating syntax. Files also support the use of front-matter to specify custom filenames that aren't static. An example use case for the Cypress config case would look like:This PR also replaces the current solution for generating specs from component/story/integration. The data-model for handling the generated files via graphql can be improved but I thought I'd keep the current model for now since there is active work ongoing with the current graphql endpoints involving spec generation.
The video below shows the result of running
yarn workspace @packages/data-context test-unit
. The given templateDir istemplate-test
and target istmp/test-code-gen/test
.Screen.Recording.2021-10-29.at.1.46.35.PM.mov
Testing
The
packages/data-context/test/unit/code-generator.spec.ts
test checks the output of the code-generator and also parses thestory, component, integration
templates to verify that we are producing valid javascript given valid arguments. Thepackages/app/cypress/e2e/integration/new-spec.spec.ts
e2e test also generates from these templates given a real world app. This flow can also be tested by runningyarn dev
and navigating to__vite__/#/newspec
in the runner.How has the user experience changed?
PR Tasks
cypress-documentation
?type definitions
?cypress.schema.json
?