Александр
Александр

Reputation: 317

How can I launch test by order on the CYPRESS 10.3.0 like "testFiles" on the previous version?

There are 1test, 2test,3test etc. cypress.config.js:

    const { defineConfig } = require('cypress')

    module.exports = defineConfig({
      video: true,
      viewportWidth: 1920,
      viewportHeight: 1024,
      numTestsKeptInMemory: 1,
      defaultCommandTimeout: 10000,
      e2e: {
     // specPattern: 'cypress/integration/2test.cy.js, cypress/integration/1test.cy.js',

      setupNodeEvents(on, config) {
        return require('./cypress/plugins/index.js')(on, config)
      },
       baseUrl: 'https://localhost:3000',
      },
    })

Also, I add specPattern, but it isn't work

cypress.json:

    {
      "baseUrl": "https://localhost:3000",
      "video": true,
      "viewportWidth": 1920,
      "viewportHeight": 1024,
      "numTestsKeptInMemory": 1,
      "defaultCommandTimeout": 10000,
      "testFiles": [
        "2test.js",
        "1test.js"
      ]}

I updated cypress to 10.3.0 version. I want to launch command : node_modules/.bin/cypress run But all tests start operate. Early, using previous version, I launch command (node_modules/.bin/cypress run) and tests operate prom testList cypress.json. How can I do it on the cepress 10.3.0?

.gitlab-ci.yml:

image: node:12.13.1

stages:
  - eslint
  - build
  - deploy

eslint:
  tags:
    - docker
  stage: eslint
  script:
    - npm i
    - npx eslint -f table ./src || true
    - export ERRORS_COUNT=$(npx eslint -f ./formatter.js ./src)
    - echo "Total number of errors - $SUM_OF_ERRORS"
    - echo "Number of errors in current commit - $ERRORS_COUNT"
    - if [ "$ERRORS_COUNT" -gt "$SUM_OF_ERRORS" ]; then exit 1;         else exit 0; fi

build:
  tags:
    - docker
  stage: build
  script:
    - npm i
    - echo "export const VERSION = "$CI_PIPELINE_ID";" >     /builds/synergy/dps1/src/version.js
    - CI=false npm run build-qa
    #- CI=false npm run build-beta
    #- CI=false npm run build
  artifacts:
    paths:
      - build/
  only:
    - develop

deploy:
  tags:
    - docker
  only:
    - develop
  stage: deploy
  script:
    - 'which ssh-agent || ( apk update && apk add openssh )'
    - eval $(ssh-agent -s)
    - mkdir -p ~/.ssh
    - curl https://ipinfo.io/ip
    - echo -e "$PRIVATE_KEY" > /root/.ssh/id_rsa
    - chmod 600 /root/.ssh/id_rsa
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    - echo "deploying to "${DEPLOY_SERVERS}""
    - ls
    - pwd
    - scp -r /builds/synergy/dps1/build ec2-user@"${DEPLOY_SERVERS}":/usr2/dpsone/
    - ssh ec2-user@"${DEPLOY_SERVERS}" 'bash' < ./updateAndRestart.sh

package.json:

{
  "name": "dps-one-frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@ant-design/icons": "^4.1.0",
    "ant-design-pro": "^2.3.2",
    "antd": "3.19.6",
    "axios": "^0.21.1",
    "chart.js": "^3.8.0",
    "classnames": "2.2.6",
    "cypress-react-selector": "^2.3.12",
    "d3": "^3.5.16",
    "d3-geo": "^2.0.1",
    "d3-tip": "^0.6.7",
    "downloadjs": "^1.4.7",
    "express": "^4.17.1",
    "html2canvas": "^1.0.0-rc.7",
    "interactjs": "^1.9.4",
    "lodash": "^4.17.15",
    "moment": "2.24.0",
    "moment-timezone": "^0.5.28",
    "path": "^0.12.7",
    "prop-types": "15.7.2",
    "rc-tween-one": "^2.5.0",
    "react": "16.8.6",
    "react-calendar-timeline": "^0.26.7",
    "react-chartjs-2": "^4.1.0",
    "react-charts": "^2.0.0-beta.7",
    "react-color": "^2.19.3",
    "react-device-detect": "^1.12.1",
    "react-dom": "16.8.6",
    "react-google-login": "^5.1.10",
    "react-image-lightbox": "^5.1.0",
    "react-lazylog": "^4.5.2",
    "react-redux": "7.1.0",
    "react-router-dom": "5.0.1",
    "react-scripts": "^3.3.0",
    "react-simple-maps": "2.1.2",
    "react-tooltip": "latest",
    "react-virtualized": "^9.21.2",
    "redux": "4.0.1",
    "redux-thunk": "2.3.0"
  },
  "scripts": {
    "start": "HTTPS=true react-scripts start",
    "build": "react-scripts build",
    "build-beta": "REACT_APP_SECRET_CODE=beta react-scripts build",
    "build-qa": "REACT_APP_SECRET_CODE=qa react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "tests:in:order": "cypress run --spec \"cypress/e2e/tests-in-order.cy.js\""
  },
  "lint-staged": {
    "*.{js,jsx}": [
      "prettier --write",
      "git add"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@cypress/react": "^5.9.4",
    "@cypress/webpack-dev-server": "^1.4.0",
    "babel-eslint": "10.0.3",
    "cypress": "^10.3.0",
    "cypress-file-upload": "^5.0.8",
    "eslint": "6.6.0",
    "eslint-config-airbnb": "17.1.0",
    "eslint-config-prettier": "5.0.0",
    "eslint-plugin-import": "2.17.3",
    "eslint-plugin-jsx-a11y": "6.2.1",
    "eslint-plugin-prettier": "3.1.0",
    "eslint-plugin-react": "7.13.0",
    "husky": "2.4.1",
    "lint-staged": "8.2.1",
    "prettier": "1.18.2",
    "sass": "^1.47.0"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged && ./node_modules/.bin/cypress run --headless"
    }
  }
}

Upvotes: 0

Views: 433

Answers (2)

Александр
Александр

Reputation: 317

  "husky": {
    "hooks": {
      "pre-commit": "lint-staged && ./node_modules/.bin/cypress run --spec \"cypress/e2e/tests-in-order.cy.js\""
    }
  }

Upvotes: 0

Alapan Das
Alapan Das

Reputation: 18650

In your cypress/e2e folder create a file named tests-in-order.cy.js and inside it import the tests in the order you want them to execute like this:

import './1test.cy.js'
import './2test.cy.js'
import './3test.cy.js'

Then to execute the tests:

In test Runner, you can click on the tests-in-order.cy.js file and all the tests will execute in the intended order.

In CLI, use the command like this.

npx cypress run --spec "cypress/e2e/tests-in-order.cy.js"

But one thing to add, if you are running the tests in CLI, the final report will just have the tests-in-order.cy.js along with the count of the test cases from all files, something like this:

All spec exec cli

Go to package.json and create a command like this under scripts:

"scripts": {
  "tests:in:order": "cypress run --spec \"cypress/e2e/tests-in-order.cy.js\"",
  }

Then from next time onwards just execute the command npm run tests:in:order

Upvotes: 1

Related Questions