I am developing a Vue.js app for a website frontend.
For this app I would like to use Unit and E2E tests. I built my project with vue-cli.
From my understanding, vue-cli uses Karma for unit tests and Nightwatch + Selenium for E2E tests.
My .gitlab-ci.yml looks like the following:
stages:
- test
test:express:
image: node:boron
stage: test
script:
- cd backend/
- npm install --progress=false
- ./node_modules/.bin/jasmine
test:vue:
image: node:boron
stage: test
script:
- cd frontend/
- npm install --progress=false
- npm test
npm test runs e2e and unit tests and works on local computers. The Unit tests run smoothly and the Selenium brings up a Chrome window and uses the E2E tests.
The problem is that don't know how to run E2E Selenium tests on GitLab CI. It keeps giving me an error saying:
Could not connect to Selenium Server. Have you started the Selenium Server yet?, although it says two lines before that it has already created a Selenium server.
How can I run E2E Selenium tests on GitLab CI? If this is not achievable, what kind of E2E can I run on GitLab CI?
CI script:
npm install wget
https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
apt install -y ./google-chrome-stable_current_amd64.deb apt-get
install -y default-jdk
npm run test:e2e:headless
package.json :
test:e2e:headless : "vue-cli-service test:e2e --config ./tests/e2e/main-test/nightwatch.conf.js --env chromeHeadless "
“dependencies”: {
“chromedriver”: “2.46.0”,
“selenium-server”: “3.9.0”
}
nightwatch config :
selenium: {
start_process: true,
server_path: require('selenium-server').path,
port: 4449,
cli_args: {
'webdriver.chrome.driver': require('chromedriver').path
}
},
test_settings: {
default: {
selenium_port: 4449,
selenium_host: 'localhost',
silent: true,
globals: {
devServerURL: 'http://localhost:' + config.devServer.port
}
},
chromeHeadless: {
desiredCapabilities: {
browserName: 'chromeHeadless',
javascriptEnabled: true,
acceptSslCerts: true,
chromeOptions: {
args: [
'headless',
'disable-gpu',
'no-sandbox'
]
}
}
}
You have to bring Selenium yourself to your pipeline in order to use it.
To do so, you should use something like gitlab-selenium-server as it is described in the repo's README.
Another option is to use a GitLab CI service as described in this blog post.
Related
I have a repo that holds two applications, a django one, and a react one.
I'm trying to integrate tests into the pipeline for the django application, currently, the message I'm getting in the pipeline is:
python backend/manage.py test
+ python backend/manage.py $SECRET_KEY
System check identified no issues (0 silenced).
---------------------------------------------------------------
Ran 0 $SECRET_KEYS in 0.000s
However, running the same command in my local docker container finds 11 tests to run. I'm not sure why they aren't being found in the pipeline
My folder structure is like this
backend/
- ...
- app/
-- tests/
- manage.py
frontend/
- ...
bitbucket-pipelines.yml
and my pipelines file:
image: python:3.8
pipelines:
default:
- parallel:
- step:
name: Test
caches:
- pip
script:
- pip install -r requirements.txt
- python backend/manage.py test
The same issue I was facing(django application) in bitbucket pipeline and in local it's working fine when we are doing it in bitbucket pipeline it's not working, it's installed all the requirements and related packages the last command was not running, my assumption is sqlite3 is not support in bitbucket pipeline.
I have my amplify project connected to gitlab
And added this segment to run API Jest tests:
test:
phases:
preTest:
commands:
- npm install
test:
commands:
- npm test
But the test section became and stays as "pending"
In logs I see only the following:
# Starting phase: preTest
# Executing command: npm install
2020-10-28T05:58:39.496Z [WARNING]: npm
Can anyone help with this?
Running test in watch mode solved the problem:
npm test -- --watchAll=false
I am trying to build a JS application with unit tests.
So when i give npm run build build should be successful only if all the Jest tests have passed.
I have two npm scripts now.
One for testing and one for building production build
"scripts": {
"build": "sudo webpack --mode=production",
"test": "jest"
}
A simple solution which will work with all environments including windows is appending both the scripts with && operator.
So the created new script will be like build:test below
"scripts": {
"build:test": "npm run test && npm run build ",
"build": "sudo webpack --mode=production",
"test": "jest",
}
&&
operator will see to that npm run build will be executed only if npm run test exits with successful return code and jest takes care of returning error code to terminal when any tests fail.
I deployed a create-react-app on GitHub Pages using a mix of these 2 tutorials (https://create-react-app.dev/docs/deployment & https://github.com/gitname/react-gh-pages). It's working just fine.
But this webpage is supposed to evolve regularly, I have some content to add.
Is there a way to modify the deployed app? How can I push the changes I would make in my local directory to gh-pages (production mode)? Do I need to run npm build again after my additions?
For the moment I have the development mode on master branch. I think it's the build mode on gh-pages, although I don't have any other branch.
Thank you for your help.
What I did to deploy:
Terminal
$ npm install --save gh-pages
$ git init
$ git remote add origin https://github.com/REMOTE
$ npm run deploy
Package.json
{
"homepage": "https://USER-PAGE.github.io/",
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -b master -d build",
},
"devDependencies": {
"gh-pages": "^2.1.1"
}
}
To modify the site just make the changes and then git add, commit and push like one would normally do to the required branch.
Then again run the command:
npm run deploy
I am a noob in Travis CI. I created a simple hello world flask app and integrated that with Travis CI. My .travis.yml is like this
os:
- linux
language: python
python:
- "2.6"
- "2.7"
# command to install dependencies
script: python app.py
branches:
only:
- master
Where app.py is the application.The app.py ran successfully while building since it doesnt return anything travis considered it as build fail. What could be the possible fix? I am attaching a screenshot of the build error message.
You are running the dev server unconditionally. Place it in a guard:
if __name__ == '__main__':
app.run()
Change the command to run your tests, rather than the app. Travis is used to build and test, not run your server.