yarn serve in background - vue.js

I'm trying to configure gitlab CI/CD for cypress e2e testing on my vue app which uses yarn for package management. cypress documents are all written for npm cypress gitlab ci/cd configuration tutorial
# start the server in the background
- npm run start:ci &
# run Cypress tests
- npx cypress run --browser firefox
is there a way to start server in background for yarn? like running yarn serve but in background.

There is an issue with the command yarn serve&. It will still give you this screen when done compiling:
I found a way to work around this through pm2 and this command
pm2 start yarn --interpreter bash --name api -- start

Related

Self-hosted GitLab Runner with shell executor can’t find npm

I’m configuring a very simple CI job. GitLab Runner is running on my own server, the specific runner for this project has been registered, with the shell executor, as I want to simply run shell commands.
stages:
- build
build:
stage: build
script:
- npm install
- npm run build
artifacts:
paths:
- "public/dist/main.js"
only:
- master
The job fails at the first command, npm install, with npm: command not found. I just installed npm and node via npm. If I SSH on my server and run npm -v, I can see version 8.5.5 is installed. If I sudo su gitlab-runner, which I suppose is what GitLab Runner is running as, npm -v works just as well.
I installed npm while gitlab-runner was already running. So I ran service gitlab-runner restart, thinking that it had to reevaluate its PATH, but it didn’t fix the issue.
I fixed it by simply adding this command before npm install: . ~/.bashrc.
I’m not sure why gitlab-runner didn’t properly read .bashrc before, even though I restarted it. Maybe it’s not supposed to? That would be contrary to what’s said in the GitLab CI runners docs.
N.B.: A key element in me being able to debug this was to clone the repo on a folder on my server, cd into it, and run gitlab-runner exec shell build after any (local) change to .gitlab-ci.yml. Skipping the whole commit + push + wait was a huge time (and sanity) saver.

Not Found Error on localhost:3400 on Github Actions

So I want to build and run my svelte application on Github Actions (and the fastapi backend) and then do cypress tests on them. Running fastapi backend works so far.
The Problem is even when npm logs
Your application is ready~! 🚀
- Local: http://localhost:3400
cypress get's a not found error on cy.visit(). I also tried just waiting on localhost:3400 (for 120 seconds) but this doesn't work either.
In my main.yml looks like this:
- name: Build and run Svelte app
run: |
npm install cypress
cd frontend/app
npm install
npm run build
npm run start &
sleep 120
cd ..
cd ..
npx cypress run
Does anyone has a clue why this happens? Has been very frustrating.
Later I want to auto dockerize and deploy. Should I already go on with this, so maybe it gets easier once it's dockerized?

What is the equivalent of npm run start:ci in yarn?

I'm trying to configure Bitbucket CI/CD for cypress testing on my vue app which uses yarn for package management.
Is there any way to start server in background by yarn?
Thanks in advance
Welcome to stackoverflow Alessandra.
yarn start command is equivalent to npm run start
However if you have created a custom command in your package.json for start:ci you can use equivalent yarn command as yarn start:ci
You can also use yarn run start:ci however its run is redundent here. Please see this documentation
https://classic.yarnpkg.com/lang/en/docs/cli/run/

NodeJS docker image to run Angular test in gitlab-ci

I have a small Angular app which I am try to build using gitlab-ci and node docker image, when I try to run the test using the command npm run test it fails with the following error :
ERROR [launcher]: No binary for Chrome browser on your platform. Please, set "CHROME_BIN" env variable.
gitlab-ci.yml
stages:
- build
variables:
NPM_CONFIG_REGISTRY: https://test.com/xx/api/npm/npm-all
build:
stage: build
image: node:12.9
script:
- npm install
- npm run build:prod
- npm run test
tags:
- DOCKER
In the above code npm run test executes ng test as configured in the package.json
I was able to run the build but when I run the test it looks for a chrome browser, I also tried running the test in a headless way using the below command but resulted in the same error :
ng test --no-watch --browsers=ChromeHeadless
How do I add the chrome feature to this build ?
Either install Chrome by yourself or try an existing Docker image that already includes it.

When I run cypress as npm run cypress run build fails

I have installed cypress using npm as npm install cypress --save-dev .
I used the same command in .gitlab-ci.yml file
When i run the command npm run cypress run locally , IDE opens and when i double click the spec.js file , then the tests run.
But I i use the same command on the gitlab pipeline , it says
cypress open "run"
It looks like this is your first time using Cypress: 4.1.0
[07:45:16] Verifying Cypress can run /osmc/ux/framework-acceptance-tests/cache/Cypress/4.1.0/Cypress [started]
[07:45:18] Verifying Cypress can run /osmc/ux/framework-acceptance-tests/cache/Cypress/4.1.0/Cypress [completed]
Opening Cypress...
and build fails .
Am i missing anything here ?
It's because it's opening the test runner, which is used locally via npx cypress open.
From that output it looks like you're running npx cypress open run, which isn't a real command and will open the runner
In CI you need to use npx cypress run, which will run tests without user interaction. https://docs.cypress.io/guides/guides/command-line.html#How-to-run-commands
Your gitlab.yml file should accomodate for the npm installations.
One example is as below. Meanwhile also please check the test/run command for your specs under package.json file. use the same command to trigger the test in pipeline.
stages:
- test
test:
image: cypress/browsers:node12.14.1-chrome85
stage: test
script:
npm i
npm run start:ci &
npx cypress run
You should have your .gitlab-ci.yml with:
stages:
- test
cypress-test:
image: cypress/browsers:node16.14.0-slim-chrome99-ff97
stage: test
script:
- npm ci
- npx cypress run