From 362378ac42c06e1fea9f3331d70b15e80cd7944b Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 8 Jul 2016 14:32:56 +0200 Subject: [PATCH 1/2] sauce tests --- .travis.yml | 10 +----- ci/browser_tests.sh | 43 +++++++++++++++++++++++ ci/sauceDisconnect.js | 72 +++++++++++++++++++++++++++++++++++++++ nightwatch.js | 79 +++++++++++++++++++++++++++++++++++++++++++ nightwatch.json | 42 ----------------------- package.json | 11 ++++-- 6 files changed, 203 insertions(+), 54 deletions(-) create mode 100644 ci/browser_tests.sh create mode 100644 ci/sauceDisconnect.js create mode 100644 nightwatch.js delete mode 100644 nightwatch.json diff --git a/.travis.yml b/.travis.yml index b5beabf939..0a04c37173 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" + - bash 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 100644 index 0000000000..05571cac6a --- /dev/null +++ b/ci/browser_tests.sh @@ -0,0 +1,43 @@ +#!/bin/bash + + +SAUCECONNECT_URL="http://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 + +function updateTestExitCode() { + if [ $? -eq 1 ] + then + TEST_EXITCODE=1 + fi +} + +npm run browser-test-remote-firefox +updateTestExitCode +npm run browser-test-remote-chrome +updateTestExitCode +npm run browser-test-remote-safari +updateTestExitCode +npm run browser-test-remote-ie +updateTestExitCode + +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" ] } } From 4700d8660bc2f338bfac9c7e8861d00e10b08254 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 11 Jul 2016 10:47:42 +0200 Subject: [PATCH 2/2] quick changes --- .travis.yml | 2 +- ci/browser_tests.sh | 23 ++++++----------------- 2 files changed, 7 insertions(+), 18 deletions(-) mode change 100644 => 100755 ci/browser_tests.sh diff --git a/.travis.yml b/.travis.yml index 0a04c37173..4cec3a90f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ node_js: - stable script: - npm run lint && npm run test && npm run build - - bash ci/browser_tests.sh + - ./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 old mode 100644 new mode 100755 index 05571cac6a..e0ba7a512a --- a/ci/browser_tests.sh +++ b/ci/browser_tests.sh @@ -1,7 +1,7 @@ -#!/bin/bash +#!/usr/bin/env bash -SAUCECONNECT_URL="http://saucelabs.com/downloads/sc-4.3.16-linux.tar.gz" +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}" @@ -18,21 +18,10 @@ while [ ! -f $SAUCECONNECT_READYFILE ]; do sleep .5 done -function updateTestExitCode() { - if [ $? -eq 1 ] - then - TEST_EXITCODE=1 - fi -} - -npm run browser-test-remote-firefox -updateTestExitCode -npm run browser-test-remote-chrome -updateTestExitCode -npm run browser-test-remote-safari -updateTestExitCode -npm run browser-test-remote-ie -updateTestExitCode +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