0

I'm currently having react project which contains some unit, integrations tests. I'm using msw for mocking data and hosting mock handlers. It works without any issue on local.

Problem: I'm having testing step in my GitHub Actions pipeline, not having any error or fails (as far I can see from logs) but I'm receiving errors logs of connection failure while not having any issue like this on my local. I suspect it is server connection, but can't figure out what should I do fix this.

Such as:

stderr | unknown test
Error: Error: connect ECONNREFUSED 127.0.0.1:5678
    at Object.dispatchError (/runner/_work/project/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:63:19)
    at EventEmitter.<anonymous> (/runner/_work/project/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18)
    at EventEmitter.emit (node:events:402:35)
    at Request.<anonymous> (/runner/_work/project/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:404:14)
    at Request.emit (node:events:390:28)
    at ClientRequest.<anonymous> (/runner/_work/project/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:127:14)
    at ClientRequest.emit (node:events:390:28)
    at Socket.socketErrorListener (node:_http_client:447:9)
    at Socket.emit (node:events:390:28)
    at emitErrorNT (node:internal/streams/destroy:157:8) undefined

My test setup:

beforeAll(() => {
  server.listen({ onUnhandledRequest: 'warn' });
});

afterEach(() => {
  server.resetHandlers();
});

afterAll(() => {
  server.close();
  vi.restoreAllMocks();
});

configure({ asyncUtilTimeout: 10000 });

GitHub Actions workflow for test:

...
steps:
   - uses: actions/checkout@v3

   - uses: actions/setup-node@v3
     with:
       node-version: '16.13.0'

   - name: Setup yarn
     run: npm install -g yarn


   - name: Install dependencies
     run: yarn install

   - id: run-tests
     name: Run tests
     run: yarn test:coverage-ci
  ...

Script basically is:

test:coverage-ci: "vitest run --coverage.enabled --coverage.reporter='text-summary'"
rufatZZ
  • 743
  • 2
  • 11
  • 27

0 Answers0