Skip to content

Commit

Permalink
test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jpolitz committed May 8, 2014
1 parent 4cc12fa commit 60ba480
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .env.test.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GOOGLE_CLIENT_ID=<your-id-here>
GOOGLE_CLIENT_SECRET=<your-secret-here>
BASE_URL=http://localhost:5000
PORT=5000
BASE_URL=http://localhost:4000
PORT=4000
SESSION_SECRET=not-so-secret

DATABASE_URL="postgres://pyret:pyret@localhost/pyret_test"
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ teachpack-dir:
.PHONY : teachpacks
teachpacks: teachpack-dir $(TEACHPACK_ARR) $(TEACHPACK_JS) $(TEACHPACK_STATIC)

db:
foreman run migrate

.PHONY : post-install
post-install: compress-pyret teachpacks
post-install: compress-pyret teachpacks db

install-link:
npm link pyret-lang
Expand Down
4 changes: 2 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ web: node src/run.js

test: node node_modules/jasmine-node/lib/jasmine-node/cli.js --matchall test/db

selenium-test-local: TEST_LOC="local" node node_modules/jasmine-node/lib/jasmine-node/cli.js --matchall test/browser/
selenium-test-sauce: TEST_LOC="sauce" node node_modules/jasmine-node/lib/jasmine-node/cli.js --matchall test/browser/
selenium-test-local: TEST_LOC="local" node node_modules/jasmine-node/lib/jasmine-node/cli.js test/browser/
selenium-test-sauce: TEST_LOC="sauce" node node_modules/jasmine-node/lib/jasmine-node/cli.js test/browser/

migrate: node node_modules/db-migrate/bin/db-migrate up

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ permission to run all the tests:
You should make a separate environment for testing, which can use the same
client secret from Google, but should be a separate databse from development.
You also need a few extra entries in the test environment for the database,
which are used to create fresh databases; see `.env.test.example`.
which are used to create fresh databases; see `.env.test.example`. It can be
useful to create a new `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` pointing
to a different port, as well, so you can run tests locally on a different port
from the development server.

To migrate the test database, use:

Expand Down
39 changes: 39 additions & 0 deletions test/browser/save-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
_ = require("jasmine-node");
var tester = require("./selenium-init.js");
var webdriver = require('selenium-webdriver');

var contains = tester.contains;
var waitThenClick = tester.waitThenClick;
var googleLogin = tester.googleLogin;
var googleLogout = tester.googleLogout;

describe("Saving programs", function() {
tester.start(function(maybeServer, baseUrl, driver) {
tester.webbit("should open up the editor and save a new program", function(done) {
var name = "test-program" + String(Math.floor(Math.random() * 10000));
driver.get(baseUrl);
driver.findElement(webdriver.By.id('login')).click();
tester.googleLogin(driver);
driver.get(baseUrl + "/editor");
tester.waitForPyretLoad(driver, 15000);
driver.findElement(webdriver.By.id('program-name')).sendKeys(name);
driver.findElement(webdriver.By.id('saveButton')).click();
driver.wait(function() {
return driver.isElementPresent(tester.contains("saved as " + name));
}, 4000);
driver.get(baseUrl + "/my-programs");
driver.wait(function() {
return driver.isElementPresent(tester.contains(name));
}, 4000);
driver.call(done);
}, 60000);

it("should close the server and the connection to the browser", function(done) {
console.log("closing down server");
if(maybeServer) { maybeServer.close(); }
driver.quit();
done();
});
});
});

3 changes: 3 additions & 0 deletions test/browser/selenium-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var webdriver = require('selenium-webdriver');

function start(withDriver) {
if (process.env["TEST_LOC"] === "local") {
console.log("Starting local server");
server.start({
baseUrl: process.env["BASE_URL"],
port: process.env["PORT"],
Expand All @@ -14,6 +15,7 @@ function start(withDriver) {
redirect: "/oauth2callback"
}
}, function(app, server) {
console.log("Server started, initializing selenium");
var driver = new webdriver.Builder().
withCapabilities({browserName: "chrome"}).
build();
Expand Down Expand Up @@ -91,6 +93,7 @@ function waitForPyretLoad(driver, timeout) {
}, timeout || 3000);
}


module.exports = {
webbit: webbit,
googleLogout: googleLogout,
Expand Down
69 changes: 69 additions & 0 deletions test/browser/signin-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
_ = require("jasmine-node");
var tester = require("./selenium-init.js");
var webdriver = require('selenium-webdriver');

var contains = tester.contains;
var waitThenClick = tester.waitThenClick;
var googleLogin = tester.googleLogin;
var googleLogout = tester.googleLogout;

describe("Sign in", function() {
tester.start(function(maybeServer, baseUrl, driver) {
tester.webbit("Should forget everything it knows", function(done) {
driver.get("https://security.google.com/settings/security/permissions");
googleLogin(driver);
console.log("Waiting to see if Patch permissions are present...");
driver.wait(function() {
return driver.executeScript("return document.readyState === 'complete'");
}, 3000);
driver.isElementPresent(contains("Patch Test")).then(function(present) {
if(present) {
waitThenClick(driver, contains("Patch Test"));
waitThenClick(driver, contains("Revoke access"));
return waitThenClick(driver, webdriver.By.name("ok"));
} else {
// do nothing otherwise
}
});
googleLogout(driver);
driver.call(done);
}, 60000);

tester.webbit("Should sign up from not being logged in", function(done) {
driver.get(baseUrl);
driver.findElement(webdriver.By.id('login')).click();
googleLogin(driver);
console.log("Waiting for permission confirmation button...");
driver.wait(function() {
return driver.findElement(webdriver.By.id("submit_approve_access")).getAttribute("disabled")
.then(function(disabled) {
return !disabled;
});
}, 3000);
driver.findElement(webdriver.By.id("submit_approve_access")).click();
tester.waitForPyretLoad(driver);
driver.call(done);
}, 60000);

tester.webbit("When logging back in, should skip authentication and go straight to my-programs", function(done) {
driver.get(baseUrl);
driver.findElement(webdriver.By.id('login')).click();
tester.waitForPyretLoad(driver);
driver.call(done);
}, 60000);

tester.webbit("If cookies are cleared, should still log in seamlessly and work", function(done) {
driver.manage().deleteAllCookies();
driver.get(baseUrl);
driver.findElement(webdriver.By.id('login')).click();
tester.waitForPyretLoad(driver);
driver.call(done);
}, 60000);

it("Should close the server and the connection to the browser", function(done) {
console.log("closing down server");
if(maybeServer) { maybeServer.close(); }
done();
});
});
});
72 changes: 0 additions & 72 deletions test/browser/signin.js

This file was deleted.

0 comments on commit 60ba480

Please sign in to comment.