Skip to content

Commit 60ba480

Browse files
committedMay 8, 2014
test updates
1 parent 4cc12fa commit 60ba480

File tree

8 files changed

+123
-78
lines changed

8 files changed

+123
-78
lines changed
 

‎.env.test.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GOOGLE_CLIENT_ID=<your-id-here>
22
GOOGLE_CLIENT_SECRET=<your-secret-here>
3-
BASE_URL=http://localhost:5000
4-
PORT=5000
3+
BASE_URL=http://localhost:4000
4+
PORT=4000
55
SESSION_SECRET=not-so-secret
66

77
DATABASE_URL="postgres://pyret:pyret@localhost/pyret_test"

‎Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ teachpack-dir:
2424
.PHONY : teachpacks
2525
teachpacks: teachpack-dir $(TEACHPACK_ARR) $(TEACHPACK_JS) $(TEACHPACK_STATIC)
2626

27+
db:
28+
foreman run migrate
29+
2730
.PHONY : post-install
28-
post-install: compress-pyret teachpacks
31+
post-install: compress-pyret teachpacks db
2932

3033
install-link:
3134
npm link pyret-lang

‎Procfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ web: node src/run.js
22

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

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

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

‎README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ permission to run all the tests:
5555
You should make a separate environment for testing, which can use the same
5656
client secret from Google, but should be a separate databse from development.
5757
You also need a few extra entries in the test environment for the database,
58-
which are used to create fresh databases; see `.env.test.example`.
58+
which are used to create fresh databases; see `.env.test.example`. It can be
59+
useful to create a new `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` pointing
60+
to a different port, as well, so you can run tests locally on a different port
61+
from the development server.
5962

6063
To migrate the test database, use:
6164

‎test/browser/save-spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
_ = require("jasmine-node");
2+
var tester = require("./selenium-init.js");
3+
var webdriver = require('selenium-webdriver');
4+
5+
var contains = tester.contains;
6+
var waitThenClick = tester.waitThenClick;
7+
var googleLogin = tester.googleLogin;
8+
var googleLogout = tester.googleLogout;
9+
10+
describe("Saving programs", function() {
11+
tester.start(function(maybeServer, baseUrl, driver) {
12+
tester.webbit("should open up the editor and save a new program", function(done) {
13+
var name = "test-program" + String(Math.floor(Math.random() * 10000));
14+
driver.get(baseUrl);
15+
driver.findElement(webdriver.By.id('login')).click();
16+
tester.googleLogin(driver);
17+
driver.get(baseUrl + "/editor");
18+
tester.waitForPyretLoad(driver, 15000);
19+
driver.findElement(webdriver.By.id('program-name')).sendKeys(name);
20+
driver.findElement(webdriver.By.id('saveButton')).click();
21+
driver.wait(function() {
22+
return driver.isElementPresent(tester.contains("saved as " + name));
23+
}, 4000);
24+
driver.get(baseUrl + "/my-programs");
25+
driver.wait(function() {
26+
return driver.isElementPresent(tester.contains(name));
27+
}, 4000);
28+
driver.call(done);
29+
}, 60000);
30+
31+
it("should close the server and the connection to the browser", function(done) {
32+
console.log("closing down server");
33+
if(maybeServer) { maybeServer.close(); }
34+
driver.quit();
35+
done();
36+
});
37+
});
38+
});
39+

‎test/browser/selenium-init.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var webdriver = require('selenium-webdriver');
44

55
function start(withDriver) {
66
if (process.env["TEST_LOC"] === "local") {
7+
console.log("Starting local server");
78
server.start({
89
baseUrl: process.env["BASE_URL"],
910
port: process.env["PORT"],
@@ -14,6 +15,7 @@ function start(withDriver) {
1415
redirect: "/oauth2callback"
1516
}
1617
}, function(app, server) {
18+
console.log("Server started, initializing selenium");
1719
var driver = new webdriver.Builder().
1820
withCapabilities({browserName: "chrome"}).
1921
build();
@@ -91,6 +93,7 @@ function waitForPyretLoad(driver, timeout) {
9193
}, timeout || 3000);
9294
}
9395

96+
9497
module.exports = {
9598
webbit: webbit,
9699
googleLogout: googleLogout,

‎test/browser/signin-spec.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
_ = require("jasmine-node");
2+
var tester = require("./selenium-init.js");
3+
var webdriver = require('selenium-webdriver');
4+
5+
var contains = tester.contains;
6+
var waitThenClick = tester.waitThenClick;
7+
var googleLogin = tester.googleLogin;
8+
var googleLogout = tester.googleLogout;
9+
10+
describe("Sign in", function() {
11+
tester.start(function(maybeServer, baseUrl, driver) {
12+
tester.webbit("Should forget everything it knows", function(done) {
13+
driver.get("https://security.google.com/settings/security/permissions");
14+
googleLogin(driver);
15+
console.log("Waiting to see if Patch permissions are present...");
16+
driver.wait(function() {
17+
return driver.executeScript("return document.readyState === 'complete'");
18+
}, 3000);
19+
driver.isElementPresent(contains("Patch Test")).then(function(present) {
20+
if(present) {
21+
waitThenClick(driver, contains("Patch Test"));
22+
waitThenClick(driver, contains("Revoke access"));
23+
return waitThenClick(driver, webdriver.By.name("ok"));
24+
} else {
25+
// do nothing otherwise
26+
}
27+
});
28+
googleLogout(driver);
29+
driver.call(done);
30+
}, 60000);
31+
32+
tester.webbit("Should sign up from not being logged in", function(done) {
33+
driver.get(baseUrl);
34+
driver.findElement(webdriver.By.id('login')).click();
35+
googleLogin(driver);
36+
console.log("Waiting for permission confirmation button...");
37+
driver.wait(function() {
38+
return driver.findElement(webdriver.By.id("submit_approve_access")).getAttribute("disabled")
39+
.then(function(disabled) {
40+
return !disabled;
41+
});
42+
}, 3000);
43+
driver.findElement(webdriver.By.id("submit_approve_access")).click();
44+
tester.waitForPyretLoad(driver);
45+
driver.call(done);
46+
}, 60000);
47+
48+
tester.webbit("When logging back in, should skip authentication and go straight to my-programs", function(done) {
49+
driver.get(baseUrl);
50+
driver.findElement(webdriver.By.id('login')).click();
51+
tester.waitForPyretLoad(driver);
52+
driver.call(done);
53+
}, 60000);
54+
55+
tester.webbit("If cookies are cleared, should still log in seamlessly and work", function(done) {
56+
driver.manage().deleteAllCookies();
57+
driver.get(baseUrl);
58+
driver.findElement(webdriver.By.id('login')).click();
59+
tester.waitForPyretLoad(driver);
60+
driver.call(done);
61+
}, 60000);
62+
63+
it("Should close the server and the connection to the browser", function(done) {
64+
console.log("closing down server");
65+
if(maybeServer) { maybeServer.close(); }
66+
done();
67+
});
68+
});
69+
});

‎test/browser/signin.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)