From f7a206abcb7d02cef3f5065d8612e0ef1a79d418 Mon Sep 17 00:00:00 2001 From: shirletan Date: Tue, 11 Apr 2017 11:18:15 -0700 Subject: [PATCH] Enable google/blockly with continuous build on travis ci (#1023) * create .travis for ci job * initial checkin for blocky-web travis ci job * rename file to .travis.yaml for typo * remove after_script * added cache * rename .travis.yaml to .travis.yml * Update .travis.yml * include build script * fix yaml file format issue * debug install part * debug build issue * Update .travis.yml * remove cache for now * Update .travis.yml * Update .travis.yml * Update .travis.yml * more debug info * Update .travis.yml * Update .travis.yml * fix typo * installing chrome browser * remove chrome setting config * run build.py as part of npm install * Update .travis.yml * update karma dependency * use karma as test runner * fix typo * remove karma test for now * Update .travis.yml * Update package.json * add npm test target * add browserstack-runner depdendency * update browser support * fix typo for test target * fix chrome typo * added closure dependency * add google-closure-library * include blockly_uncompressed.js and core.js dependency * uncomment out core/*.js files * add kama job as part of install * remove browserstack add on for now * fix karma config typo * add karma-closure * add os support * remove typo config * include more closure files * change os back to linux * use closure-library from node_modules * change log level back to INFO * change npm test target to use open browser command instead of karma * change travis test target to use open command instead of karma * list current directory * find what's in current dir * typo command * Update .travis.yml * typo again * open right index.html * use right path for index.html * xdg-open to open default browser on travis * exit browser after 5s wait * change timeout to 1 min * exit after opening up browser * use browser only * use karma * remove un-needed dependency * clean up script section * fix typo * update build status on readme * initial commit for selenium integration tests * update selenium jar path * fix test_runner.js typo * add more debug info * check java version * add && instead of 9288 * fix java path * add logic to check if selenium is running or not * add some deugging info * initial commit to get chromedriver * add chromedriver flag * add get_chromedriver.sh to package.json and .travel * change browser to chrome for now * fix path issue * update chromdriver path * fix path issue again * more debugging * add debug msg * fix typo * minor fix for getting chromedriver * install latest chrome browser * clean up pakcage.json * use npm target for test run * remove removing trailing comma * fix another trailing comma * updated travis test target * clean up scripts * not sure nmp run preinstall * redirect selenium log to tmp file * revert writing console log to file * update test summary * more clean up * minor clean up before pull request * resolved closure-library conflict 1. add closure-library to dependencies instead of devDependencies. 2. add lint back in scripts block * fix typo (adding comma) in script section --- .travis.yml | 32 ++++++++++++++++++++++++++++++++ README.md | 3 ++- package.json | 26 ++++++++++++++++++++------ scripts/get_chromedriver.sh | 12 ++++++++++++ scripts/get_geckdriver.sh | 7 +++++++ scripts/get_selenium.sh | 14 ++++++++++++++ scripts/selenium_connect.sh | 10 ++++++++++ tests/jsunit/test_runner.js | 35 +++++++++++++++++++++++++++++++++++ 8 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 .travis.yml create mode 100755 scripts/get_chromedriver.sh create mode 100755 scripts/get_geckdriver.sh create mode 100755 scripts/get_selenium.sh create mode 100755 scripts/selenium_connect.sh create mode 100644 tests/jsunit/test_runner.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..35b3b125a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,32 @@ +language: node_js +node_js: +- "4" +- "stable" +sudo: required +dist: trusty +addons: + apt: + sources: + - google-chrome + packages: + - google-chrome-stable + +before_install: +- npm install google-closure-library +# Symlink closure library +- ln -s $(npm root)/google-closure-library ../closure-library + +before_script: + - export CHROME_BIN=/usr/bin/google-chrome + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start +script: + - set -x + - scripts/get_geckdriver.sh + - scripts/get_selenium.sh + - scripts/get_chromedriver.sh + - scripts/selenium_connect.sh & + - node tests/jsunit/test_runner.js + +os: + - linux diff --git a/README.md b/README.md index 474dbf8ac..71b4e3205 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# Blockly +# Blockly [![Build Status]( https://travis-ci.org/google/blockly.svg?branch=master)](https://travis-ci.org/google/blockly) + Google's Blockly is a web-based, visual programming editor. Users can drag blocks together to build programs. All code is free and open source. diff --git a/package.json b/package.json index 530279a2b..46bc66e26 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,9 @@ "name": "blockly", "version": "1.0.0", "description": "Blockly is a library for building visual programming editors.", - "keywords": ["blockly"], - "scripts": { - "lint": "jshint ." - }, + "keywords": [ + "blockly" + ], "repository": { "type": "git", "url": "https://github.com/google/blockly.git" @@ -17,6 +16,11 @@ "author": { "name": "Neil Fraser" }, + "scripts": { + "lint": "jshint .", + "preinstall": "scripts/get_geckdriver.sh && scripts/get_selenium.sh && scripts/get_chromedriver.sh && scripts/selenium_connect.sh &", + "test": "node tests/jsunit/test_runner.js" + }, "license": "Apache-2.0", "private": true, "devDependencies": { @@ -24,12 +28,22 @@ }, "jshintConfig": { "globalstrict": true, - "predef": ["Blockly", "goog", "window", "document", "soy", "XMLHttpRequest"], + "predef": [ + "Blockly", + "goog", + "window", + "document", + "soy", + "XMLHttpRequest" + ], "sub": true, "undef": true, "unused": true }, "dependencies": { - "closure-library": "^1.43629075.2" + "install": "^0.8.8", + "npm": "^4.4.4", + "closure-library": "^1.43629075.2", + "webdriverio": "^4.6.2" } } diff --git a/scripts/get_chromedriver.sh b/scripts/get_chromedriver.sh new file mode 100755 index 000000000..ab24d9bba --- /dev/null +++ b/scripts/get_chromedriver.sh @@ -0,0 +1,12 @@ +#!/bin/bash +os_name=`uname` +chromedriver_dir="chromedriver" +if [ ! -d $chromedriver_dir ]; then + mkdir $chromedriver_dir +fi + +if [[ $os_name == 'Linux' ]]; then + cd chromedriver && curl -L https://chromedriver.storage.googleapis.com/2.29/chromedriver_linux64.zip > tmp.zip && unzip -o tmp.zip && rm tmp.zip +elif [[ $os_name == 'Darwin' ]]; then + cd chromedriver && curl -L https://chromedriver.storage.googleapis.com/2.29/chromedriver_mac64.zip | tar xz +fi diff --git a/scripts/get_geckdriver.sh b/scripts/get_geckdriver.sh new file mode 100755 index 000000000..4cc3b8f68 --- /dev/null +++ b/scripts/get_geckdriver.sh @@ -0,0 +1,7 @@ +#!/bin/bash +os_name=`uname` +if [[ $os_name == 'Linux' ]]; then + cd ../ && curl -L https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-linux64.tar.gz | tar xz +elif [[ $os_name == 'Darwin' ]]; then + cd ../ && curl -L https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-macos.tar.gz | tar xz +fi diff --git a/scripts/get_selenium.sh b/scripts/get_selenium.sh new file mode 100755 index 000000000..34a416b60 --- /dev/null +++ b/scripts/get_selenium.sh @@ -0,0 +1,14 @@ +#!/bin/bash +DIR="../webdriverio-test" +FILE=selenium-server-standalone-3.0.1.jar + +if [ ! -d $DIR ]; then + mkdir $DIR +fi + +if [ ! -f $DIR/$FILE ]; then + cd $DIR && curl -O http://selenium-release.storage.googleapis.com/3.0/selenium-server-standalone-3.0.1.jar +fi + + + diff --git a/scripts/selenium_connect.sh b/scripts/selenium_connect.sh new file mode 100755 index 000000000..3fae90576 --- /dev/null +++ b/scripts/selenium_connect.sh @@ -0,0 +1,10 @@ +#!/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.0.1.jar & + diff --git a/tests/jsunit/test_runner.js b/tests/jsunit/test_runner.js new file mode 100644 index 000000000..d3a44944a --- /dev/null +++ b/tests/jsunit/test_runner.js @@ -0,0 +1,35 @@ +var webdriverio = require('webdriverio'); +var options = { + desiredCapabilities: { + browserName: 'chrome' + } +}; + +var path = process.cwd(); +//TODO: change pause to waitunitl +var browser = webdriverio + .remote(options) + .init() + .url("file://" + path + "/tests/jsunit/index.html").pause(3000); + + +browser +.getHTML('#closureTestRunnerLog') +.then(function(result) { + // call js to parse html + var regex = /[\d]+\spassed,\s([\d]+)\sfailed./i; + var numOfFailure = regex.exec(result)[1]; + var regex2 = /Unit Tests for Blockly .*]/; + var testStatus = regex2.exec(result)[0]; + console.log("============Blockly Unit Test Summary================="); + console.log(testStatus); + var regex3 = /\d+ passed,\s\d+ failed/; + var detail = regex3.exec(result)[0]; + console.log(detail); + console.log("============Blockly Unit Test Summary================="); + if ( parseInt(numOfFailure) !== 0) { + console.log(result); + process.exit(1); + } +}) +.catch(function(err) { console.log(err); process.exit(1); });