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

CT Public API docs #5069

Merged
merged 15 commits into from
Feb 24, 2023
Merged

CT Public API docs #5069

merged 15 commits into from
Feb 24, 2023

Conversation

lmiller1990
Copy link
Contributor

@lmiller1990 lmiller1990 commented Feb 16, 2023

closes cypress-io/cypress#25800

Docs for the new Framework Definitions feature. Epic: cypress-io/cypress#25637 (linked to all relevant issues).

@vercel
Copy link

vercel bot commented Feb 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
cypress-documentation ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 24, 2023 at 8:06PM (UTC)

Copy link
Contributor

@mike-plummer mike-plummer left a comment

Choose a reason for hiding this comment

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

Couple wording suggestions and questions, but overall this is awesome content!

One total nitpick - the screenshots have 12.6.0 but this feature is marked as 12.7+

docs/guides/component-testing/third-party-definitions.mdx Outdated Show resolved Hide resolved
docs/guides/component-testing/third-party-definitions.mdx Outdated Show resolved Hide resolved
docs/guides/component-testing/third-party-definitions.mdx Outdated Show resolved Hide resolved
docs/guides/component-testing/third-party-definitions.mdx Outdated Show resolved Hide resolved
docs/guides/component-testing/third-party-definitions.mdx Outdated Show resolved Hide resolved
docs/guides/component-testing/third-party-definitions.mdx Outdated Show resolved Hide resolved
docs/guides/component-testing/third-party-definitions.mdx Outdated Show resolved Hide resolved
docs/guides/component-testing/third-party-definitions.mdx Outdated Show resolved Hide resolved
docs/guides/component-testing/third-party-definitions.mdx Outdated Show resolved Hide resolved
@mike-plummer mike-plummer requested a review from a team February 17, 2023 15:28
@elylucas
Copy link
Contributor

We should probably update the supported frameworks to also mention community libraries with a link to this guide and link to a list of community libs.

Where would be a good place to list the community libraries in the docs? My initial thoughts is we can remove the older CT libs from the component testing section in plugins and list them there.


The second part of defining a Framework Definition is the Mount Adapter. This is the function that renders the component in your tests using `cy.mount()`.

By default, Cypress will look for this as a `mount` function that is a **named export** from the package. This should be written in a `index.mjs` file. This example is for a [Solid.js](https://www.solidjs.com/) mount adapter:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should be showing the examples in TypeScript and highly recommending that TS is used in their own libraries.

We might even think about putting together a starter template that someone could just clone and it would have building and bundling baked in.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, I see reading further down there is a template, but I think that should be updated to TypeScript with the build steps built in (like above). This will help ensure that the Typings get created and (🌶) all libs should be built in TS.

Copy link
Contributor

Choose a reason for hiding this comment

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

might be good to mention the template earlier in the guide as well

Copy link
Contributor Author

@lmiller1990 lmiller1990 Feb 20, 2023

Choose a reason for hiding this comment

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

I did not do this initially since I thought it added quite a bit of complexity. The build step is a little messy. Cypress (the server component) will always require the CJS entry - in this case, definition.cjs. Both our bundlers (webpack and vite) want an ES module. We would need two separate build steps - one for the Node.js entry and one for the ESM entry.

I updated the template to have TypeScript by default. It has two tsconfig.json - one for the server entry (definition) and one for the mount entry (esm). Take a look and let me know what you think @elylucas: https://github.com/cypress-io/cypress-ct-definition-template

I also updated my own example to use this template: https://github.com/lmiller1990/cypress-ct-solid-js

docs/guides/component-testing/third-party-definitions.mdx Outdated Show resolved Hide resolved
Co-authored-by: Ely Lucas <ely@meta-tek.net>
Co-authored-by: Mike Plummer <mike-plummer@users.noreply.github.com>

## Testing

If you develop the Framework Definition file using TypeScript, for example by using [our official template](https://github.com/cypress-io/cypress-ct-definition-template), as long as you don't have any compile time errors, everything should work as expected. If you do run into unexpected behavior, please [file an issue](https://github.com/cypress-io/cypress/issues).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Worth noting we've got better warnings for definitions coming VERY soon (next sprint) cypress-io/cypress#25838 but they are not supported right now. The issue requires the docs to be updated when they are added.

Copy link
Contributor Author

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

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

@elylucas @mike-plummer thanks for the reviews, I have done my best to address all comments. I also updated the official template to include TypeScript and my own example to use it.

@lmiller1990
Copy link
Contributor Author

Will merge once 12.7 goes out with https://github.com/cypress-io/cypress/pull/25780/files in it.

Copy link
Contributor

@astone123 astone123 left a comment

Choose a reason for hiding this comment

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

Not sure if I'm looking at the wrong deployment, but I'm seeing the entire page inside of the "info" banner 🤔

Screenshot 2023-02-21 at 7 46 07 AM


// Wait until next microtick to ensure any async render logic has executed
return cy.wait(0, { log: false }).then(() => {
if (options.log) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work unless we check the value of options.log. We're assuming that it's true here but that's not the case unless it is explicitly set. Should we change this to

Suggested change
if (options.log) {
if (options.log !== false) {

@astone123
Copy link
Contributor

@lmiller1990 do you think we should mention dev server support at all? Maybe suggest a way to give users a custom dev server function to drop into their config until we build support for that? Is that something that we want to encourage? Not sure 🤔

@lmiller1990
Copy link
Contributor Author

@astone123

  • Banner CSS - what on earth, will look
  • options.log- will fix
  • custom dev server - we could add a link to our custom dev server docs, but those are kind of bad. If we could get a proper example (eg Preact) that'd be much more useful. I thought about a "caveats" section but it seems like too much information for the tiny group of developers who'd actually want to build a custom dev server. I'd love to see some better docs in general around this... We've got this but it's not exactly the most useful... :|

@lmiller1990
Copy link
Contributor Author

Banner looks good to me, tested locally - maybe preview was an old commit?

Screenshot 2023-02-22 at 12 45 54 pm

@elylucas
Copy link
Contributor

@lmiller1990 do you think we should mention dev server support at all? Maybe suggest a way to give users a custom dev server function to drop into their config until we build support for that? Is that something that we want to encourage? Not sure 🤔

I think this is a good idea. I've been trying to throw together one and the point I got stuck on was getting the dev server up and running. One project was vite and the other is a custom dev server and couldn't really get either working. Would be good to know (and update the custom dev server section under framework configuration) how to set one up from scratch.

@elylucas
Copy link
Contributor

Banner looks good to me, tested locally - maybe preview was an old commit?

Screenshot 2023-02-22 at 12 45 54 pm

It got messed up in a commit suggestion, I pushed a quick fix for it in #81e6b7e

@ryanthemanuel ryanthemanuel changed the base branch from main to release-12.6.1 February 24, 2023 20:08
@ryanthemanuel ryanthemanuel merged commit d09ffc8 into release-12.6.1 Feb 24, 2023
@ryanthemanuel ryanthemanuel deleted the lmiller/ct-public-api-docs branch February 24, 2023 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document CT Third Party Definitions API
5 participants