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); });