diff --git a/.travis.yml b/.travis.yml index bc0bb84157b..2ad7f41017c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/package.json b/package.json index 981605871a5..615beaacc38 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/generators/run_generators_in_browser.js b/tests/generators/run_generators_in_browser.js index 1a39c6d1227..1674f944230 100644 --- a/tests/generators/run_generators_in_browser.js +++ b/tests/generators/run_generators_in_browser.js @@ -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'; diff --git a/tests/jsunit/run_jsunit_tests_in_browser.js b/tests/jsunit/run_jsunit_tests_in_browser.js index 397b0b107f4..a5358b61df1 100644 --- a/tests/jsunit/run_jsunit_tests_in_browser.js +++ b/tests/jsunit/run_jsunit_tests_in_browser.js @@ -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...'); diff --git a/tests/mocha/run_mocha_tests_in_browser.js b/tests/mocha/run_mocha_tests_in_browser.js index 24d8c4c34dd..b9f73244411 100644 --- a/tests/mocha/run_mocha_tests_in_browser.js +++ b/tests/mocha/run_mocha_tests_in_browser.js @@ -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...'); diff --git a/tests/run_all_tests.sh b/tests/run_all_tests.sh index 775b0b4caad..dacdd0e9803 100755 --- a/tests/run_all_tests.sh +++ b/tests/run_all_tests.sh @@ -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 ." diff --git a/tests/screenshot/gen_screenshots.js b/tests/screenshot/gen_screenshots.js index 9866a9ad0d6..f58908be019 100644 --- a/tests/screenshot/gen_screenshots.js +++ b/tests/screenshot/gen_screenshots.js @@ -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) { diff --git a/tests/scripts/.selenium_connect.sh.swp b/tests/scripts/.selenium_connect.sh.swp deleted file mode 100644 index ceaa1343a7a..00000000000 Binary files a/tests/scripts/.selenium_connect.sh.swp and /dev/null differ diff --git a/tests/scripts/get_chromedriver.sh b/tests/scripts/get_chromedriver.sh deleted file mode 100755 index 469d99d7280..00000000000 --- a/tests/scripts/get_chromedriver.sh +++ /dev/null @@ -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 diff --git a/tests/scripts/get_geckdriver.sh b/tests/scripts/get_geckdriver.sh deleted file mode 100755 index 60743841bf7..00000000000 --- a/tests/scripts/get_geckdriver.sh +++ /dev/null @@ -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 diff --git a/tests/scripts/get_selenium.sh b/tests/scripts/get_selenium.sh deleted file mode 100755 index e6e830a0d89..00000000000 --- a/tests/scripts/get_selenium.sh +++ /dev/null @@ -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 diff --git a/tests/scripts/selenium-config.js b/tests/scripts/selenium-config.js new file mode 100644 index 00000000000..2bf53ff9655 --- /dev/null +++ b/tests/scripts/selenium-config.js @@ -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 + }, +}; diff --git a/tests/scripts/selenium_connect.sh b/tests/scripts/selenium_connect.sh deleted file mode 100755 index fb04d95ea56..00000000000 --- a/tests/scripts/selenium_connect.sh +++ /dev/null @@ -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 & - diff --git a/tests/scripts/setup_linux_env.sh b/tests/scripts/setup_linux_env.sh index da3d0ce6c90..6e21e87e347 100755 --- a/tests/scripts/setup_linux_env.sh +++ b/tests/scripts/setup_linux_env.sh @@ -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 diff --git a/tests/scripts/setup_osx_env.sh b/tests/scripts/setup_osx_env.sh index 92891f966d7..5a7092269ff 100755 --- a/tests/scripts/setup_osx_env.sh +++ b/tests/scripts/setup_osx_env.sh @@ -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 diff --git a/tests/scripts/test_setup.sh b/tests/scripts/test_setup.sh deleted file mode 100755 index e9ddf561f6a..00000000000 --- a/tests/scripts/test_setup.sh +++ /dev/null @@ -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