3

I have a very basic application which has an html/js frontend, and a json DB hosted by json-server. I have setup a simple e2e test suite in Cypress with 2 tests. This runs completely fine locally, but when I run this on GitHub Actions I get an ECONNREFUSED error:

  Running:  standard-criteria.spec.js                                                       (1 of 1)


  Todo List
    Standard Criteria
      1) "before each" hook for "Loads and renders the Todo List from the server"


  0 passing (1s)
  1 failing

  1) Todo List
       Standard Criteria
         "before each" hook for "Loads and renders the Todo List from the server":
     CypressError: `cy.request()` failed trying to load:

http://localhost:3000/todos

We attempted to make an http request to this URL but the request failed without a response.

We received this error at the network level:

  > Error: connect ECONNREFUSED 127.0.0.1:3000

-----------------------------------------------------------

The request we sent was:

Method: GET
URL: http://localhost:3000/todos

-----------------------------------------------------------

Frustratingly, the setup and running of the server in GitHub Actions, which happens prior to the error showing, indicates that the server IS running and the resource /todos is available:

Run cypress-io/github-action@v5.0.9
Received 6752398 of 6752398 (100.0%), 9.8 MBs/sec
Cache Size: ~6 MB (6752398 B)
/usr/bin/tar -xf /home/runner/work/_temp/3f18ede8-26a0-4695-a13b-b89f0d335c5b/cache.tgz -P -C /home/runner/work/js-dom-todos/js-dom-todos -z
Cache restored successfully
Received 134217728 of 169363420 (79.2%), 128.0 MBs/sec
Received 169363420 of 169363420 (100.0%), 126.8 MBs/sec
Cache Size: ~162 MB (169363420 B)
/usr/bin/tar -xf /home/runner/work/_temp/821a36e6-5b1e-4be7-a3fa-063c54775cb3/cache.tgz -P -C /home/runner/work/js-dom-todos/js-dom-todos -z
Cache restored successfully
/usr/local/bin/npm ci

added 324 packages, and audited 325 packages in 11s

46 packages are looking for funding
  run `npm fund` for details

9 vulnerabilities (5 moderate, 4 high)

To address all issues, run:
  npm audit fix

Run `npm audit` for details.
/usr/local/bin/npx cypress cache list
┌─────────┬───────────────────┐
│ version │ last used         │
├─────────┼───────────────────┤
│ 12.6.0  │ a few seconds ago │
└─────────┴───────────────────┘
start server command "npm run dev:test"
current working directory "/home/runner/work/js-dom-todos/js-dom-todos"
/usr/local/bin/npm run dev:test

> dev:test
> npx json-server --watch db/test_todos.json

[1924:0223/102500.289570:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.

  \{^_^}/ hi!

  Loading db/test_todos.json
  Done

  Resources
  http://localhost:3000/todos

  Home
  http://localhost:3000

  Type s + enter at any time to create a snapshot of the database
  Watching...

Files

github action yml

name: Standard Criteria
on:
  pull_request:
    branches: [ main, jules-cypress-test ]
jobs:
  cypress-e2e-tests:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [ 16.19.1 ]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Cypress run
        uses: cypress-io/github-action@v5.0.9 # Released 2023-02-13
        with:
          browser: chrome

cypress.config.js

const { defineConfig } = require("cypress");

module.exports = defineConfig({
  env: {
    apiUrl: "http://localhost:3000/todos",
  },
  e2e: {
    experimentalStudio: true,
    specPattern: "cypress/tests/**/*.spec.{js,jsx,ts,tsx}",
    // setupNodeEvents(on, config) {
    // }
  }
});

spec file

describe('Todo List', () => {
  beforeEach(() => {
    cy.visit("index.html");
    cy.request(Cypress.env("apiUrl")).as("todos");
  });

  describe('Standard Criteria', () => {
    it('Loads and renders the Todo List from the server', () => {
      cy.get("@todos").should((response) => {
        expect(response.body).to.have.length(3)
      })
  ...

What I have tried

  • Initially, Node version was LTS (V18), but then I downgraded to V16 based on GitHub Issues I've seen about IPV4/6.
  • Setting the action to run with Electron and Chrome browsers (I run on Chrome locally).
  • Setting the wait-on in the action file:
wait-on: 'http://localhost:3000'
wait-on-timeout: 120s
  • Added a curl in a different step to test out the endpoint and that works fine:
  \{^_^}/ hi!

  Loading db/todos.json
  Done

  Resources
  http://localhost:3000/todos

  Home
  http://localhost:3000

  Type s + enter at any time to create a snapshot of the database
  Watching...

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
[
100   226  100   226    0     0  14951      0 --:--:-- --:--:-- --:--:-- 15066
  {
    "id": 1,
    "title": "Feed the cat",
    "completed": false
  },
  {
    "id": 2,
    "title": "Cut the grass",
    "completed": true
  },
  {
    "id": 3,
    "title": "Fix the gutters",
    "completed": true
  }
]GET /todos 200 6.783 ms - 226
  • Updating the node script to npx json-server --watch db/test_todos.json --port 3000 --no-cors
  • I don't see it in your GitHub workflow file, but I assume you are using the [start multiple servers](https://github.com/cypress-io/github-action#start-multiple-servers) command to start the web server and json-server. Is that correct? – John Craft Mar 01 '23 at 16:16

0 Answers0