Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests on Travis CI #76

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: node_js
node_js:
- "6"
- "6.1"
- "4.4"
- "5.11"
- "0.10"
- "0.12"
before_script:
- npm install -g uglifyjs
script:
- ./tools/build.sh
31 changes: 31 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
dependencies:
post:
- npm install -g uglifyjs
- pip install selenium
- wget https://saucelabs.com/downloads/sc-latest-linux.tar.gz
- tar -xzf sc-latest-linux.tar.gz
- wget https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-linux64.tar.gz
- tar -xvzf geckodriver-v0.11.1-linux64.tar.gz
test:
override:
# First start the tunnel because it takes time to setup.
- cd sc-*-linux && ./bin/sc --user $SAUCE_USERNAME --api-key $SAUCE_ACCESS_KEY --readyfile ~/sauce_is_ready --tunnel-identifier numeric-$CIRCLE_BUILD_NUM:
background: true
# Build and test locally.
- ./tools/build.sh
# Server files.
- python ./tools/serve.py:
background: true
# Wait for server to be ready.
- curl --retry 10 --retry-delay 2 -s http://localhost:8000/ > /dev/null
# Run selenium tests.
- python ./tools/selenium_tests.py Chrome http://localhost:8000/
- PATH=.:$PATH ; python ./tools/selenium_tests.py Firefox http://localhost:8000/
# Wait for tunnel to be ready.
- while [ ! -e ~/sauce_is_ready ]; do sleep 1; done
# TODO: We should upgrade to HTTPS once selenium Python package is released with this pull request: https://github.com/SeleniumHQ/selenium/pull/3179
- SELENIUM_REMOTE_CAPABILITIES="{\"browserName\":\"internet explorer\",\"platform\":\"Windows 10\",\"version\":\"11.103\",\"name\":\"numeric\",\"build\":\"$CIRCLE_BUILD_NUM\",\"tunnelIdentifier\":\"numeric-$CIRCLE_BUILD_NUM\"}" SELENIUM_REMOTE_URL=http://$SAUCE_USERNAME:[email protected]:80/wd/hub python ./tools/selenium_tests.py Remote http://localhost:8000/
post:
# Wait for Sauce Connect to close the tunnel.
- killall --wait sc
- killall --wait python
9 changes: 7 additions & 2 deletions tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ cd ..
runjs=`which d8 || which jsdb || which node`
echo Using $runjs
$runjs ./tools/unit2.js &
echo $! > tools/nodepid.log
nodepid=$!
echo $nodepid > tools/nodepid.log

cd lib
rm -rf numeric-$ver
Expand Down Expand Up @@ -78,7 +79,11 @@ rm -f numeric-$ver.tar.gz
tar cfz numeric-$ver.tar.gz numeric-$ver
rm -rf numeric-$ver
cd ../tools
wait
set +e
wait "$nodepid"
testexit=$?
set -e
rm -f buildpid.log
rm -f nodepid.log
echo "Build complete"
exit $testexit
23 changes: 20 additions & 3 deletions tools/selenium_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import sys
import urllib
import re
import json
import os

# Returns True if any test failed.
def test(name,driver):
p = 0
f = 0
Expand All @@ -31,9 +34,11 @@ def test(name,driver):
print k,"FAIL:",tests[k][0],'==>',foo,"reason:",str(ex)
f=f+1
print name,'testing complete. PASS:',p,'FAIL:',f,'Total:',t
return bool(f)
except:
print "FAIL: "+name+" selenium tests. Details:"
traceback.print_exc()
return True

url = ""
if len(sys.argv) > 1:
Expand All @@ -50,7 +55,8 @@ def test(name,driver):
print 'Fetching',u0
njs = urllib.urlopen(u0).read()
y = re.findall(r'<pre>[\s\S]*?(?=<\/pre>)',njs)
tests = [];
tests = []
failure = True

