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

Add cypress init command to seed / scaffold test files on current directory #619

Open
brian-mann opened this issue Sep 6, 2017 · 10 comments
Assignees
Labels
cli pkg/server This is due to an issue in the packages/server directory type: feature New feature that does not currently exist

Comments

@brian-mann
Copy link
Member

We no longer seed anything when running cypress run on a fresh project.

Instead we now error: #618

For that reason we should give users the ability to seed / scaffold out files from the command line instead of using the GUI.

Proposal add a cypress init command which does this.

Bonus points if we offer an inquirer view enabling the user to select what they want to. We could even explain what each one does.

@Knaledge
Copy link

Knaledge commented Jul 26, 2018

@brian-mann - I am running into this exact (exact) situation right now. I am so glad I found this specific issue entry here! It captures exactly what I'm running into.

Is there any ETA?

We do not have the desire to gen node_modules per project (at the moment, or even short term) as we will only be utilizing a single version of Node.js and Cypress for the foreseeable future - and technically don't have a "node" project to even work with atm ;)

Just getting this working (and I have, via desktop) with our current project - so that we can make the case for using it with our next (and quickly approaching) project that will use node.

Or maybe that logic is misapplied. Either way - we went from a "global" installation to a "local" installlation (Cypress CLI was complaining that the .cache folder did not contain a "Cypress" instance) and it worked great.

We now do this:

su - cypress -c 'npm install cypress'

I then do the following, and encounter the "cypress.json" error mentioned here in this issue:

`[cypress@proto ~]$ npx cypress run --spec '/home/cypress/cy.tests/EXAMPLE.staff_login.js'
It looks like this is your first time using Cypress: 3.0.2

✔ Verified Cypress! /home/cypress/.cache/Cypress/3.0.2/Cypress

Opening Cypress...
Could not find any tests to run.

We looked but did not find a cypress.json file in this folder: /home/cypress`

Passing --config (despite no test/spec specified) further underscores this:

`[cypress@proto ~]$ npx cypress run --config integrationFolder=/home/cypress/cy.tests/,fixturesFolder=false
Could not find any tests to run.

We looked but did not find a cypress.json file in this folder: /home/cypress`

@Knaledge
Copy link

@brian-mann - Alternatively, just some clear instruction/guidance on how to do this "init" on my own would be so, so helpful as I believe it is the last barricade. Cypress docs - while super awesome (really!) - don't seem to cover what exactly is required for a run to work. It seems there is a lot of reliance on using the UI to select a project (which then generates the required files/folders/etc.) - but as you raised here, we're using CLI entirely.

Even just a few quick pointers to get me on my feet would be incredibly appreciated.

@jennifer-shehane
Copy link
Member

Looping the below suggestion in as discussed in #164:

Never seed tests when running cypress ci

@jennifer-shehane
Copy link
Member

  • Allow user to choose a different directory other than cypress directory to scaffold?? (we could set up the appropriate mappings in their cypress.json
  • Offer prompt to skip interactive mode just doing cypress init -f like npm init.
  • Add new command to Command Line docs.
  • cypress init should be released with GUI option, but can be developed after we figure out user flow of GUI: Give the option to seed / scaffold cypress files on new project through UI #3364
  • Make the configFile optional -- (kind of required for the Dashboard.....), so only make it if they set up Dashboard.
  • Make the pluginsFile and supportFile optional also.
  • Choose whether they want to seed or not & reinvoke it as part of GUI later.
  • Relax rules of scaffolding/seeding - don't regenerate cypress folder.
  • Don't error on cypress run if no tests - improve this message and give a call to action.

@jennifer-shehane jennifer-shehane added cli pkg/server This is due to an issue in the packages/server directory labels Feb 7, 2019
@jennifer-shehane jennifer-shehane changed the title Proposal: cypress init command Add cypress init command to seed / scaffold test files on current directory Feb 7, 2019
@ollie-o
Copy link

ollie-o commented May 22, 2019

This issue was opened in 2017. What is the ETA? Is someone working on it?

Also, are there any workarounds in the meantime?

@kuceb
Copy link
Contributor

kuceb commented Jul 8, 2019

another use case would be properly setting up eslint with eslint-plugin-cypress, since there can be quite a few steps to this e.g.:

  • install all required dependencies for eslint (eslint, eslint-plugin-cypress, eslint-plugin-mocha, possibly others) OR use hacky patching around eslint to be able to provide the plugins thru our plugin, so users dont have to install peerDependency plugins themselves
  • create .eslintrc in cypress directory
  • if users are using typescript, they will need @ typescript-eslint/parser + plugin

@bahmutov
Copy link
Contributor

bahmutov commented Jul 8, 2019

@bkucera we could just implement / add this to https://github.com/bahmutov/cly issues - there the progress will be much faster

PS: @ollie-o

@Adil-Iqbal
Copy link

Adil-Iqbal commented Aug 19, 2020

I've had to train a few devs on the team to use Cypress, and not having this feature kind of threw them for a loop. It would be more intuitive to explain.

"First open the test launcher. Then close the test launcher. Now we can create a test..."
-versus-
"Run the intialize command. Now we can create a test..."

I realize that that's not as big of a problem as some other comments on here. All I'm saying is, having this command would really help with our onboarding process. It would also give cypress a better first impression for the uninitiated.

@benjaminbours
Copy link

benjaminbours commented Aug 27, 2020

@Adil-Iqbal president!

It is also very nice for the motivation explained here #1929

I can't wait for this #6249 to be reviewed :D

@the0neWhoKnocks
Copy link

It's a shame this issue hasn't gotten the attention it deserves. In case anyone else wanders across this ticket, and needs a zero-dependency solution:

#!/bin/bash

TEST_FOLDER="./e2e"
PATH_01=("${TEST_FOLDER}/cypress.json" "{ \"video\": false }\n")
PATH_02=("${TEST_FOLDER}/cypress/integration")
PATH_03=("${TEST_FOLDER}/cypress/integration/example.test.js" "context('Example', () => {\n  beforeEach(() => { cy.visit('/'); });\n\n  it('should have loaded', () => {\n    cy.get('title').contains(/.*/);\n  });\n});\n")
scaffold=(PATH_01[@] PATH_02[@] PATH_03[@])
if [ ! -f "${!scaffold[0]:0:1}" ]; then
  echo "[SCAFFOLD] Cypress test directory"
  
  length=${#scaffold[@]}
  for ((i=0; i<$length; i++)); do
    path="${!scaffold[i]:0:1}"
    contents="${!scaffold[i]:1:1}"
    
    if [[ "${contents}" != "" ]]; then printf "${contents}" > "${path}"; else mkdir -p "${path}"; fi
  done
fi

TLDR: If the cypress.json doesn't exist in the TEST_FOLDER, scaffold the bare minimum of what's required to get tests running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli pkg/server This is due to an issue in the packages/server directory type: feature New feature that does not currently exist
Projects
None yet
Development

Successfully merging a pull request may close this issue.