diff --git a/.travis.yml b/.travis.yml index da05cd2d40..2be23f4d9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,9 @@ language: node_js node_js: - stable -# This is disabled until we can stablize the nightwatch testing process -#before_script: -# - npm run serve & script: - npm run lint && npm run test && npm run build -# && nightwatch --env remote -# - pkill node -#addons: -# sauce_connect: -# username: "chriseth" -# access_key: "b781828a-9e9c-43d8-89d4-2fbb879595ca" + - ./ci/browser_tests.sh deploy: provider: script script: ci/deploy_from_travis.sh diff --git a/ci/browser_tests.sh b/ci/browser_tests.sh new file mode 100755 index 0000000000..e0ba7a512a --- /dev/null +++ b/ci/browser_tests.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + + +SAUCECONNECT_URL="https://saucelabs.com/downloads/sc-4.3.16-linux.tar.gz" +SAUCECONNECT_USERNAME="chriseth" +SAUCECONNECT_ACCESSKEY="b781828a-9e9c-43d8-89d4-2fbb879595ca" +SAUCECONNECT_JOBIDENTIFIER="browsersolidity_tests_${TRAVIS_JOB_NUMBER}" +SAUCECONNECT_READYFILE="sc.ready" +TEST_EXITCODE=0 + +npm run build +npm run serve & + +wget $SAUCECONNECT_URL +tar -zxvf sc-4.3.16-linux.tar.gz +./sc-4.3.16-linux/bin/sc -u $SAUCECONNECT_USERNAME -k $SAUCECONNECT_ACCESSKEY -i $SAUCECONNECT_JOBIDENTIFIER --readyfile $SAUCECONNECT_READYFILE & +while [ ! -f $SAUCECONNECT_READYFILE ]; do + sleep .5 +done + +npm run browser-test-remote-firefox || TEST_EXITCODE=1 +npm run browser-test-remote-chrome || TEST_EXITCODE=1 +npm run browser-test-remote-safari || TEST_EXITCODE=1 +npm run browser-test-remote-ie || TEST_EXITCODE=1 + +node ci/sauceDisconnect.js $SAUCECONNECT_USERNAME $SAUCECONNECT_ACCESSKEY $SAUCECONNECT_JOBIDENTIFIER + +echo $TEST_EXITCODE +if [ $TEST_EXITCODE -eq 1 ] +then + exit 1 +fi diff --git a/ci/sauceDisconnect.js b/ci/sauceDisconnect.js new file mode 100644 index 0000000000..b29328db5c --- /dev/null +++ b/ci/sauceDisconnect.js @@ -0,0 +1,72 @@ +const https = require('https') + +var userName = process.argv[2] +var accessKey = process.argv[3] +var tunnelName = process.argv[4] + +function removeTunnel () { + const requestPath = `/rest/v1/${userName}/tunnels` + console.log(requestPath) + callSauce(requestPath, 'GET', function (error, result) { + if (error) { + console.log(error) + } else { + var data = JSON.parse(result) + for (var k in data) { + retrieveTunnel(data[k], function (error, result) { + if (error) { + console.log(error) + } else if (result.identtifier === tunnelName) { + deleteTunnel(result.id, function () { + console.log('tunnel deleted ' + data[k] + ' ' + tunnelName) + }) + } + }) + } + } + }) +} + +function retrieveTunnel (tunnelid, callback) { + const requestPath = `/rest/v1/${userName}/tunnels/${tunnelid}` + callSauce(requestPath, 'GET', function (error, result) { + if (error) { + callback(error) + } else { + callback(null, {'identtifier': JSON.parse(result).tunnel_identifier, 'id': tunnelid}) + } + }) +} + +function deleteTunnel (tunnelid, callback) { + const requestPath = `/rest/v1/${userName}/tunnels/${tunnelid}` + callSauce(requestPath, 'DELETE', callback) +} + +function callSauce (requestPath, type, callback) { + function responseCallback (res) { + res.setEncoding('utf8') + console.log('Response: ', res.statusCode, JSON.stringify(res.headers)) + res.on('data', function onData (chunk) { + console.log('BODY: ' + chunk) + callback(null, chunk) + }) + res.on('end', function onEnd () {}) + } + + var req = https.request({ + hostname: 'saucelabs.com', + path: requestPath, + method: type, + auth: userName + ':' + accessKey + }, responseCallback) + + req.on('error', function onError (e) { + console.log('problem with request: ' + e.message) + callback(e.message) + }) + req.write('') + req.end() +} + +removeTunnel() diff --git a/nightwatch.js b/nightwatch.js new file mode 100644 index 0000000000..0d89cfa0b8 --- /dev/null +++ b/nightwatch.js @@ -0,0 +1,79 @@ +'use strict' +var TRAVIS_JOB_NUMBER = process.env.TRAVIS_JOB_NUMBER + +module.exports = { + 'src_folders': ['test-browser'], + 'output_folder': 'reports', + 'custom_commands_path': '', + 'custom_assertions_path': '', + 'page_objects_path': '', + 'globals_path': '', + + 'test_settings': { + 'default': { + 'launch_url': 'http://ondemand.saucelabs.com:80', + 'selenium_host': 'ondemand.saucelabs.com', + 'selenium_port': 80, + 'silent': true, + 'username': 'chriseth', + 'access_key': 'b781828a-9e9c-43d8-89d4-2fbb879595ca', + 'use_ssl': false, + 'globals': { + 'waitForConditionTimeout': 10000, + 'asyncHookTimeout': 100000 + }, + 'screenshots': { + 'enabled': false, + 'path': '' + }, + 'desiredCapabilities': { + 'browserName': 'firefox', + 'javascriptEnabled': true, + 'acceptSslCerts': true, + 'build': 'build-' + TRAVIS_JOB_NUMBER, + 'tunnel-identifier': 'browsersolidity_tests_' + TRAVIS_JOB_NUMBER + } + }, + + 'chrome': { + 'desiredCapabilities': { + 'browserName': 'chrome', + 'javascriptEnabled': true, + 'acceptSslCerts': true, + 'build': 'build-' + TRAVIS_JOB_NUMBER, + 'tunnel-identifier': 'browsersolidity_tests_' + TRAVIS_JOB_NUMBER + } + }, + + 'safari': { + 'desiredCapabilities': { + 'browserName': 'safari', + 'javascriptEnabled': true, + 'acceptSslCerts': true, + 'build': 'build-' + TRAVIS_JOB_NUMBER, + 'tunnel-identifier': 'browsersolidity_tests_' + TRAVIS_JOB_NUMBER + } + }, + + 'ie': { + 'desiredCapabilities': { + 'browserName': 'internet explorer', + 'javascriptEnabled': true, + 'acceptSslCerts': true, + 'build': 'build-' + TRAVIS_JOB_NUMBER, + 'tunnel-identifier': 'browsersolidity_tests_' + TRAVIS_JOB_NUMBER + } + }, + + 'local': { + 'launch_url': 'http://localhost:8080', + 'selenium_port': 4444, + 'selenium_host': 'localhost', + 'desiredCapabilities': { + 'browserName': 'firefox', + 'javascriptEnabled': true, + 'acceptSslCerts': true + } + } + } +} diff --git a/nightwatch.json b/nightwatch.json deleted file mode 100644 index 646626c178..0000000000 --- a/nightwatch.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "src_folders" : ["test-browser"], - "output_folder" : "reports", - "custom_commands_path" : "", - "custom_assertions_path" : "", - "page_objects_path" : "", - "globals_path" : "", - - "test_settings" : { - "default" : { - "launch_url": "http://ondemand.saucelabs.com:80", - "selenium_port": 80, - "selenium_host": "ondemand.saucelabs.com", - "silent": true, - "username": "chriseth", - "access_key": "b781828a-9e9c-43d8-89d4-2fbb879595ca", - "screenshots" : { - "enabled" : false - }, - "globals": { - "waitForConditionTimeout": 60000 - } - }, - "remote" : { - "desiredCapabilities": { - "browserName": "firefox", - "javascriptEnabled": true, - "acceptSslCerts": true - } - }, - "local" : { - "launch_url": "http://localhost:8080", - "selenium_port": 4444, - "selenium_host": "localhost", - "desiredCapabilities": { - "browserName": "firefox", - "javascriptEnabled": true, - "acceptSslCerts": true - } - } - } -} diff --git a/package.json b/package.json index ae8a5d99ac..9a8dc09a22 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,11 @@ "description": "Minimalistic browser-based Solidity IDE", "scripts": { "test": "node test/index.js", - "browser-test": "nightwatch --env local", - "browser-test-sc": "nightwatch --env remote", + "browser-test": "nightwatch --config nightwatch.js --env local", + "browser-test-remote-firefox": "nightwatch --config nightwatch.js --env default", + "browser-test-remote-ie": "nightwatch --config nightwatch.js --env ie", + "browser-test-remote-chrome": "nightwatch --config nightwatch.js --env chrome", + "browser-test-remote-safari": "nightwatch --config nightwatch.js --env safari", "build": "mkdir -p build; browserify src/index.js -o build/app.js", "lint": "semistandard", "serve": "http-server ." @@ -48,7 +51,9 @@ "ignore": [ "assets/js/", "build/", - "src/mode-solidity.js" + "src/mode-solidity.js", + "nightwatch.js", + "ci/sauceDisconnect.js" ] } }