Fix travis by running browser tests in headless mode (#3001)

* Fix travis by running browser tests in headless mode
This commit is contained in:
Sam El-Husseini
2019-09-11 17:25:22 -07:00
committed by GitHub
parent 042ddb043b
commit 09d2a167f9
16 changed files with 66 additions and 92 deletions

View File

@@ -1,21 +1,20 @@
language: node_js
os: linux
dist: trusty
dist: xenial
node_js:
- 8
- 10
addons:
chrome: stable
firefox: latest
apt:
packages:
- google-chrome-stable
# TODO (#2114): reenable osx build.
# - os: osx
# node_js: stable
# osx_image: xcode8.3
# addons:
# firefox: latest
env:
- TRAVIS_CI=true
before_script:
# Symlink closure library used by test/jsunit
- ln -s $(npm root)/google-closure-library ../closure-library
@@ -23,6 +22,5 @@ before_script:
- if [ "${TRAVIS_OS_NAME}" == "linux" ]; then ( tests/scripts/setup_linux_env.sh ) fi
- if [ "${TRAVIS_OS_NAME}" == "osx" ]; then ( tests/scripts/setup_osx_env.sh ) fi
- sleep 2
script:
- tests/run_all_tests.sh
- npm run test:run

View File

@@ -23,7 +23,11 @@
"package": "gulp package",
"prepare": "gulp blockly_node_javascript_en",
"release": "gulp release",
"test": "tests/run_all_tests.sh",
"test": "concurrently 'npm run test:prepare' 'sleep 5 && npm run test:run'",
"test:run": "tests/run_all_tests.sh",
"test:prepare": "npm run test:setupselenium && npm run test:startselenium",
"test:setupselenium": "selenium-standalone install --config=./tests/scripts/selenium-config.js",
"test:startselenium": "selenium-standalone start --config=./tests/scripts/selenium-config.js",
"typings": "gulp typings"
},
"main": "./index.js",
@@ -38,6 +42,7 @@
"license": "Apache-2.0",
"devDependencies": {
"chai": "^4.2.0",
"concurrently": "^4.1.2",
"eslint": "^5.13.0",
"fs": "0.0.1-security",
"google-closure-compiler": "^20190618.0.0",
@@ -54,6 +59,7 @@
"mocha": "^6.1.4",
"pixelmatch": "^4.0.2",
"pngjs": "^3.4.0",
"selenium-standalone": "^6.16.0",
"rimraf": "^2.6.3",
"typescript-closure-tools": "^0.0.7",
"webdriverio": "^5.11.5",

View File

@@ -57,6 +57,12 @@ async function runGeneratorsInBrowser() {
browserName: 'firefox'
}
};
// Run in headless mode on Travis.
if (process.env.TRAVIS_CI) {
options.capabilities['moz:firefoxOptions'] = {
args: ['-headless']
};
}
var url = 'file://' + __dirname + '/index.html';
var prefix = 'tests/generators/tmp/generated';

View File

@@ -37,6 +37,12 @@ async function runJsUnitTestsInBrowser() {
browserName: 'chrome'
}
};
// Run in headless mode on Travis.
if (process.env.TRAVIS_CI) {
options.capabilities['goog:chromeOptions'] = {
args: ['--headless', '--no-sandbox', '--disable-dev-shm-usage']
};
}
var url = 'file://' + __dirname + '/index.html';
console.log('Starting webdriverio...');

View File

@@ -37,6 +37,12 @@ async function runMochaTestsInBrowser() {
browserName: 'chrome'
}
};
// Run in headless mode on Travis.
if (process.env.TRAVIS_CI) {
options.capabilities['goog:chromeOptions'] = {
args: ['--headless', '--no-sandbox', '--disable-dev-shm-usage']
};
}
var url = 'file://' + __dirname + '/index.html';
console.log('Starting webdriverio...');

View File

@@ -49,9 +49,6 @@ run_test_command () {
fi
}
# Set up the environment (Chrome, Selenium, etc.)
run_test_command "test_setup" "tests/scripts/test_setup.sh"
# Lint the codebase.
run_test_command "eslint" "eslint ."

View File

