Skip to content

Component testing framework docs #3883

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

Merged
merged 26 commits into from
May 6, 2021
Merged

Conversation

lmiller1990
Copy link
Contributor

resolves: #3882

We should have some basic quick start guides for popular configurations. I think a single page like this is probably a good start.

@@ -0,0 +1,26 @@
---
title: Framework Specific Guides
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking out loud here of a better title for this page. If we're keeping it scoped to configuration then here are some options:

  1. Framework Configuration
  2. Framework Setup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put "Framework Configuration" for now, but I think we can probably think of something a little better. Let's keep thinking.

I added Next.js 4/5, I'll keep working through the other major frameworks (CRA, Nuxt).

@lmiller1990 lmiller1990 marked this pull request as ready for review April 30, 2021 01:23
@lmiller1990 lmiller1990 requested a review from amirrustam April 30, 2021 01:24
@lmiller1990
Copy link
Contributor Author

lmiller1990 commented Apr 30, 2021

@amirrustam I finished documenting all the different frameworks (at least the popular ones I've seen people using, and we have adapters for). Can you please give me a review? Also, do you think it's worth also including a link to a repo with everything set up for each example?

return startDevServer({
options,
viteConfig: {
configFile: path.resolve(__dirname, '..', '..', 'vite.config.js'),
Copy link
Contributor

Choose a reason for hiding this comment

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

I've using it yesterday and I add type error on the configFile which is UserConfig and not InlineConfig (which permits configFile attribute)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean an inline vite config?

const { startDevServer } = require('@cypress/vite-dev-server')

module.exports = (on, config) => {
on('dev-server:start', (options) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also I got error when the support file is missing. You can try and see the error when support/index.js is not present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not able to reproduce this - I deleted support but it still seems okay. Can you share a reproduction?

I shared all of my examples here: https://github.com/lmiller1990/cypress-component-examples

@lmiller1990
Copy link
Contributor Author

@edimitchel I pushed some updates, mainly including links to example projects.

@amirrustam who else best to add as a reviewer?

Copy link
Contributor

@amirrustam amirrustam left a comment

Choose a reason for hiding this comment

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

This is a great start. There are various quick fixes to wrap things up. I'll push up some commits to just knock them out.

@lmiller1990 lmiller1990 merged commit d8bddf9 into master May 6, 2021
@lmiller1990 lmiller1990 deleted the component-testing-framework-docs branch May 6, 2021 14:06
Copy link
Contributor

@cowboy cowboy left a comment

Choose a reason for hiding this comment

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

Apologies for the late feedback, I should have mentioned that I was reviewing!

Once you have a React project, you'll also need to install the Cypress Webpack Dev Server and React adapter, as well as some devDependencies:

```sh
npm install --save-dev cypress @cypress/vue @cypress/webpack-dev-server html-webpack-plugin@4
Copy link
Contributor

Choose a reason for hiding this comment

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

@cypress/vue -> @cypress/react


### Vue 3 (Vue CLI)

The installation and configuration is the same as Vue 2 with the Vue CLI as described above. The only difference is the Vue adapter should be installed using `npm install @cypress/vue@next` - `@cypress/vue` target Vue 2, and the `next` branch targets Vue 3.
Copy link
Contributor

Choose a reason for hiding this comment

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

target -> targets ?


Recent years have seen an explosion in component based libraries (Vue, React) and frameworks built on top of them (Nuxt, Next). Cypress tests are written and behave the same regardless. Some frameworks require some additional configuration to work correctly with Cypress component testing.

All the example projects described in this page can be found [here](https://github.com/lmiller1990/cypress-component-examples).
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these component examples be moved into a repo in the cypress org?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, will do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Next configure the dev-server to use the same Webpack configuration used by Create React App. We can do this easily using the `react-scripts` plugin provided by Cypress:

```js
const injectDevServer = require('@cypress/react/plugins/react-scripts')
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be helpful if this document explained where this code goes. I can see it in the cypress-component-examples repo and also in a comment in a code block in the @cypress/react docs but I had to search for it.


it('renders learn react link', () => {
mount(<App />)
cy.get('a').contains('Learn React')
Copy link
Contributor

Choose a reason for hiding this comment

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

In my local testing, this causes an eslint error, because cy is not imported. In order to suppress this error, I had to:

  • npm install --save-dev eslint-plugin-cypress
  • Add "plugin:cypress/recommended" to the package.json eslintConfig.extends array

An alternative would be to import cy from 'cypress'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting, I did not get this. I will investigate eslint a little more, it would be good if we could do this on our end perhaps, so the user does not need to mess with linting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better docs for CT specific frameworks (next.js, etc)
5 participants