cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.97k stars 3.18k forks source link

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

Open brian-mann opened 7 years ago

brian-mann commented 7 years ago

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 commented 6 years ago

@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 commented 6 years ago

@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 commented 5 years ago

Looping the below suggestion in as discussed in https://github.com/cypress-io/cypress/issues/164:

Never seed tests when running cypress ci

jennifer-shehane commented 5 years ago
ollie-o commented 5 years ago

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

Also, are there any workarounds in the meantime?

kuceb commented 5 years ago

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

bahmutov commented 5 years ago

@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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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.

MikeMcC399 commented 4 months ago

What would you like?

Cypress should support an automated way of configuring and setting up E2E examples through the command line, for instance using an environment variable.

The choice of the full set of "Scaffold example specs" or the single test spec from "Create new spec" should be given.

Why is this needed?

Currently it is necessary to use cypress open, then to manually agree to the configuration, followed by selecting spec options.

This means that there is no straightforward way to automate the setup or update of a running Cypress example project. Instead, manual steps have to be described and carried out. An example of this is in the instructions factory/test-project/README.MD in the cypress-io/cypress-docker-images repo, where it is necessary to combine shell instructions with manual instructions to achieve setup:


rm -rf cypress cypress.config.js
npm install cypress@latest --no-package-lock
npx cypress open

Test that scaffolded specs run:

npm test