@@ -113,6 +113,12 @@ async function buildBrowser(url, isRtl) {
},
logLevel: 'warn'
};
// Run in headless mode on Travis.
if (process.env.TRAVIS_CI) {
options.capabilities['goog:chromeOptions'] = {
args: ['--headless', '--no-sandbox', '--disable-dev-shm-usage']
};
}
console.log('Starting webdriverio...');
const browser = await webdriverio.remote(options);
var injectBlockly = function(isRtl) {

View File

@@ -1,17 +0,0 @@
#!/bin/bash
os_name=`uname`
chromedriver_dir="chromedriver"
if [ ! -d $chromedriver_dir ]; then
mkdir $chromedriver_dir
fi
echo "downloading chromedriver"
if [[ $os_name == 'Linux' && ! -f $chromedriver_dir/chromedriver ]]; then
cd chromedriver && curl -L https://chromedriver.storage.googleapis.com/2.44/chromedriver_linux64.zip > tmp.zip && unzip -o tmp.zip && rm tmp.zip
# wait until download finish
sleep 5
elif [[ $os_name == 'Darwin' && ! -f $chromedriver_dir/chromedriver ]]; then
cd chromedriver && curl -L https://chromedriver.storage.googleapis.com/2.44/chromedriver_mac64.zip | tar xz
sleep 5
fi

View File

@@ -1,15 +0,0 @@
#!/bin/bash
os_name=`uname`
if [ -f geckodriver ]; then
exit 0
fi
echo "downloading gechdriver"
if [[ $os_name == 'Linux' ]]; then
cd ../ && curl -L https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz | tar xz
sleep 5
elif [[ $os_name == 'Darwin' ]]; then
cd ../ && curl -L https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-macos.tar.gz | tar xz
sleep 5
fi

View File

@@ -1,14 +0,0 @@
#!/bin/bash
DIR="../webdriverio-test"
FILE=selenium-server-standalone-3.9.1.jar
if [ ! -d $DIR ]; then
mkdir $DIR
fi
echo "downloading selenium jar"
if [ ! -f $DIR/$FILE ]; then
cd $DIR && curl -O http://selenium-release.storage.googleapis.com/3.9/selenium-server-standalone-3.9.1.jar
sleep 5
fi

View File

@@ -0,0 +1,27 @@
/* eslint-disable */
module.exports = {
// check for more recent versions of selenium here:
// https://selenium-release.storage.googleapis.com/index.html
version: '3.9.1',
baseURL: 'https://selenium-release.storage.googleapis.com',
drivers: {
chrome: {
// check for more recent versions of chrome driver here:
// https://chromedriver.storage.googleapis.com/index.html
version: '77.0.3865.40',
arch: process.arch,
baseURL: 'https://chromedriver.storage.googleapis.com'
},
firefox: {
// check for more recent versions of chrome driver here:
// https://chromedriver.storage.googleapis.com/index.html
version: '0.21.0',
arch: process.arch,
baseURL: 'https://github.com/mozilla/geckodriver/releases/download'
},
},
requestOpts: { // see https://github.com/request/request#requestoptions-callback
timeout: 10000
},
};

View File

@@ -1,10 +0,0 @@
#!/bin/bash
#check if selenium server is up running
pid=`lsof -ti tcp:4444`
if [ $? -eq 0 ]
then
kill -9 $pid
fi
java -jar -Dwebdriver.gecko.driver=../geckodriver -Dwebdriver.chrome.driver="chromedriver/chromedriver" ../webdriverio-test/selenium-server-standalone-3.9.1.jar &

View File

@@ -3,6 +3,6 @@
if [ "${TRAVIS_OS_NAME}" == "linux" ]
then
export CHROME_BIN="/usr/bin/google-chrome"
export DISPLAY=:99.0
sh -e /etc/init.d/xvfb start &
npm run test:prepare > /dev/null &
fi

View File

@@ -4,5 +4,6 @@ if [ "${TRAVIS_OS_NAME}" == "osx" ]
then
brew cask install google-chrome
sudo Xvfb :99 -ac -screen 0 1024x768x8 &
export CHROME_BIN="/Applications/Google Chrome.app"
export CHROME_BIN="/Applications/Google Chrome.app"
npm run test:prepare > /dev/null &
fi

View File

@@ -1,23 +0,0 @@
#!/bin/bash
EXIT_STATUS=0
function check_command {
"$@"
local STATUS=$?
if [ $STATUS -ne 0 ]; then
echo "error with $1 ($STATUS)" >&2
EXIT_STATUS=$STATUS
fi
}
check_command tests/scripts/get_geckdriver.sh
sleep 5
check_command tests/scripts/get_selenium.sh
sleep 5
check_command tests/scripts/get_chromedriver.sh
sleep 10
check_command tests/scripts/selenium_connect.sh
sleep 10
exit $EXIT_STATUS