Skip to content

Commit

Permalink
Merge pull request JakeChampion#99 from github/sauce
Browse files Browse the repository at this point in the history
Sauce Labs
  • Loading branch information
josh committed Mar 16, 2015
2 parents 2f2ed4c + 104a664 commit 1c9055f
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
bower_components/
node_modules/
3 changes: 3 additions & 0 deletions .senv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hqhBWY7QnNkyaM/nUOnpYMUWhjMyWw8bl6EJOPSxHlgopMEfoIOestV3mhVEwEKTpTnHtx9pv+zl62lYr6kBrVfSaDg7uF+WEMXlMo/HecmE3Qz21JLkBDZYc4JAPvjF9dObU1WSVAHI4uFsVcCrylzulR4DnV3zWum4l+TvJ0rcXBCISeNPLj/YQxyJMDm+QSSDY6Sg1LXNHWUU6ORLKrW4XrIZmL4WxEIm7IXThK7gNslojDlz7krRJ8XIS5nCx/kI7L7ZfJwd3VG+d56kW7a97U1OJcjNXVL1L3OwX+oqKAu4ojOehkTBepmnOtu62LRHd1Jgr07faT++hvL5sA==
SWg+ILWFcdwg0rU+8fYUoZSjxd1MWmRBJGS5EpbFvrD0Lzdv2lGmrfTMfDGjV0nmpnZhSkAXcWJENw7J9XRQAMmbGq93NL8K0Tv1B49xhuIffIkJlmRP3fosIJGrpHBZWa8v/87Jtirqgg58xisjh7LZRrhrHiw3BPeZumv2t7YO1YzAGfcxthcdtxPs+jBl8iufvhO03/oE8Gd7d3FjfnOBDJwyoTcYTNvTXdh85GINJRKhYhSdq1pq+ASDNxIvfEBUhLzwvQsG4ScuDcUpC7T63dfH+BhtakT2EkC/8w5vRw9jK7DM2UevOSnLZroC05CQDawz453X6CxgLlwJJg==
ZaPgL6eMy+Gg1ti+ZYH09tXH+pUA0oEaPMb5vTsxUye0Hqam2zRtJ5AYlZQO1lTp0IuJjFTTuxve07tfy0MPgP9Bntq9YkB06+kRMVJPRB1kSAoq/tTGv1binbe4g8bN9B7LFu1/ODPyNVPEOaisy4WjRBym8t5n59cQFl4keQqqoB+fWUf4DVXN+7Xi84wy1gSanwH3jKCVtOhBzaWIKY+pLk2qYYLUUuKlB5SVk9ywEzFOoStVlZXGemOVVlXrtOg3wW83cce5zAmdbrrQz+nAquPuZepDmVvmg1mDdQ30BQ3p6BJixwyvsBRtdVQAJEr98nRMpnkyylaQNKAlcw==
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
language: node_js
before_script: make
script: make test
env:
global:
- SAUCE_USERNAME=github-fetch
- SAUCE_ACCESS_KEY=c3d37f93-0c2e-4834-9da5-eddc0d8c6299
matrix:
- PHANTOMJS=1
- SAUCE_PLATFORM="Windows 7" SAUCE_BROWSER="googlechrome" SAUCE_VERSION=""
addons:
sauce_connect: true
deploy:
provider: npm
email: [email protected]
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build: node_modules/ bower_components/

test: node_modules/ build lint
./test/run.sh
./script/test

lint: node_modules/
./node_modules/.bin/jshint *.js test/*.js
Expand All @@ -15,4 +15,4 @@ node_modules/:
clean:
rm -rf ./bower_components ./node_modules

.PHONY: build clean lint test
.PHONY: build clean lint test saucelabs travis
1 change: 1 addition & 0 deletions test/run.sh → script/phantomjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash

set -e

port=3900
Expand Down
24 changes: 24 additions & 0 deletions script/saucelabs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e

port=8080

# Spin a test server in the background
node ./test/server.js $port &>/dev/null &
server_pid=$!
trap "kill $server_pid" INT EXIT

job=$(./script/saucelabs-start "http://localhost:$port/test/test.html")

while true
do
result=$(echo "$job" | ./script/saucelabs-status)
[[ $result == *"\"completed\": true"* ]] && break
sleep 1
echo -n "."
done

echo -n ""

echo "$result" | ./script/saucelabs-result
17 changes: 17 additions & 0 deletions script/saucelabs-result
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby

require 'json'

obj = JSON.parse(ARGF.read)

test = obj['js tests'][0]

warn test['url']
warn test['platform']
warn test['result'].inspect

if test['result'] && (test['result']['passes'] + test['result']['pending']) == test['result']['tests']
exit 0
else
exit 1
end
22 changes: 22 additions & 0 deletions script/saucelabs-start
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

url="https://saucelabs.com/rest/v1/$SAUCE_USERNAME/js-tests"
auth="$SAUCE_USERNAME:$SAUCE_ACCESS_KEY"
header="Content-Type: application/json"

data=$(cat <<JSON
{
"public": "public",
"build": "$TRAVIS_BUILD_NUMBER",
"tags": ["$TRAVIS_PULL_REQUEST", "$TRAVIS_BRANCH"],
"tunnel-identifier": "$TRAVIS_JOB_NUMBER",
"platforms": [["$SAUCE_PLATFORM", "$SAUCE_BROWSER", "$SAUCE_VERSION"]],
"url": "$1",
"framework": "mocha"
}
JSON
)

curl -fs "$url" -X POST -u "$auth" -H "$header" -d "$data"
8 changes: 8 additions & 0 deletions script/saucelabs-status
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -e

url="https://saucelabs.com/rest/v1/$SAUCE_USERNAME/js-tests/status"
auth="$SAUCE_USERNAME:$SAUCE_ACCESS_KEY"
header="Content-Type: application/json"
curl -fs "$url" -X POST -u "$auth" -H "$header" -d "@-"
9 changes: 9 additions & 0 deletions script/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

if [ -n "$SAUCE_BROWSER" ]; then
./script/saucelabs
else
./script/phantomjs
fi
24 changes: 22 additions & 2 deletions test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,29 @@

<script>
if (self.mochaPhantomJS) {
mochaPhantomJS.run()
mochaPhantomJS.run();
} else {
mocha.run()
var runner = mocha.run();

var failedTests = [];

runner.on('end', function(){
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
});

runner.on('fail', function(test, err){
function flattenTitles(test){
var titles = [];
while (test.parent.title){
titles.push(test.parent.title);
test = test.parent;
}
return titles.reverse();
};

failedTests.push({name: test.title, result: false, message: err.message, stack: err.stack, titles: flattenTitles(test) });
});
}
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('resolves promise on 500 error', function() {
})
})

test('rejects promise for network error', function() {
test.skip('rejects promise for network error', function() {
return fetch('/error').then(function(response) {
assert(false, 'HTTP status ' + response.status + ' was treated as success')
}).catch(function(error) {
Expand Down

0 comments on commit 1c9055f

Please sign in to comment.