print "In-browser unit tests."
for x in y:
Expand All @@ -60,17 +66,28 @@ def test(name,driver):
tests.append((re.sub(r'\s',' ',foo[0:bar]),re.sub(r'\s','',foo[bar+5:])))
driver=0
try:
driver = eval('webdriver.'+client+'()')
if client == 'Remote':
driver = webdriver.Remote(
# Example: http://YOUR_SAUCE_USERNAME:[email protected]:80/wd/hub
command_executor=os.environ['SELENIUM_REMOTE_URL'],
# Example: {"browserName": "chrome", "platform": "Linux", "version": "48.0"}
desired_capabilities=json.loads(os.environ['SELENIUM_REMOTE_CAPABILITIES']),
)
else:
driver = eval('webdriver.'+client+'()')
print "Using",client
driver.implicitly_wait(2)
driver.get(url+'workshop.php')
try:
WebDriverWait(driver, 30).until(lambda driver : driver.find_element_by_id("text_1"))
test(client,driver)
failure=test(client,driver)
except Exception as ex:
print "FAIL: text_1 not found. ",ex
except Exception as ex:
print "Could not use browser",client
print ex

if(driver):
driver.quit()

sys.exit(failure)
17 changes: 17 additions & 0 deletions tools/serve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/python

import SimpleHTTPServer
import SocketServer

HOST = 'localhost'
PORT = 8000

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
Handler.extensions_map.update({
'.php': 'text/html',
});

httpd = SocketServer.TCPServer((HOST, PORT), Handler)

print "Serving at", HOST, PORT
httpd.serve_forever()
1 change: 1 addition & 0 deletions tools/unit2.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ for(_j=0;_j<_bar.length;_j++) {
runner(_bar[_j].replace(/<pre>/g,'').split('\nIN> '));
}
console.log('unit2: '+_k1+' tests, '+_unit_pass+' pass and '+_unit_fail+' fail.');
if(typeof process !== "undefined") { process.exit(!!_unit_fail); }
16 changes: 9 additions & 7 deletions tools/workshop_in.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ function con() {

WORKSHOPHTML

<script>
workshop._restore = ((typeof localStorage.savedata === "string")?
(JSON.parse(localStorage.savedata)):
{inputs: [], outputs: [],
scripts: ["lib/numeric-VERSIONSTRING.js"] });
</script>

<script>
<?php
$incs = NULL;
Expand All @@ -42,16 +49,11 @@ function con() {
echo <<<EOT
workshop._restore = $restore;
EOT;
} else {
echo <<<EOT
workshop._restore = ((typeof localStorage.savedata === "string")?
(JSON.parse(localStorage.savedata)):
{inputs: [], outputs: [],
scripts: ["lib/numeric-VERSIONSTRING.js"] });
EOT;
}
?>
</script>

<script>
workshop.version = "VERSIONSTRING";
workshop.updateVersion = "lib/numeric-VERSIONSTRING.js";
workshop.preload(workshop._restore);
Expand Down
16 changes: 9 additions & 7 deletions workshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,13 @@ function submit() {
<br><br><br>


<script>
workshop._restore = ((typeof localStorage.savedata === "string")?
(JSON.parse(localStorage.savedata)):
{inputs: [], outputs: [],
scripts: ["lib/numeric-1.2.6.js"] });
</script>

<script>
<?php
$incs = NULL;
Expand All @@ -479,16 +486,11 @@ function submit() {
echo <<<EOT
workshop._restore = $restore;
EOT;
} else {
echo <<<EOT
workshop._restore = ((typeof localStorage.savedata === "string")?
(JSON.parse(localStorage.savedata)):
{inputs: [], outputs: [],
scripts: ["lib/numeric-1.2.6.js"] });
EOT;
}
?>
</script>

<script>
workshop.version = "1.2.6";
workshop.updateVersion = "lib/numeric-1.2.6.js";
workshop.preload(workshop._restore);
Expand Down