I am trying to run e2e Cypress tests on Github actions. I build functions, run an emulator and start cypress like to:
npx nx build functions | firebase emulators:start | nx e2e frontend-e2e --watch
This works well on localhost, but fails on GitHub Actions, when the first part of the code tries to connect to the emulators.
cy.request(
"DELETE",
"http://localhost:9099/emulator/v1/projects/****/accounts"
);
It can't reach the emulator on port localhost:9099
, as I would normally do on localhost.
1) Login
runs setup:
CypressError: `cy.request()` failed trying to load:
http://localhost:9099/emulator/v1/projects/****/accounts
We attempted to make an http request to this URL but the request failed without a response.
Is there something I need to do about connecting to localhost port on GitHub Actions?
CodePudding user response:
Solved! The Firebase emulator was throwing an error, but I haven't seen it because I ran it on one line with other commands: npx nx build functions | firebase emulators:start | nx e2e frontend-e2e --watch
I rewrote the job in the workflow:
- name: Cypress run
uses: cypress-io/github-action@v2
with:
browser: chrome
build: npm run integration:build
start: |
npm run integration:emulate
npm run integration:test
Calling custom scripts from package.json
like so:
"integration:build": "nx build functions && nx run frontend:build",
"integration:emulate": "firebase use default && firebase emulators:start",
"integration:test": "nx e2e frontend-e2e --watch",
Then I could see the Firebase error in the log and fixed them. There were two issues:
- Selecting a project before running the emulators (adding
firebase use default
) - Firebase login (great answer from the Firebase team)
After that, the emulators worked just as on localhost