How to use cypressVersion method in Cypress

Best JavaScript code snippet using cypress

generate-config.js

Source:generate-config.js Github

copy

Full Screen

1// @ts-check2// this script generates CircleCI config file by looking at the "base/*" folders3// for each subfolder it creates a separate job4const globby = require('globby');5const fs = require('fs')6const path = require('path')7const os = require('os')8const semver = require('semver')9const { camelCase } = require('lodash')10const slugify = require('slugify')11const skipBaseImages = [12 '6',13 '8',14 '8.0.0',15 '8.15.1',16 '8.16.0',17 '8.2.1',18 '8.9.3',19 '8.9.3-npm-6.10.1',20 '10',21 '10.0.0',22 '10.11.0',23 '10.15.3',24 '10.16.0',25 '10.16.3',26 '10.18.0',27 '10.18.1',28 '10.2.1',29 '11.13.0',30 '12.0.0',31 '12.1.0',32 '12.12.0',33 '12.13.0',34 '12.14.0',35 '12.14.1',36 '12.16.0',37 '12.16.1',38 '12.16.2',39 '12.18.0',40 '12.18.2',41 '12.4.0',42 '12.6.0',43 '12.8.1',44 '13.1.0',45 '13.3.0',46 '13.6.0',47 '13.8.0',48 '14.0.0',49 'centos7',50 'centos7-12.4.0',51 'ubuntu16',52 'ubuntu16-12.13.1',53 'ubuntu16-8',54 'ubuntu18-node12.14.1',55 'ubuntu19-node12.14.1'56];57const skipBrowserImages = [58 'chrome63-ff57',59 'chrome65-ff57',60 'chrome67',61 'chrome67-ff57',62 'chrome69',63 'node8.15.1-chrome73',64 'node8.2.1-chrome73',65 'node8.9.3-chrome73',66 'node8.9.3-npm6.10.1-chrome75',67 'node8.9.3-npm6.10.1-chrome76-ff68',68 'node10.11.0-chrome75',69 'node10.16.0-chrome76',70 'node10.16.0-chrome77',71 'node10.16.0-chrome77-ff71',72 'node10.16.3-chrome80-ff73',73 'node10.2.1-chrome74',74 'node11.13.0-chrome73',75 'node12.0.0-chrome73',76 'node12.0.0-chrome73-ff68',77 'node12.0.0-chrome75',78 'node12.13.0-chrome78-ff70',79 'node12.13.0-chrome78-ff70-brave78',80 'node12.13.0-chrome80-ff73',81 'node12.13.0-chrome80-ff74',82 'node12.14.0-chrome79-ff71',83 'node12.14.1-chrome83-ff77',84 'node12.16.1-chrome80-ff73',85 'node12.16.2-chrome81-ff75',86 'node12.18.0-chrome83-ff77',87 'node12.4.0-chrome76',88 'node12.6.0-chrome75',89 'node12.6.0-chrome77',90 'node12.8.1-chrome78-ff70',91 'node12.8.1-chrome80-ff72',92 'node13.1.0-chrome78-ff70',93 'node13.3.0-chrome79-ff70',94 'node13.6.0-chrome80-ff72'95]96const awsCodeBuildPreamble = `97version: 0.298env:99 variables:100 PUBLIC_ECR_ALIAS: "cypress-io"101batch:102 fast-fail: false103 build-list:`104const awsCodeBuildPostamble = `105phases:106 pre_build:107 commands:108 - aws --version109 - echo Check if $IMAGE_TAG is in ECR...110 - ./find-ecr-image.sh $IMAGE_REPO_NAME $IMAGE_TAG -p111 - echo Logging in to Amazon ECR...112 - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com113 - aws ecr-public get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin public.ecr.aws/$PUBLIC_ECR_ALIAS114 build:115 commands:116 - echo Building the Docker image... 117 - cd $IMAGE_DIR/$IMAGE_TAG118 - docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .119 - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG public.ecr.aws/$PUBLIC_ECR_ALIAS/$IMAGE_REPO_NAME:$IMAGE_TAG120 post_build:121 commands:122 - echo Pushing the Docker image...123 - docker push public.ecr.aws/$PUBLIC_ECR_ALIAS/$IMAGE_REPO_NAME:$IMAGE_TAG124`125const preamble = `126# WARNING: this file is automatically generated by ${path.basename(__filename)}127# info on building Docker images on Circle128# https://circleci.com/docs/2.0/building-docker-images/129version: 2.1130orbs:131 node: circleci/node@1.1132commands:133 halt-on-branch:134 description: Halt current CircleCI job if not on master branch135 steps:136 - run:137 name: Halting job if not on master branch138 command: |139 if [[ "$CIRCLE_BRANCH" != "master" ]]; then140 echo "Not master branch, will skip the rest of commands"141 circleci-agent step halt142 else143 echo "On master branch, can continue"144 fi145 halt-if-docker-image-exists:146 description: Halt current CircleCI job if Docker image exists already147 parameters:148 imageName:149 type: string150 description: Docker image name to test151 steps:152 - run:153 name: Check if image << parameters.imageName >> exists or Docker hub does not respond154 # using https://github.com/cypress-io/docker-image-not-found155 # to check if Docker hub definitely does not have this image156 command: |157 if npx docker-image-not-found --repo << parameters.imageName >>; then158 echo Docker hub says image << parameters.imageName >> does not exist159 else160 echo Docker hub has image << parameters.imageName >> or not responding161 echo We should stop in this case162 circleci-agent step halt163 fi164 test-base-image:165 description: Build a test image from base image and test it166 parameters:167 nodeVersion:168 type: string169 description: Node version to expect in the base image, starts with "v"170 imageName:171 type: string172 description: Cypress base docker image to test173 checkNodeVersion:174 type: boolean175 description: Check if the FROM image name is strict Node version176 default: true177 steps:178 - when:179 condition: << parameters.checkNodeVersion >>180 steps:181 - run:182 name: confirm image has Node << parameters.nodeVersion >>183 # do not run Docker in the interactive mode - adds control characters!184 command: |185 version=$(docker run << parameters.imageName >> node --version)186 if [ "$version" == "<< parameters.nodeVersion >>" ]; then187 echo "Base image has the expected version of Node << parameters.nodeVersion >>";188 else189 echo "Problem: base image has unexpected Node version"190 echo "Expected << parameters.nodeVersion >> and got $version"191 exit 1192 fi193 - run:194 name: test image << parameters.imageName >>195 no_output_timeout: '3m'196 command: |197 docker build -t cypress/test -\\<<EOF198 FROM << parameters.imageName >>199 RUN echo "current user: $(whoami)"200 ENV CI=1201 WORKDIR /app202 RUN npm init --yes203 RUN npm install --save-dev cypress cypress-expect204 RUN ./node_modules/.bin/cypress verify205 RUN npx @bahmutov/cly init206 # run Cypress by itself207 RUN ./node_modules/.bin/cypress run208 # run Cypress using module API and confirm number of passing tests209 RUN ./node_modules/.bin/cypress-expect run --passing 1210 EOF211 - run:212 name: test image << parameters.imageName >> using Kitchensink213 no_output_timeout: '3m'214 command: |215 docker build -t cypress/test-kitchensink -\\<<EOF216 FROM << parameters.imageName >>217 RUN echo "current user: $(whoami)"218 ENV CI=1219 ENV CYPRESS_INTERNAL_FORCE_SCAFFOLD=1220 WORKDIR /app221 RUN npm init --yes222 RUN npm install --save-dev cypress cypress-expect223 RUN ./node_modules/.bin/cypress verify224 RUN echo '{}' > cypress.json225 # run Cypress and confirm minimum number of passing tets226 RUN ./node_modules/.bin/cypress-expect run --min-passing 100227 EOF228 test-browser-image:229 description: Build a test image from browser image and test it230 parameters:231 imageName:232 type: string233 description: Cypress browser docker image to test234 chromeVersion:235 type: string236 default: ''237 description: Chrome version to expect in the base image, starts with "Google Chrome XX"238 firefoxVersion:239 type: string240 default: ''241 description: Firefox version to expect in the base image, starts with "Mozilla Firefox XX"242 edgeVersion:243 type: string244 default: ''245 description: Edge version to expect in the base image, starts with "Microsoft Edge XX"246 steps:247 - when:248 condition: << parameters.chromeVersion >>249 steps:250 - run:251 name: confirm image has Chrome << parameters.chromeVersion >>252 # do not run Docker in the interactive mode - adds control characters!253 # and use Bash regex string comparison254 command: |255 version=$(docker run << parameters.imageName >> google-chrome --version)256 if [[ "$version" =~ ^"<< parameters.chromeVersion >>" ]]; then257 echo "Image has the expected version of Chrome << parameters.chromeVersion >>"258 echo "found $version"259 else260 echo "Problem: image has unexpected Chrome version"261 echo "Expected << parameters.chromeVersion >> and got $version"262 exit 1263 fi264 - when:265 condition: << parameters.firefoxVersion >>266 steps:267 - run:268 name: confirm the image has Firefox << parameters.firefoxVersion >>269 command: |270 version=$(docker run << parameters.imageName >> firefox --version)271 if [[ "$version" =~ ^"<< parameters.firefoxVersion >>" ]]; then272 echo "Image has the expected version of Firefox << parameters.firefoxVersion >>"273 echo "found $version"274 else275 echo "Problem: image has unexpected Firefox version"276 echo "Expected << parameters.firefoxVersion >> and got $version"277 exit 1278 fi279 - when:280 condition: << parameters.edgeVersion >>281 steps:282 - run:283 name: confirm the image has Edge << parameters.edgeVersion >>284 command: |285 version=$(docker run << parameters.imageName >> edge --version)286 if [[ "$version" =~ ^"<< parameters.edgeVersion >>" ]]; then287 echo "Image has the expected version of Edge << parameters.edgeVersion >>"288 echo "found $version"289 else290 echo "Problem: image has unexpected Edge version"291 echo "Expected << parameters.edgeVersion >> and got $version"292 exit 1293 fi294 - run:295 name: test image << parameters.imageName >>296 no_output_timeout: '3m'297 command: |298 docker build -t cypress/test -\\<<EOF299 FROM << parameters.imageName >>300 RUN echo "current user: $(whoami)"301 ENV CI=1302 RUN npm init --yes303 RUN npm install --save-dev cypress304 RUN ./node_modules/.bin/cypress verify305 RUN npx @bahmutov/cly init306 EOF307 - run:308 name: Test built-in Electron browser309 no_output_timeout: '1m'310 command: docker run cypress/test ./node_modules/.bin/cypress run311 - when:312 condition: << parameters.chromeVersion >>313 steps:314 - run:315 name: Test << parameters.chromeVersion >>316 no_output_timeout: '1m'317 command: docker run cypress/test ./node_modules/.bin/cypress run --browser chrome318 - when:319 condition: << parameters.firefoxVersion >>320 steps:321 - run:322 name: Test << parameters.firefoxVersion >>323 no_output_timeout: '1m'324 command: docker run cypress/test ./node_modules/.bin/cypress run --browser firefox325 - when:326 condition: << parameters.edgeVersion >>327 steps:328 - run:329 name: Test << parameters.edgeVersion >>330 no_output_timeout: '1m'331 command: docker run cypress/test ./node_modules/.bin/cypress run --browser edge332 - run:333 name: scaffold image << parameters.imageName >> using Kitchensink334 no_output_timeout: '3m'335 command: |336 docker build -t cypress/test-kitchensink -\\<<EOF337 FROM << parameters.imageName >>338 RUN echo "current user: $(whoami)"339 ENV CI=1340 ENV CYPRESS_INTERNAL_FORCE_SCAFFOLD=1341 RUN npm init --yes342 RUN npm install --save-dev cypress343 RUN ./node_modules/.bin/cypress verify344 RUN echo '{}' > cypress.json345 EOF346 - when:347 condition: << parameters.chromeVersion >>348 steps:349 - run:350 name: Test << parameters.chromeVersion >>351 no_output_timeout: '1m'352 command: docker run cypress/test-kitchensink ./node_modules/.bin/cypress run --browser chrome353 - when:354 condition: << parameters.firefoxVersion >>355 steps:356 - run:357 name: Test << parameters.firefoxVersion >>358 no_output_timeout: '1m'359 command: docker run cypress/test-kitchensink ./node_modules/.bin/cypress run --browser firefox360 - when:361 condition: << parameters.edgeVersion >>362 steps:363 - run:364 name: Test << parameters.edgeVersion >>365 no_output_timeout: '1m'366 command: docker run cypress/test-kitchensink ./node_modules/.bin/cypress run --browser edge367 test-included-image-versions:368 description: Testing pre-installed versions369 parameters:370 cypressVersion:371 type: string372 description: Cypress version to test, like "4.0.0"373 imageName:374 type: string375 description: Cypress included docker image to test376 steps:377 - run:378 name: 'Print versions'379 command: docker run -it --entrypoint cypress cypress/included:<< parameters.cypressVersion >> version380 - run:381 name: 'Print info'382 command: docker run -it --entrypoint cypress cypress/included:<< parameters.cypressVersion >> info383 - run:384 name: 'Check Node version'385 command: |386 export NODE_VERSION=$(docker run --entrypoint node cypress/included:<< parameters.cypressVersion >> --version)387 export CYPRESS_NODE_VERSION=$(docker run --entrypoint cypress cypress/included:<< parameters.cypressVersion >> version --component node)388 echo "Included Node $NODE_VERSION"389 echo "Cypress includes Node $CYPRESS_NODE_VERSION"390 # "node --version" returns something like "v12.1.2"391 # and "cypres version ..." returns just "12.1.2"392 if [ "$NODE_VERSION" = "v$CYPRESS_NODE_VERSION" ]; then393 echo "Node versions match"394 else395 echo "Node version mismatch 🔥"396 # TODO make sure there are no extra characters in the versions397 # https://github.com/cypress-io/cypress-docker-images/issues/411398 # exit 1399 fi400 test-included-image:401 description: Testing Docker image with Cypress pre-installed402 parameters:403 cypressVersion:404 type: string405 description: Cypress version to test, like "4.0.0"406 imageName:407 type: string408 description: Cypress included docker image to test409 steps:410 - run:411 name: New test project and testing412 no_output_timeout: '3m'413 command: |414 node --version415 mkdir test416 cd test417 echo "Initializing test project"418 npx @bahmutov/cly init --cypress-version << parameters.cypressVersion >>419 echo "Testing using Electron browser"420 docker run -it -v $PWD:/e2e -w /e2e cypress/included:<< parameters.cypressVersion >>421 echo "Testing using Chrome browser"422 docker run -it -v $PWD:/e2e -w /e2e cypress/included:<< parameters.cypressVersion >> --browser chrome423 working_directory: /tmp424 test-included-image-using-kitchensink:425 description: Testing Cypress pre-installed using Kitchensink426 parameters:427 cypressVersion:428 type: string429 description: Cypress version to test, like "4.0.0"430 imageName:431 type: string432 description: Cypress included docker image to test433 steps:434 - run:435 name: Testing Kitchensink436 no_output_timeout: '3m'437 command: |438 node --version439 mkdir test-kitchensink440 cd test-kitchensink441 npm init -y442 echo '{}' > cypress.json443 echo "Testing using Electron browser"444 docker run -it -v $PWD:/e2e -w /e2e -e CYPRESS_INTERNAL_FORCE_SCAFFOLD=1 cypress/included:<< parameters.cypressVersion >>445 echo "Testing using Chrome browser"446 docker run -it -v $PWD:/e2e -w /e2e -e CYPRESS_INTERNAL_FORCE_SCAFFOLD=1 cypress/included:<< parameters.cypressVersion >> --browser chrome447 working_directory: /tmp448 docker-push:449 description: Log in and push a given image to Docker hub450 parameters:451 imageName:452 type: string453 description: Docker image name to push454 steps:455 # before pushing, let's check again that the Docker Hub does not have the image456 # accidental rebuild and overwrite of an image is bad, since it can bump every tool457 # https://github.com/cypress-io/cypress/issues/6335458 - halt-if-docker-image-exists:459 imageName: << parameters.imageName >>460 - run:461 name: Pushing image << parameters.imageName >> to Docker Hub462 command: |463 echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin464 docker push << parameters.imageName >>465jobs:466 lint-markdown:467 executor:468 name: node/default469 tag: '12'470 steps:471 - checkout472 - node/with-cache:473 steps:474 - run: npm ci475 - run: npm run check:markdown476 build-base-image:477 machine: true478 parameters:479 dockerName:480 type: string481 description: Image name to build482 default: cypress/base483 dockerTag:484 type: string485 description: Image tag to build like "12.14.0"486 checkNodeVersion:487 type: boolean488 description: Check if the FROM image name is strict Node version489 default: true490 steps:491 - checkout492 - halt-if-docker-image-exists:493 imageName: << parameters.dockerName >>:<< parameters.dockerTag >>494 - run:495 name: building Docker image << parameters.dockerName >>:<< parameters.dockerTag >>496 command: |497 docker build -t << parameters.dockerName >>:<< parameters.dockerTag >> .498 working_directory: base/<< parameters.dockerTag >>499 - test-base-image:500 nodeVersion: v<< parameters.dockerTag >>501 imageName: << parameters.dockerName >>:<< parameters.dockerTag >>502 checkNodeVersion: << parameters.checkNodeVersion >>503 - halt-on-branch504 - docker-push:505 imageName: << parameters.dockerName >>:<< parameters.dockerTag >>506 build-browser-image:507 machine: true508 parameters:509 dockerName:510 type: string511 description: Image name to build512 default: cypress/browsers513 dockerTag:514 type: string515 description: Image tag to build like "node12.4.0-chrome76"516 chromeVersion:517 type: string518 default: ''519 description: Chrome version to expect in the base image, starts with "Google Chrome XX"520 firefoxVersion:521 type: string522 default: ''523 description: Firefox version to expect in the base image, starts with "Mozilla Firefox XX"524 edgeVersion:525 type: string526 default: ''527 description: Edge version to expect in the base image, starts with "Microsoft Edge XX"528 steps:529 - checkout530 - halt-if-docker-image-exists:531 imageName: << parameters.dockerName >>:<< parameters.dockerTag >>532 - run:533 name: building Docker image << parameters.dockerName >>:<< parameters.dockerTag >>534 command: |535 docker build -t << parameters.dockerName >>:<< parameters.dockerTag >> .536 working_directory: browsers/<< parameters.dockerTag >>537 - test-browser-image:538 imageName: << parameters.dockerName >>:<< parameters.dockerTag >>539 chromeVersion: << parameters.chromeVersion >>540 firefoxVersion: << parameters.firefoxVersion >>541 edgeVersion: << parameters.edgeVersion >>542 - halt-on-branch543 - docker-push:544 imageName: << parameters.dockerName >>:<< parameters.dockerTag >>545 build-included-image:546 machine: true547 parameters:548 dockerName:549 type: string550 description: Image name to build551 default: cypress/included552 dockerTag:553 type: string554 description: Image tag to build, should match Cypress version, like "3.8.1"555 steps:556 - checkout557 - halt-if-docker-image-exists:558 imageName: << parameters.dockerName >>:<< parameters.dockerTag >>559 - run:560 name: building Docker image << parameters.dockerName >>:<< parameters.dockerTag >>561 command: |562 docker build -t << parameters.dockerName >>:<< parameters.dockerTag >> .563 working_directory: included/<< parameters.dockerTag >>564 - test-included-image-versions:565 cypressVersion: << parameters.dockerTag >>566 imageName: << parameters.dockerName >>:<< parameters.dockerTag >>567 - test-included-image:568 cypressVersion: << parameters.dockerTag >>569 imageName: << parameters.dockerName >>:<< parameters.dockerTag >>570 - test-included-image-using-kitchensink:571 cypressVersion: << parameters.dockerTag >>572 imageName: << parameters.dockerName >>:<< parameters.dockerTag >>573 - halt-on-branch574 - docker-push:575 imageName: << parameters.dockerName >>:<< parameters.dockerTag >>576workflows:577 version: 2578 lint:579 jobs:580 - lint-markdown581`582const formBaseWorkflow = (baseImages) => {583 // skip images that already have been built584 // one can update this list if the number of585 // build jobs in circleci grows too long586 const isSkipped = (tag) => skipBaseImages.includes(tag)587 const isIncluded = (imageAndTag) => !isSkipped(imageAndTag.tag)588 const yml = baseImages.filter(isIncluded).map(imageAndTag => {589 // important to have indent590 let job = ' - build-base-image:\n' +591 ` name: "base ${imageAndTag.tag}"\n` +592 ` dockerTag: "${imageAndTag.tag}"\n`593 // do not check Node versions in some custom images594 if (imageAndTag.tag === '12.0.0-libgbm' || imageAndTag.tag === 'manjaro-14.12.0') {595 job += ' checkNodeVersion: false\n'596 }597 return job598 })599 // indent is important600 const workflowName = ' build-base-images:\n' +601 ' jobs:\n'602 const text = workflowName + yml.join('')603 return text604}605const fullChromeVersion = (version) =>606 `Google Chrome ${version}`607const fullFirefoxVersion = (version) =>608 `Mozilla Firefox ${version}`609const fullEdgeVersion = (version) =>610 `Microsoft Edge ${version}`611const findChromeVersion = (imageAndTag) => {612 // image name like "nodeX.Y.Z-chromeXX..."613 // the folder has "chromeXX" name, so extract the "XX" part614 const matches = /chrome(\d+)/.exec(imageAndTag)615 if (matches && matches[1]) {616 return fullChromeVersion(matches[1])617 }618 return null619}620const findFirefoxVersion = (imageAndTag) => {621 // image name like "nodeX.Y.Z-chromeXX-ffYY..."622 // the folder has "ffYY" name, so extract the "YY" part623 const matches = /-ff(\d+)/.exec(imageAndTag)624 if (matches && matches[1]) {625 return fullFirefoxVersion(matches[1])626 }627 return null628}629const findEdgeVersion = (imageAndTag) => {630 // image name like "nodeX.Y.Z-edgeXX"631 // so we will extract "XX" part632 const matches = /-edge(\d+)/.exec(imageAndTag)633 if (matches && matches[1]) {634 return fullEdgeVersion(matches[1])635 }636 return null637}638const formBrowserWorkflow = (browserImages) => {639 // not every browser image can be tested640 // some old images do not have NPX for example641 // so let them be642 const isSkipped = (tag) => skipBrowserImages.includes(tag)643 const isIncluded = (imageAndTag) => !isSkipped(imageAndTag.tag)644 const yml = browserImages.filter(isIncluded).map(imageAndTag => {645 const chromeVersion = findChromeVersion(imageAndTag.tag)646 const firefoxVersion = findFirefoxVersion(imageAndTag.tag)647 const edgeVersion = findEdgeVersion(imageAndTag.tag)648 const foundBrowser = chromeVersion || firefoxVersion || edgeVersion649 if (!foundBrowser) {650 throw new Error(`Cannot find any browsers from image tag "${imageAndTag.tag}"`)651 }652 // important to have indent653 let job = ' - build-browser-image:\n' +654 ` name: "browsers ${imageAndTag.tag}"\n` +655 ` dockerTag: "${imageAndTag.tag}"\n`656 if (chromeVersion) {657 job += ` chromeVersion: "${chromeVersion}"\n`658 }659 if (firefoxVersion) {660 job += ` firefoxVersion: "${firefoxVersion}"\n`661 }662 if (edgeVersion) {663 job += ` edgeVersion: "${edgeVersion}"\n`664 }665 return job666 })667 // indent is important668 const workflowName = ' build-browser-images:\n' +669 ' jobs:\n'670 const text = workflowName + yml.join('')671 return text672}673const formIncludedWorkflow = (images) => {674 // skip images that have been built already675 const isSkipped = (tag) => {676 return semver.lt(tag, '6.0.0')677 }678 const isIncluded = (imageAndTag) => !isSkipped(imageAndTag.tag)679 const yml = images.filter(isIncluded).map(imageAndTag => {680 // important to have indent681 const job = ' - build-included-image:\n' +682 ` name: "included ${imageAndTag.tag}"\n` +683 ` dockerTag: "${imageAndTag.tag}"\n`684 return job685 })686 // indent is important687 const workflowName = ' build-included-images:\n' +688 ' jobs:\n'689 const text = workflowName + yml.join('')690 return text691}692const writeConfigFile = (baseImages, browserImages, includedImages) => {693 const base = formBaseWorkflow(baseImages)694 const browsers = formBrowserWorkflow(browserImages)695 const included = formIncludedWorkflow(includedImages)696 const text = preamble.trim() + os.EOL + base + os.EOL + browsers + os.EOL + included697 fs.writeFileSync('circle.yml', text, 'utf8')698 console.log('generated circle.yml')699}700const splitImageFolderName = (folderName) => {701 const [name, tag] = folderName.split('/')702 return {703 name,704 tag705 }706}707const formAwsCodeBuildBaseWorkflow = (baseImages) => {708 // skip images that already have been built709 // one can update this list if the number of710 // build jobs in AWS CodeBuild grows too long711 const isSkipped = (tag) => skipBaseImages.includes(tag)712 const isIncluded = (imageAndTag) => !isSkipped(imageAndTag.tag)713 const yml = baseImages.filter(isIncluded).map(imageAndTag => {714 console.log('imageAndTag', imageAndTag)715 // @ts-ignore716 const tagSlug = slugify(imageAndTag.tag, '-')717 console.log('tagSlug', tagSlug)718 const identifier = camelCase(`${imageAndTag.name}${imageAndTag.tag}`)719 let job = ` - identifier: ${identifier}720 env:721 image: aws/codebuild/standard:5.0722 type: LINUX_CONTAINER723 privileged-mode: true724 compute-type: BUILD_GENERAL1_MEDIUM725 variables:726 IMAGE_REPO_NAME: "cypress/${imageAndTag.name}"727 IMAGE_DIR: "${imageAndTag.name}"728 IMAGE_TAG: "${imageAndTag.tag}"\n`729 return job730 })731 const text = yml.join('')732 return text733}734const formAwsCodeBuildBrowserWorkflow = (baseImages) => {735 // skip images that already have been built736 // one can update this list if the number of737 // build jobs in AWS CodeBuild grows too long738 const isSkipped = (tag) => skipBrowserImages.includes(tag)739 const isIncluded = (imageAndTag) => !isSkipped(imageAndTag.tag)740 const yml = baseImages.filter(isIncluded).map(imageAndTag => {741 console.log('imageAndTag', imageAndTag)742 // @ts-ignore743 const tagSlug = slugify(imageAndTag.tag, '-')744 console.log('tagSlug', tagSlug)745 const identifier = camelCase(`${imageAndTag.name}${imageAndTag.tag}`)746 let job = ` - identifier: ${identifier}747 env:748 image: aws/codebuild/standard:5.0749 type: LINUX_CONTAINER750 privileged-mode: true751 compute-type: BUILD_GENERAL1_MEDIUM752 variables:753 IMAGE_REPO_NAME: "cypress/${imageAndTag.name}"754 IMAGE_DIR: "${imageAndTag.name}"755 IMAGE_TAG: "${imageAndTag.tag}"\n`756 return job757 })758 const text = yml.join('')759 return text760}761const formAwsCodeBuildIncludedWorkflow = (baseImages) => {762 // skip images that already have been built763 // one can update this list if the number of764 // build jobs in AWS CodeBuild grows too long765 const isSkipped = (tag) => skipBaseImages.includes(tag)766 const isIncluded = (imageAndTag) => !isSkipped(imageAndTag.tag)767 const yml = baseImages.filter(isIncluded).map(imageAndTag => {768 console.log('imageAndTag', imageAndTag)769 // @ts-ignore770 const tagSlug = slugify(imageAndTag.tag, '-')771 console.log('tagSlug', tagSlug)772 const identifier = camelCase(`${imageAndTag.name}${imageAndTag.tag}`)773 let job = ` - identifier: ${identifier}774 env:775 image: aws/codebuild/standard:5.0776 type: LINUX_CONTAINER777 privileged-mode: true778 compute-type: BUILD_GENERAL1_MEDIUM779 variables:780 IMAGE_REPO_NAME: "cypress/${imageAndTag.name}"781 IMAGE_DIR: "${imageAndTag.name}"782 IMAGE_TAG: "${imageAndTag.tag}"\n`783 return job784 })785 const text = yml.join('')786 return text787}788const writeBuildspecConfigFile = (baseImages, browserImages, includedImages) => {789 const base = formAwsCodeBuildBaseWorkflow(baseImages)790 const browsers = formAwsCodeBuildBrowserWorkflow(browserImages)791 const included = formAwsCodeBuildIncludedWorkflow(includedImages)792 const text = awsCodeBuildPreamble.trim() + os.EOL + base + os.EOL + browsers + os.EOL + included + os.EOL + awsCodeBuildPostamble.trim()793 fs.writeFileSync('buildspec.yml', text, 'utf8')794 console.log('generated buildspec.yml')795}796(async () => {797 const basePaths = await globby('base/*', {onlyDirectories: true});798 const base = basePaths.map(splitImageFolderName)799 console.log(' *** base images ***')800 console.log(base)801 const browsersPaths = await globby('browsers/*', {onlyDirectories: true});802 const browsers = browsersPaths.map(splitImageFolderName)803 console.log(' *** browser images ***')804 console.log(browsers)805 const includedPaths = await globby('included/*', {onlyDirectories: true});806 const included = includedPaths.map(splitImageFolderName)807 console.log(' *** included images ***')808 console.log(included)809 writeConfigFile(base, browsers, included)810 writeBuildspecConfigFile(base, browsers, included)...

Full Screen

Full Screen

parallel.spec.js

Source:parallel.spec.js Github

copy

Full Screen

1const path = require("path");2const fsExtra = require("fs-extra");3const { runParallelSpecsTests } = require("./support/testsRunner");4const removeParallelStorage = () => {5 const parallelStorageFolder = path.resolve(__dirname, "..", "parallel-storage");6 fsExtra.removeSync(path.resolve(parallelStorageFolder, "run-a-is-cancelled.json"));7 fsExtra.removeSync(path.resolve(parallelStorageFolder, "run-b-is-waiting.json"));8};9runParallelSpecsTests(10 "When parallel strategy is enabled and first tests run fails",11 [12 {13 cypressVersion: "latest",14 pluginFile: "parallel-preprocessor-babel-config",15 specs: "parallel-failing",16 delay: 5000,17 specsResults: [18 {19 logBefore: true,20 executed: 4,21 passed: 1,22 failed: 1,23 skipped: 2,24 },25 {26 logBefore: false,27 executed: 4,28 passed: 0,29 failed: 0,30 skipped: 4,31 },32 {33 logBefore: false,34 executed: 3,35 passed: 0,36 failed: 0,37 skipped: 3,38 },39 ],40 env: {41 CYPRESS_FAIL_FAST_STRATEGY: "parallel",42 },43 },44 {45 cypressVersion: "ts",46 pluginFile: "parallel",47 specs: "all-tests-passing",48 specsResults: [49 {50 logBefore: true,51 executed: 4,52 passed: 4,53 failed: 0,54 skipped: 0,55 },56 {57 logBefore: true,58 executed: 4,59 passed: 0,60 failed: 0,61 skipped: 4,62 },63 {64 logBefore: false,65 executed: 4,66 passed: 0,67 failed: 0,68 skipped: 4,69 },70 ],71 env: {72 CYPRESS_FAIL_FAST_STRATEGY: "parallel",73 },74 },75 ],76 {77 afterAll: removeParallelStorage,78 }79);80runParallelSpecsTests(81 "When parallel strategy is enabled and first tests run fails using Cypress v8",82 [83 {84 cypressVersion: "8",85 pluginFile: "parallel-preprocessor-babel-config",86 specs: "parallel-failing",87 delay: 5000,88 specsResults: [89 {90 logBefore: true,91 executed: 4,92 passed: 1,93 failed: 1,94 skipped: 2,95 },96 {97 logBefore: false,98 executed: 4,99 passed: 0,100 failed: 0,101 skipped: 4,102 },103 {104 logBefore: false,105 executed: 3,106 passed: 0,107 failed: 0,108 skipped: 3,109 },110 ],111 env: {112 CYPRESS_FAIL_FAST_STRATEGY: "parallel",113 },114 },115 {116 cypressVersion: "7",117 pluginFile: "parallel",118 specs: "all-tests-passing",119 specsResults: [120 {121 logBefore: true,122 executed: 4,123 passed: 4,124 failed: 0,125 skipped: 0,126 },127 {128 logBefore: true,129 executed: 4,130 passed: 0,131 failed: 0,132 skipped: 4,133 },134 {135 logBefore: false,136 executed: 4,137 passed: 0,138 failed: 0,139 skipped: 4,140 },141 ],142 env: {143 CYPRESS_FAIL_FAST_STRATEGY: "parallel",144 },145 },146 ],147 {148 afterAll: removeParallelStorage,149 }150);151runParallelSpecsTests(152 "When parallel strategy is disabled and first tests run fails",153 [154 {155 cypressVersion: "latest",156 pluginFile: "parallel-preprocessor-babel-config",157 specs: "parallel-failing",158 delay: 5000,159 specsResults: [160 {161 logBefore: true,162 executed: 4,163 passed: 1,164 failed: 1,165 skipped: 2,166 },167 {168 logBefore: false,169 executed: 4,170 passed: 0,171 failed: 0,172 skipped: 4,173 },174 {175 logBefore: false,176 executed: 3,177 passed: 0,178 failed: 0,179 skipped: 3,180 },181 ],182 env: {183 CYPRESS_FAIL_FAST_STRATEGY: "run",184 },185 },186 {187 cypressVersion: "8",188 pluginFile: "parallel-preprocessor-babel-config",189 specs: "all-tests-passing",190 specsResults: [191 {192 logBefore: true,193 executed: 4,194 passed: 4,195 failed: 0,196 skipped: 0,197 },198 {199 logBefore: true,200 executed: 4,201 passed: 4,202 failed: 0,203 skipped: 0,204 },205 {206 logBefore: true,207 executed: 4,208 passed: 4,209 failed: 0,210 skipped: 0,211 },212 ],213 env: {214 CYPRESS_FAIL_FAST_STRATEGY: "run",215 },216 },217 ],218 {219 afterAll: removeParallelStorage,220 }...

Full Screen

Full Screen

config.js

Source:config.js Github

copy

Full Screen

1let _highlight2const { findCypressVersion } = require('../../src/utils')3const path = require('path')4const cypressVersion = findCypressVersion()5const base = `/cypress-examples/${cypressVersion}/`6const dest = path.join('public', 'cypress-examples', cypressVersion)7console.log('output folder: %s', dest)8const title = `Cypress examples (v${cypressVersion})`9module.exports = {10 title,11 description:12 'Static site with Cypress examples tested right from the Markdown sources',13 base,14 dest,15 head: [16 [17 'link',18 {19 rel: 'stylesheet',20 href:21 'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css',22 },23 ],24 [25 'style',26 {},27 '.action-focus.focus { border: 5px solid orange; } .hidden { display: none !important; }',28 ],29 // include jQuery and Bootstrap on every page30 [31 'script',32 {33 src: 'https://code.jquery.com/jquery-3.5.0.min.js',34 integrity:35 'sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=',36 crossorigin: 'anonymous',37 },38 ],39 [40 'script',41 {42 src:43 'https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js',44 integrity:45 'sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx',46 crossorigin: 'anonymous',47 },48 ],49 ],50 plugins: [],51 themeConfig: {52 // point pages back at the GitHub documents53 repo: 'bahmutov/cypress-examples',54 docsDir: 'docs',55 editLinks: true,56 editLinkText: 'Help us improve this page!',57 nav: [58 {59 text: 'Commands',60 items: [61 { text: 'Querying', link: '/commands/querying/' },62 {63 text: 'Traversal',64 link: '/commands/traversal/',65 },66 { text: 'Actions', link: '/commands/actions/' },67 { text: 'Window', link: '/commands/window/' },68 { text: 'Viewport', link: '/commands/viewport/' },69 { text: 'Location', link: '/commands/location/' },70 {71 text: 'Navigation',72 link: '/commands/navigation/',73 },74 {75 text: 'Assertions',76 link: '/commands/assertions/',77 },78 {79 text: 'Misc',80 link: '/commands/misc/',81 },82 {83 text: 'Connectors',84 link: '/commands/connectors/',85 },86 {87 text: 'Aliasing',88 link: '/commands/aliasing/',89 },90 {91 text: 'Waiting',92 link: '/commands/waiting/',93 },94 {95 text: 'Network Requests',96 link: '/commands/network-requests/',97 },98 {99 text: 'Files',100 link: '/commands/files/',101 },102 {103 text: 'Local Storage',104 link: '/commands/local-storage/',105 },106 {107 text: 'Cookies',108 link: '/commands/cookies/',109 },110 {111 text: 'Spies, Stubs & Clocks',112 link: '/commands/spies-stubs-clocks/',113 },114 ],115 },116 { text: 'Utilities', link: '/utilities/' },117 { text: 'Cypress API', link: '/cypress-api/' },118 ],119 sidebar: 'auto',120 algolia: {121 // DANGER 🧨💀: ONLY USE ALGOLIA PUBLIC SEARCH-ONLY API KEY122 apiKey: 'd2cc2084df39806bdefb04f60f16e856',123 indexName: 'cypress-examples',124 appId: '48DTXR75RW',125 },126 },127 markdown: {128 extendMarkdown(md) {129 if (!_highlight) {130 _highlight = md.options.highlight131 }132 // every time we see HTML code block133 // it is part of Cypress mini test134 // so we really want to show the HTML source135 // AND mount it as a live example block to run tests against136 md.options.highlight = (str, lang) => {137 if (lang !== 'html') {138 return _highlight(str, lang)139 }140 const highlightedHtml = _highlight(str, 'html')141 return (142 highlightedHtml +143 `144 <div class="example">145 ${str}146 </div>147 `148 )149 }150 },151 },...

Full Screen

Full Screen

run-tests.js

Source:run-tests.js Github

copy

Full Screen

1const cypress = require('cypress');2const glob = require('glob');3const Promise = require('bluebird');4const fs = require('fs');5require('console.table');6const runOneSpec = (spec, config) => {7 return cypress8 .run({9 config: {10 video: false,11 ...config,12 },13 spec: spec,14 })15 .then((result) => {16 if (result.failures) {17 console.error('Could not execute tests');18 console.error(result.message);19 process.exit(1); // abort testrun fast20 }21 return result;22 })23 .catch((err) => {24 console.error(err.message);25 // process.exit(1);26 });27};28glob('**/*in*spec.js', (err, specs) => {29 if (err) {30 console.error(err);31 process.exit(2);32 }33 console.table('Running last modified spec first', specs);34 var configs = [35 {36 env: {37 NO_COMMAND_LOG: 1,38 },39 },40 {41 env: {42 NO_COMMAND_LOG: 0,43 },44 },45 ];46 configs.forEach((config) => {47 Promise.mapSeries(specs, (specs) => runOneSpec(specs, config)).then((runResults) => writeReport(runResults, config));48 });49});50function writeReport(runResults, config) {51 // information about each test run is available52 // see the full NPM API declaration in53 // https://github.com/cypress-io/cypress/tree/develop/cli/types54 const summary = runResults.map((run) => {55 var firstRun = run.runs ? run.runs[0] : {};56 var runReport = {57 spec: firstRun.spec.name,58 totalDuration: run.totalDuration,59 reporterDuration: firstRun.reporterStats.duration,60 runStatsDuration: firstRun.stats.duration,61 browserName: run.browserName,62 browserVersion: run.browserVersion,63 osName: run.osName,64 // osVersion: run.osVersion,65 cypressVersion: run.cypressVersion,66 video: run.config.video,67 report: run.config.report,68 resolvedNodeVersion: run.config.resolvedNodeVersion,69 noCommandLog: run.config.env.NO_COMMAND_LOG,70 // config: JSON.stringify(config, null, 2),71 };72 //console.log(runReport);73 return runReport;74 });75 var overallDuration = summary.reduce((total, curr) => total + curr.totalDuration, 0);76 const shortSummary = {77 cypressVersion: summary[0].cypressVersion,78 browserName: summary[0].browserName,79 browserVersion: summary[0].browserVersion,80 osName: summary[0].osName,81 resolvedNodeVersion: summary[0].resolvedNodeVersion,82 overallDuration,83 video: summary[0].video,84 noCommandLog: summary[0].noCommandLog,85 };86 console.log('Short summary', shortSummary);87 var fileName = `run-stats.csv`;88 if (!fs.existsSync(fileName)) {89 fs.writeFileSync(fileName, csvHeader(shortSummary));90 }91 fs.appendFileSync(fileName, csvContent(shortSummary));92 // fs.appendFileSync(`run-stats.csv`, csvHeader(summary));93 // fs.writeFileSync(94 // `logs/cypress(${cypressVersion})-video(${video})-commandlog(${commandLog})-duration(${overallDuration})-${new Date().getTime()}.log`,95 // JSON.stringify(summary, null, 2)96 // );97}98function csvHeader(obj) {99 // Use first element to choose the keys and the order100 var keys = Object.keys(obj);101 // Build header102 var result = keys.join(',') + '\r\n';103 return result;104}105function csvContent(obj) {106 // Use first element to choose the keys and the order107 var keys = Object.keys(obj);108 var result = '';109 // Add the rows110 result += keys.map((k) => `${obj[k]}`).join(',') + '\r\n';111 return result;112}113// function csvHeader(array) {114// // Use first element to choose the keys and the order115// var keys = Object.keys(array[0]);116// // Build header117// var result = keys.join(',') + '\r\n';118// return result;119// }120// function csvContent(array) {121// // Use first element to choose the keys and the order122// var keys = Object.keys(array[0]);123// var result = '';124// // Add the rows125// array.forEach(function (obj) {126// result += keys.map((k) => `${obj[k]}`).join(',') + '\r\n';127// // result += keys.map((k) => `"${(obj[k] + '').replace(/"/g, '""')}"`).join(',') + '\r\n';128// });129// return result;...

Full Screen

Full Screen

spec.js

Source:spec.js Github

copy

Full Screen

1require('mocha-banner').register()2const cypress = require('cypress')3const chdir = require('chdir-promise')4const join = require('path').join5const fromFolder = join.bind(null, __dirname)6const snapshot = require('snap-shot-it')7const la = require('lazy-ass')8const is = require('check-more-types')9const debug = require('debug')('test')10const R = require('ramda')11const importantProperties = [12 'cypressVersion',13 'totalDuration',14 'totalSuites',15 'totalTests',16 'totalFailed',17 'totalPassed',18 'totalPending',19 'totalSkipped',20 'browserName',21 'browserVersion',22 'osName',23 'osVersion'24]25const pickImportant = R.pick(importantProperties)26const normalize = output => {27 la(is.unemptyString(output.cypressVersion), 'has Cypress version', output)28 la(is.positive(output.totalDuration), 'has duration', output)29 la(is.unemptyString(output.browserVersion), 'has browserVersion', output)30 la(is.unemptyString(output.osName), 'has osName', output)31 la(is.unemptyString(output.osVersion), 'has osVersion', output)32 output.cypressVersion = '0.0.0'33 output.totalDuration = 'X seconds'34 output.browserVersion = '1.2.3'35 output.osName = 'darwin'36 output.osVersion = '16.7.0'37 return output38}39describe('successful tests', () => {40 const projectFolder = fromFolder('successful')41 beforeEach(() => {42 chdir.to(projectFolder)43 })44 afterEach(chdir.back)45 it('returns with all successful tests', () =>46 cypress.run()47 .then(R.tap(debug))48 .then(normalize)49 .then(pickImportant)50 .then(snapshot)51 )52 it('runs specific spec', () => {53 return cypress.run({54 spec: 'cypress/integration/a-spec.js'55 }).then(R.tap(debug))56 .then((result) => {57 la(result.totalTests === 1, 'there should be single test', result.totalTests)58 })59 })60 it('runs specific spec using absolute path', () => {61 const absoluteSpec = join(projectFolder, 'cypress/integration/a-spec.js')62 debug('absolute path to the spec: %s', absoluteSpec)63 return cypress.run({64 spec: absoluteSpec65 }).then(R.tap(debug))66 .then((result) => {67 la(result.totalTests === 1, 'there should be single test', result.totalTests)68 })69 })70 it('runs a single spec using wildcard', () => {71 return cypress.run({72 spec: 'cypress/integration/a-*.js'73 }).then(R.tap(debug))74 .then((result) => {75 la(result.totalTests === 1, 'there should be single test', result.totalTests)76 })77 })78 it('runs both found specs using wildcard', () => {79 return cypress.run({80 spec: 'cypress/integration/a-*.js,cypress/integration/b-*.js'81 }).then(R.tap(debug))82 .then((result) => {83 la(result.totalTests === 2, 'found both tests', result.totalTests)84 })85 })86})87describe('env variables', () => {88 const projectFolder = fromFolder('env')89 beforeEach(() => {90 chdir.to(projectFolder)91 })92 afterEach(chdir.back)93 it('passes environment variables in the object', () => {94 return cypress.run({95 spec: 'cypress/integration/env-spec.js',96 env: {97 foo: {98 bar: 'baz'99 },100 another: 42101 }102 })103 })104})105describe('failing test', () => {106 beforeEach(() => {107 chdir.to(fromFolder('failing'))108 })109 afterEach(chdir.back)110 it('returns correct number of failing tests', () =>111 cypress.run()112 .then(normalize)113 .then(pickImportant)114 .then(snapshot)115 )116})117// https://github.com/cypress-io/cypress-test-module-api/issues/3118describe('invalid malformed spec file', () => {119 beforeEach(() => {120 chdir.to(fromFolder('invalid'))121 })122 afterEach(chdir.back)123 it('returns with error code', () =>124 // test has reference error on load125 cypress.run({126 spec: './cypress/integration/a-spec.js'127 })128 .then(normalize)129 .then(pickImportant)130 .then(snapshot)131 )...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1#!/usr/bin/env node2// @ts-check3'use strict'4const shell = require('shelljs')5const debug = require('debug')('@bahmutov/cly')6const path = require('path')7const DEFAULT_SCAFFOLD_VERSION = '6'8const initCommand = args => {9 debug('command arguments %o', args)10 if (args.typescript) {11 console.log('scaffolding new Cypress TypeScript project')12 } else {13 console.log('scaffolding new Cypress project')14 }15 debug('working directory %s', process.cwd())16 if (shell.test('-d', 'cypress')) {17 console.error('Found existing folder "cypress", cannot scaffold')18 process.exit(1)19 }20 if (shell.test('-f', 'cypress.json')) {21 console.error('Found existing file "cypress.json", cannot scaffold')22 process.exit(1)23 }24 if (!args.cypressVersion) {25 throw new Error('Unknown Cypress version to scaffold')26 }27 let scaffoldedVersion = args.cypressVersion28 if (scaffoldedVersion.indexOf('.')) {29 scaffoldedVersion = scaffoldedVersion.split('.')[0]30 debug('extracted major version %s', scaffoldedVersion)31 }32 let sourceFolder = path.join(__dirname, '..', scaffoldedVersion)33 if (args.bare) {34 debug('scaffolding bare specs')35 sourceFolder += 'bare'36 } else if (args.typescript) {37 debug('scaffolding TypeScript specs')38 sourceFolder += 'ts'39 }40 debug('checking if folder "%s" exists', sourceFolder)41 if (!shell.test('-d', sourceFolder)) {42 console.error(43 'WARNING: do not have scaffold %s for Cypress version %s',44 sourceFolder,45 scaffoldedVersion46 )47 console.error('Will scaffold for version %s', DEFAULT_SCAFFOLD_VERSION)48 scaffoldedVersion = DEFAULT_SCAFFOLD_VERSION49 sourceFolder = path.join(__dirname, '..', scaffoldedVersion)50 }51 debug('using scaffold folder %s', sourceFolder)52 shell.cp(path.join(sourceFolder, 'cypress.json'), process.cwd())53 shell.cp('-r', path.join(sourceFolder, 'cypress'), process.cwd())54 if (args.typescript) {55 shell.cp(path.join(sourceFolder, 'tsconfig.json'), process.cwd())56 }57 debug('done copying files from %s', sourceFolder)58 console.log(59 '✅ scaffolded "cypress" folder with a single example spec (v%s)',60 scaffoldedVersion61 )62 console.log('you can configure additional options in cypress.json file')63 console.log('see https://on.cypress.io/configuration')64}65// eslint-disable-next-line no-unused-expressions66require('yargs')67 .command({68 command: 'init',69 aliases: 'scaffold',70 desc: 'scaffold Cypress tests',71 builder: {72 cypressVersion: {73 default: DEFAULT_SCAFFOLD_VERSION,74 alias: 'cv',75 desc: 'for Cypress version',76 type: 'string'77 },78 typescript: {79 default: false,80 alias: 't',81 desc: 'scaffold using TypeScript',82 type: 'boolean'83 },84 bare: {85 default: false,86 alias: 'b',87 desc: 'bare spec file, no support, no plugins',88 type: 'boolean'89 }90 },91 handler: initCommand92 })93 .demandCommand()94 .help()...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

1// @ts-check2const assertCypressVersion = (version) => {3 if (!version) {4 throw new Error('Expected version string argument')5 }6 const exactVersionRe = /^\d+\.\d+\.\d+$/7 if (!exactVersionRe.test(version)) {8 throw new Error(9 `Cypress version "${version}" does not match exact version x.y.z`,10 )11 }12}13const findCypressVersion = () => {14 const pkg = require('../package.json')15 const deps = pkg.devDependencies16 const cypressVersion = deps.cypress17 if (!cypressVersion) {18 throw new Error('Cannot find Cypress dev dependency')19 }20 assertCypressVersion(cypressVersion)21 return cypressVersion22}...

Full Screen

Full Screen

useAfterSpec.js

Source:useAfterSpec.js Github

copy

Full Screen

1const { semVer } = require('./semver');2const shouldUseAfterSpec = (config) => {3 const cypressVersion = semVer(config.version);4 if (5 config.isInteractive &&6 cypressVersion.above('7.1.0') &&7 config.experimentalInteractiveRunEvents8 ) {9 return true;10 }11 if (cypressVersion.above('6.7.0')) {12 return true;13 }14 if (cypressVersion.above('6.2.0') && config.experimentalRunEvents) {15 return true;16 }17 return false;18};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { cypressVersion } from 'cypress'2describe('My First Test', function() {3 it('Does not do much!', function() {4 cy.contains('type').click()5 cy.url().should('include', '/commands/actions')6 cy.get('.action-email')7 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1const cypress = require('cypress')2cypress.cypressVersion()3.then((version) => {4 console.log(version)5})6.catch((err) => {7 console.error(err)8})

Full Screen

Using AI Code Generation

copy

Full Screen

1const cypressVersion = require('cypress-version');2const version = cypressVersion.getCypressVersion();3console.log(version);4{5}6const cypressVersion = require('cypress-version');7module.exports = (on, config) => {8 on('task', {9 });10};11before(() => {12 cy.task('cypressVersion').then((version) => {13 console.log(version);14 });15});16describe('Test', () => {17 it('should log the version', () => {18 cy.task('cypressVersion').then((version) => {19 console.log(version);20 });21 });22});23describe('Test 2', () => {24 it('should log the version', () => {25 cy.task('cypressVersion').then((version) => {26 console.log(version);27 });28 });29});30describe('Test 3', () => {31 it('should log the version', () => {32 cy.task('cypressVersion').then((version) => {33 console.log(version);34 });35 });36});37describe('Test 4', () => {38 it('should log the version', () => {39 cy.task('cypressVersion').then((version) => {40 console.log(version);41 });42 });43});44describe('Test 5', () => {45 it('should log the version', () => {46 cy.task('cypressVersion').then((version) => {47 console.log(version);48 });49 });50});51describe('Test 6', () => {52 it('should log the version', () => {53 cy.task('cypressVersion').then((version) => {54 console.log(version);55 });56 });57});58describe('Test 7', () =>

Full Screen

Using AI Code Generation

copy

Full Screen

1const cypressVersion = require('cypress').cypressVersion2cy.log(cypressVersion)3describe('cypressVersion', () => {4 it('prints Cypress version', () => {5 cy.cypressVersion()6 })7})8const cypressVersion = require('cypress').cypressVersion9cy.log(cypressVersion)10describe('cypressVersion', () => {11 it('prints Cypress version', () => {12 cy.cypressVersion()13 })14})15const cypressVersion = require('cypress').cypressVersion16cy.log(cypressVersion)17describe('cypressVersion', () => {18 it('prints Cypress version', () => {19 cy.cypressVersion()20 })21})

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful