Skip to content

Commit

Permalink
Clean up testing
Browse files Browse the repository at this point in the history
* Switch to using firefox in selenium
* Add script `run-tests.sh` that will pre-download assets such as spks
* Fix tests to work in firefox
* Upgrade versions of dependencies
  • Loading branch information
jparyani committed Oct 7, 2014
1 parent 54bfa9c commit 328ae48
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 42 deletions.
10 changes: 6 additions & 4 deletions shell/shared/testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ if (isTesting) {

mockLoginGithub = function () {
Meteor.call('mockCreateGithub', function (err) {
// TODO(soon)
console.log(err);
if (err) {
console.log(err);
}
window.localStorage.setItem('Meteor.loginToken', 'F0S6luPxIJV--y_GAkBKOMuWMYnnqgG3UMv9M-DIs2f');
window.localStorage.setItem('Meteor.loginTokenExpires', 'Mon Nov 10 2099 21:16:02 GMT-0800 (PST)');
window.localStorage.setItem('Meteor.userId', 'Py8fwsaryQNGBuiXb');
Expand All @@ -45,8 +46,9 @@ if (isTesting) {

mockLoginGoogle = function () {
Meteor.call('mockCreateGoogle', function (err) {
// TODO(soon)
console.log(err);
if (err) {
console.log(err);
}
window.localStorage.setItem('Meteor.loginToken', 'P3ffUfVJtptyVX2IPUfNDZY0F3b-GIZ-WQf7w3GdL21');
window.localStorage.setItem('Meteor.loginTokenExpires', 'Tue Nov 18 2099 23:52:55 GMT-0800 (PST)');
window.localStorage.setItem('Meteor.userId', '6WJcRo2gg2Ysuxsok');
Expand Down
Empty file added tests/assets/.gitkeep
Empty file.
12 changes: 8 additions & 4 deletions tests/nightwatch.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@
},

"desiredCapabilities": {
"browserName": "phantomjs",
"phantomjs.binary.path" : "node_modules/phantomjs/bin/phantomjs"
"browserName": "firefox",
"javascriptEnabled" : true,
"acceptSslCerts" : true
}
},

"firefox" : {
"phantomjs" : {
"desiredCapabilities": {
"browserName": "firefox"
"browserName": "phantomjs",
"javascriptEnabled" : true,
"acceptSslCerts" : true,
"phantomjs.binary.path" : "node_modules/phantomjs/bin/phantomjs"
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"devDependencies": {
"chai": "~1.9.1",
"mocha": "~1.20.1",
"nightwatch": "~0.5.11",
"phantomjs": "~1.9.7",
"selenium-standalone": "2.42.2-2.9.0"
"nightwatch": "~0.5.29",
"phantomjs": "~1.9.10",
"selenium-standalone": "2.43.1-3"
},
"repository": {
"type": "git",
"url": "https://github.com/sandstorm-io/sandstorm.git"
},
"scripts": {
"test": "nightwatch"
"test": "./run-tests.sh"
}
}
21 changes: 16 additions & 5 deletions tests/run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,32 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

THIS_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")

cd "$THIS_DIR"/..
make -j4 XZ_FLAGS='-0' .docker

cd "$THIS_DIR"
rm -rf sandstorm_var
mkdir -p sandstorm_var/{log,mongo,pid,sandstorm/apps,sandstorm/grains,sandstorm/downloads}
chmod -R 777 sandstorm_var

cd $THIS_DIR/..
make -j4 XZ_FLAGS='-0' .docker
CONTAINER_ID=$(docker run -v `pwd`/tests/sandstorm_var:/home/sandstorm/sandstorm/var --privileged -d -p 6080:6080 -t sandstorm bash -c 'echo "IS_TESTING=true
CONTAINER_ID=$(docker run -v `pwd`/sandstorm_var:/home/sandstorm/sandstorm/var --privileged -d -p 6080:6080 -t sandstorm bash -c 'echo "IS_TESTING=true
ALLOW_DEMO_ACCOUNTS=true" >> $HOME/sandstorm/sandstorm.conf && $HOME/sandstorm/sandstorm start && sleep infinity')

while ! curl -s localhost:6080 > /dev/null; do sleep .1; done;
echo -n "Waiting for sandstorm to start."
while ! curl -s localhost:6080 > /dev/null; do
echo -n .
sleep .1
done;
echo

cd $THIS_DIR
npm install

set +e

npm test
rc=$?

Expand Down
30 changes: 30 additions & 0 deletions tests/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
#
# Sandstorm - Personal Cloud Sandbox
# Copyright (c) 2014 Sandstorm Development Group, Inc. and contributors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

THIS_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")

cd "$THIS_DIR"

test -e assets/ssjekyll5.spk || curl http://sandstorm.io/apps/ssjekyll5.spk > assets/ssjekyll5.spk
test -e assets/ssjekyll6.spk || curl http://sandstorm.io/apps/ssjekyll6.spk > assets/ssjekyll6.spk
test -e assets/ssjekyll7.spk || curl http://sandstorm.io/apps/ssjekyll7.spk > assets/ssjekyll7.spk

set +e
nightwatch
88 changes: 63 additions & 25 deletions tests/tests/grain.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

var utils = require('../utils');
var path = require('path');
var spkPath = path.resolve(__dirname, '../assets/ssjekyll6.spk');
var assetsPath = path.resolve(__dirname, '../assets');

module.exports = utils.testAllLogins({
"Test local install" : function (browser) {
Expand All @@ -27,51 +27,87 @@ module.exports = utils.testAllLogins({
.ifDemo(function () {
browser
.waitForElementVisible('#upload p', 5000)
.assert.containsText('#upload p', 'demo users are not allowed');
.assert.containsText('#upload p', 'demo users are not allowed')
.init()
.waitForElementVisible('#applist-apps', 5000);
})
.ifNotDemo(function () {
browser
.waitForElementVisible('#uploadButton', 5000)
.assert.containsText('#uploadButton', 'Upload');
// TODO(someday): change ironrouter to allow larger requests, fails with 413 error now
// .waitForElementVisible('#uploadButton', 1000)
// .setValue('#uploadFile', spkPath)
// .click('#uploadButton')
// .waitForElementVisible('#step-confirm', 60000)
// .click('#confirmInstall')
// .assert.containsText('.new-grain-button', 'New Ghost');
.assert.containsText('#uploadButton', 'Upload')
.waitForElementVisible('#uploadButton', 1000)
.setValue('#uploadFile', path.join(assetsPath, 'ssjekyll6.spk'))
.click('#uploadButton')
.waitForElementVisible('#step-confirm', 30000)
.click('#confirmInstall')
.assert.containsText('.new-grain-button', 'New Hacker CMS Site');
});
},

"Test remote install" : function (browser) {
"Test upgrade" : function (browser) {
browser
.url(browser.launch_url + "/install/9bb0068c51f20fea26688db0fc0647be?url=http://sandstorm.io/apps/ssjekyll7.spk")
.waitForElementVisible('#step-confirm', 120000)
.click('#confirmInstall')
.assert.containsText('.new-grain-button', 'New Hacker CMS Site');
.click("#applist-apps > ul > li:nth-child(1)")
.waitForElementVisible('#upload-app-button', 5000)
.click('#upload-app-button')
.ifDemo(function () {
browser
.waitForElementVisible('#upload p', 5000)
.assert.containsText('#upload p', 'demo users are not allowed')
.init()
.waitForElementVisible('#applist-apps', 5000);
})
.ifNotDemo(function () {
browser
.waitForElementVisible('#uploadButton', 5000)
.assert.containsText('#uploadButton', 'Upload')
.waitForElementVisible('#uploadButton', 1000)
.setValue('#uploadFile', path.join(assetsPath, 'ssjekyll7.spk'))
.click('#uploadButton')
.waitForElementVisible('#step-confirm', 30000)
.assert.containsText('#confirmInstall', 'Upgrade')
.click('#confirmInstall')
.assert.containsText('.new-grain-button', 'New Hacker CMS Site');
});
},

"Test upgrade" : function (browser) {
"Test downgrade" : function (browser) {
browser
.url(browser.launch_url + "/install/ca690ad886bf920026f8b876c19539c1?url=http://sandstorm.io/apps/ssjekyll8.spk")
.waitForElementVisible('#step-confirm', 120000)
.assert.containsText('#confirmInstall', 'Upgrade')
.click('#confirmInstall')
.assert.containsText('.new-grain-button', 'New Hacker CMS Site');
.click("#applist-apps > ul > li:nth-child(1)")
.waitForElementVisible('#upload-app-button', 5000)
.click('#upload-app-button')
.ifDemo(function () {
browser
.waitForElementVisible('#upload p', 5000)
.assert.containsText('#upload p', 'demo users are not allowed')
.init()
.waitForElementVisible('#applist-apps', 5000);
})
.ifNotDemo(function () {
browser
.waitForElementVisible('#uploadButton', 5000)
.assert.containsText('#uploadButton', 'Upload')
.waitForElementVisible('#uploadButton', 1000)
.setValue('#uploadFile', path.join(assetsPath, 'ssjekyll5.spk'))
.click('#uploadButton')
.waitForElementVisible('#step-confirm', 30000)
.assert.containsText('#confirmInstall', 'Downgrade')
.click('#confirmInstall')
.assert.containsText('.new-grain-button', 'New Hacker CMS Site');
});
},

"Test downgrade" : function (browser) {
"Test remote install" : function (browser) {
browser
.url(browser.launch_url + "/install/c551ac859564c996bf301627481b7273?url=http://sandstorm.io/apps/ssjekyll5.spk")
.url(browser.launch_url + "/install/ca690ad886bf920026f8b876c19539c1?url=http://sandstorm.io/apps/ssjekyll8.spk")
.waitForElementVisible('#step-confirm', 120000)
.assert.containsText('#confirmInstall', 'Downgrade')
.click('#confirmInstall')
.assert.containsText('.new-grain-button', 'New Hacker CMS Site');
},

"Test new grain" : function (browser) {
browser
.click('.new-grain-button')
.waitForElementVisible('#grainTitle', 5000)
.assert.containsText('#grainTitle', 'Untitled Hacker CMS Site');
},

Expand All @@ -94,17 +130,19 @@ module.exports = utils.testAllLogins({
.click('#restartGrain')
.frame('grain-frame')
.waitForElementPresent('#publish', 10000)
.pause(1000)
.assert.containsText('#publish', 'Publish')
.frame(null);
},

"Test grain debug" : function (browser) {
browser
.click('#openDebugLog')
.pause(50)
.pause(1000)
.windowHandles(function (windows) {
browser.switchWindow(windows.value[1]);
})
.pause(1000)
.assert.containsText('#topbar', 'Debug')
.closeWindow()
.end();
Expand Down

0 comments on commit 328ae48

Please sign in to comment.