Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# bitbucket-pipelines.yml
# this is example using cypress/base docker image
image: cypress/base:10
options:
max-time: 30
# job definition for running E2E tests in parallel with KnapsackPro.com
e2e: &e2e
name: Run E2E tests with @knapsack-pro/cypress
caches:
- node
- cypress
script:
# run web application in the background
- npm run start:ci &
# env vars from https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
- export KNAPSACK_PRO_CI_NODE_BUILD_ID=$BITBUCKET_BUILD_NUMBER
- export KNAPSACK_PRO_COMMIT_HASH=$BITBUCKET_COMMIT
- export KNAPSACK_PRO_BRANCH=$BITBUCKET_BRANCH
- export KNAPSACK_PRO_CI_NODE_TOTAL=$BITBUCKET_PARALLEL_STEP
- export KNAPSACK_PRO_CI_NODE_INDEX=$BITBUCKET_PARALLEL_STEP_COUNT
# https://github.com/KnapsackPro/knapsack-pro-cypress#configuration-steps
- export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true
- $(npm bin)/knapsack-pro-cypress
artifacts:
# store any generated images and videos as artifacts
- cypress/screenshots/**
- cypress/videos/**
pipelines:
default:
- step:
name: Install dependencies
caches:
- npm
- cypress
- node
script:
- npm ci
- parallel:
# run N steps in parallel
- step:
<<: *e2e
- step:
<<: *e2e
- step:
<<: *e2e
definitions:
caches:
npm: $HOME/.npm
cypress: $HOME/.cache/Cypress
# this is example using node docker image. The cypress docker image is used on the parallel step level.
image: node:14.15.5
options:
max-time: 30
e2e: &e2e
name: Run parallel tests with @knapsack-pro/cypress
caches:
- npm
- cypress
# cypress docker image
image: cypress/included:6.5.0
# env vars from https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
script:
- npm install
- npm run start
# env vars from https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
- export KNAPSACK_PRO_COMMIT_HASH=$BITBUCKET_COMMIT
- export KNAPSACK_PRO_BRANCH=$BITBUCKET_BRANCH
- export KNAPSACK_PRO_CI_NODE_BUILD_ID=$BITBUCKET_BUILD_NUMBER
- export KNAPSACK_PRO_CI_NODE_TOTAL=$BITBUCKET_PARALLEL_STEP
- export KNAPSACK_PRO_CI_NODE_INDEX=$BITBUCKET_PARALLEL_STEP_COUNT
# https://github.com/KnapsackPro/knapsack-pro-cypress#configuration-steps
- export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true
- $(npm bin)/knapsack-pro-cypress
artifacts:
- cypress/reports/**
- cypress/videos/**
pipelines:
default:
# How to run parallel tests https://support.atlassian.com/bitbucket-cloud/docs/set-up-or-run-parallel-steps/
# You should add KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS as secure variable https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
# to not expose Knapsack Pro API token in this config file.
- parallel:
# run N steps in parallel
- step:
<<: *e2e
- step:
<<: *e2e
- step:
<<: *e2e
definitions:
caches:
npm: $HOME/.npm
cypress: $HOME/.cache/Cypress
@ArturT

This comment has been minimized.

Copy link
Owner Author

@ArturT ArturT commented Apr 10, 2021

Learn more about how Queue Mode in Knapsack Pro can distribute tests to get the shortest CI build time:
https://docs.knapsackpro.com/2020/how-to-speed-up-ruby-and-javascript-tests-with-ci-parallelisation

@hvaandres

This comment has been minimized.

Copy link

@hvaandres hvaandres commented Apr 12, 2021

This is the error message that I'm getting:

 $(npm bin)/knapsack-pro-cypress
npm ERR! missing script: start:ci
npm ERR! 
npm ERR! Did you mean this?
npm ERR!     start
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-04-12T18_36_37_518Z-debug.log
2021-04-12T18:36:38.223Z [@knapsack-pro/core] info: POST https://api.knapsackpro.com/v1/queues/queue
2021-04-12T18:36:38.560Z [@knapsack-pro/core] error: 422 Unprocessable Entity
Request ID:
ba94ce33-7ae0-4341-91b7-dee1ebc279d9
Response error body:
{ errors: [ { node_total: [ 'must be greater than or equal to 2' ] } ] }
(node:70) UnhandledPromiseRejectionWarning: Error: Knapsack Pro API returned an error. See the above logs.
    at /opt/atlassian/pipelines/agent/build/node_modules/@knapsack-pro/core/lib/knapsack-pro-core.js:46:23
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:70) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:70) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

@hvaandres

This comment has been minimized.

Copy link

@hvaandres hvaandres commented Apr 12, 2021

If I run the second option, I get the following error message:

+ npm run start
> installation_cypress@1.0.0 start
> my-server -p 3030
sh: 1: my-server: not found
npm ERR! code 127
npm ERR! path /opt/atlassian/pipelines/agent/build
npm ERR! command failed
npm ERR! command sh -c my-server -p 3030
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-04-12T19_16_04_384Z-debug.log
@ArturT

This comment has been minimized.

Copy link
Owner Author

@ArturT ArturT commented Apr 12, 2021

@hvaandres

npm run start command is specific to a project. Maybe you need to start web application in your project with a different command like npm run start:ci. You can check that in your project package.json.

Regarding error

Response error body: { errors: [ { node_total: [ 'must be greater than or equal to 2' ] } ] }

You need to double-check if env var has value BITBUCKET_PARALLEL_STEP and BITBUCKET_PARALLEL_STEP_COUNT. They are available in parallel steps only.

to display value run:

echo $BITBUCKET_PARALLEL_STEP 
echo $BITBUCKET_PARALLEL_STEP_COUNT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment