Thursday, 4 November 2021

Gitlab CI - server gets 'killed' before Cypress tests can run

I am running a CI pipeline in Gitlab which runs some Cypress integration tests as part of the testing stage. The tests are working absolutely fine on my machine locally but when I try and run them in Gitlab CI it appears that the Gitlab runner is killing my local server before I can run my Cypress tests against it. Here is my Gitlab config:

variables:
  API_BASE_URL: https://t.local.um.io/api
  CYPRESS_API_BASE_URL: https://t.local.um.io/api
  npm_config_cache: '$CI_PROJECT_DIR/.npm'
  CYPRESS_CACHE_FOLDER: '$CI_PROJECT_DIR/cache/Cypress'

cache:
  paths:
    - node_modules/
    - cache/Cypress

stages:
  - install
  - build
  - tests

install:
  image: cypress/browsers:node14.15.0-chrome86-ff82
  stage: install
  cache:
    key: 'e2eDeps'
    paths:
      - node_modules/
      - cache/Cypress/
  script:
    - npm ci

build:
  stage: build
  dependencies:
    - install
  script:
    - npm run build
  artifacts:
    expire_in: 1 days
    when: on_success

tests:
  image: cypress/browsers:node14.15.0-chrome86-ff82
  stage: tests
  script:
    - npm ci
    - npm run test:ci

And here are the relevant package.json scripts that the above config runs in CI:

  "scripts": {
    "build": "webpack --config webpack.prod.js",
    "dev": "webpack serve --config webpack.dev.js",
    "start:ci": "export NODE_OPTIONS=--max_old_space_size=4096 serve dist --no-clipboard --listen ${PORT:-3000}",
    "test": "cross-env NODE_ENV=test && npm run test:cypress && npm run test:jest",
    "test:ci": "cross-env NODE_ENV=test && start-server-and-test start:ci http-get://localhost:3000 test",
    "test:cypress": "cypress run --headless --browser chrome",
    "test:jest": "jest",
  },

It is the final stage tests that is currently failing. Here is the console output from the Gitlab runner, you can see where it says 'killed' then 'err no 137' it appears that it just stops the start:ci process which is what runs my local server so the integration tests can run against them.

enter image description here

Finally here is a small snippet of my test, I use the cy.visit command which never responds as the server is killed:

describe('Code entry page - API responses are managed correctly', () => {
  beforeEach(() => {
    cy.visit(routes.APP.HOME); // this just times out
  });
...

EDIT I have tried running the test:ci script inside of the exact same docker container that it uses (cypress/browsers:node14.15.0-chrome86-ff82) locally (not in gitlabci) and it works no problem. The issue must lay with Gitlab surely?



from Gitlab CI - server gets 'killed' before Cypress tests can run

No comments:

Post a Comment