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

feat: create-cypress-tests installation wizard #9563

Merged
merged 102 commits into from
Mar 5, 2021

Conversation

dmtrKovalenko
Copy link
Contributor

@dmtrKovalenko dmtrKovalenko commented Dec 8, 2020

This PR adds a new project that can be run as yarn create cypress-tests or npx create-cypress-tests to install cypress and all required dependencies including component tests.

Features of this approach:

  1. Fails if user git status contains untracked or uncommitted changes
  2. Automatically determines yarn or npm to use
  3. Copies and creates plugins and support files so the developer can instantly start writing tests without yarn cypress open
  4. Determines if the project is using typescript and injects tsconfig.json
  5. Has --ignore-examples option, which will create a dummy spec file from scratch so if the user will open cypress initially it won't create examples.
  6. Asks for component testing, determine which framework (vue or react) is using and installs the right framework adapter
  7. All the required configuration for component testing is automagically injected right to the user config using babel

Things to do

Test it right now:

Run yarn create cypress-tests-beta or npx create-cypress-tests-beta to check how it works.

Quick demo:
demoThis PR adds a new project that can be run as yarn create cypress-tests or npx create-cypress-tests to install cypress and all required dependencies including component tests.

Features of this approach:

  1. Fails if user git status contains untracked or uncommitted changes
  2. Automatically determines yarn or npm to use
  3. Copies and creates plugins and support files so the developer can instantly start writing tests without yarn cypress open
  4. Determines if the project is using typescript and injects tsconfig.json
  5. Has --ignore-examples option, which will create a dummy spec file from scratch so if the user will open cypress initially it won't create examples.
  6. Asks for component testing, determine which framework (vue or react) is using and installs the right framework adapter
  7. All the required configuration for component testing is automagically injected right to the user config using babel

Things to do

@dmtrKovalenko
Copy link
Contributor Author

@dmtrKovalenko dmtrKovalenko requested a review from a team March 2, 2021 14:26
@jennifer-shehane
Copy link
Member

@dmtrKovalenko Is this meant to close this issue? #619

Will this also close this PR? #6249

@dmtrKovalenko
Copy link
Contributor Author

@jennifer-shehane It's not inside cypress npm package. It's more like create-react-app, but the idea is same - simplify installation process especially for component testing.

lmiller1990
lmiller1990 previously approved these changes Mar 3, 2021
Copy link
Contributor

@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.

I see why this PR is so massive now - all the different templates to consider, and their tests and snapshots. I was not expecting you to use babel to hook into the compilation, but this seems like a clean way to inject code! I suppose this is normally how it's done? Never seen the source code for a wizard before.

The tests looks solid so as long as you are confident it works, I think it's fine. My main concern will be around cypress.json, since we may also support cypress.js soon too, so we cannot assume JSON. That said, I think we can just do require('./cypress.js').experimentalComponentTesting to see if they are using CT, so the idea should be the same.

I will drop a ✔️ for now - I did not give this a test by hand yet, though, but I can do that if you think it's necessary.

"plugins": [
"cypress",
"@cypress/dev"
],
Copy link
Contributor

Choose a reason for hiding this comment

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

eslint has an extends feature, I wonder if we can use that to save the boilerplate

}

async function injectAndShowCypressJsonConfig (
cypressJsonPath: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

This might get a whole lot more complex with this PR: #15280

Since we cannot assume JSON. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that may be a pain in the ass. But I think we can resolve this later, but we already using babel so injecting a new key should be pretty easy

@lmiller1990
Copy link
Contributor

Hi, I cannot try it :(

$ y global add cypress-tests-beta
yarn global v1.22.10
[1/4] 🔍  Resolving packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/cypress-tests-beta: Not found".
info If you think this is a bug, please open a bug report with the information provided in "/Users/lachlan/.config/yarn/global/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.
$ yarn create-cypress-tests
yarn run v1.22.10
error Command "create-cypress-tests" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
$ yarn create create-cypress-tests
yarn create v1.22.10
[1/4] 🔍  Resolving packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/create-create-cypress-tests: Not found".
info If you think this is a bug, please open a bug report with the information provided in "/Users/lachlan/.config/yarn/global/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.
$ yarn create cypress-tests
yarn create v1.22.10
[1/4] 🔍  Resolving packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/create-cypress-tests: Not found".
info If you think this is a bug, please open a bug report with the information provided in "/Users/lachlan/.config/yarn/global/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.
$ yarn create cypress-tests

Copy link
Contributor

@elevatebart elevatebart left a comment

Choose a reason for hiding this comment

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

In MS Azure there is status saying: "Approved with suggestions..."

type: 'list',
name: 'framework',
choices: Object.keys(frameworks),
message: `Which framework do you use?`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
message: `Which framework do you use?`,
message: `Choose a framework to install`,

import { version } from '../package.json'

program
.option('--ignore-examples', 'Ignore generating example tests and fixtures by creating one ready-to-fill spec file')
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not lcear what this option do. I think we could find a better name for it
Does it create an example?
Does it make an empty spec instead?

@@ -10,16 +10,16 @@
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
// Cypress.Commands.add('login', (email, password) => { ... })
Copy link
Contributor

Choose a reason for hiding this comment

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

hum....

Copy link
Contributor

@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.

I still got this error (using the latest version - I pulled this branch and built it):

This project is using react. Let's install the right adapter:
✔ Installing @cypress/react (yarn add @cypress/react --dev)
? We were not able to automatically determine which framework or bundling tool you are using.
Please choose one from the list: default (webpack options)
? Which folder would you like to use for your component tests? src

Installing required dependencies

✔ Installing @cypress/webpack-dev-server (yarn add @cypress/webpack-dev-server --dev)

Let's setup everything for component testing with default (webpack options):

✅  cypress.json was updated with the following config:

{
  "experimentalComponentTesting": true,
  "componentFolder": "src",
  "testFiles": "**/*.spec.{js,ts,jsx,tsx}"
}

✅  cypress/support/index.js was updated with the following config:

import '@cypress/react/support'

Error: ENOENT: no such file or directory, open '/Users/lachlan/code/dump/cy-draw/dist/src/component-testing/templates/react/webpack-options-module-exports.template.js'
    at Object.openSync (fs.js:462:3)
    at Object.readFileSync (fs.js:364:35)
    at Object.getPluginsCodeAst (/Users/lachlan/code/dump/cy-draw/dist/src/component-testing/templates/react/webpack-options.js:42:64)
    at injectAndShowPluginConfig (/Users/lachlan/code/dump/cy-draw/dist/src/component-testing/init-component-testing.js:73:26)
    at Object.initComponentTesting (/Users/lachlan/code/dump/cy-draw/dist/src/component-testing/init-component-testing.js:127:11)
    at async Object.main (/Users/lachlan/code/dump/cy-draw/dist/src/main.js:72:9) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/lachlan/code/dump/cy-draw/dist/src/component-testing/templates/react/webpack-options-module-exports.template.js'
}

Happy to approve for now so we can this HUGE PR merged, we can make little improvements as we go. Thoughts @dmtrKovalenko? webpack-options-module-exports.template.js seems to be not included in the build.

Can pair later with you if you want to test more.

@dmtrKovalenko
Copy link
Contributor Author

@lmiller1990 I did fix the error here ab9707d

@dmtrKovalenko dmtrKovalenko merged commit c405ee8 into develop Mar 5, 2021
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.

5 participants