Skip to content

Commit

Permalink
Clean up selenium test scripts to have simpler API
Browse files Browse the repository at this point in the history
  • Loading branch information
cowlicks committed Oct 1, 2018
1 parent 9f92ade commit a786f22
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
1 change: 0 additions & 1 deletion scripts/source_me.sh
Expand Up @@ -10,6 +10,5 @@ selenium_dir=${toplevel}/selenium
run_in_dir() {
pushd $1 > /dev/null
trap "popd > /dev/null" EXIT

$2
}
19 changes: 9 additions & 10 deletions selenium/cookies.js
Expand Up @@ -2,6 +2,7 @@

const express = require('express'),
cookieParser = require('cookie-parser'),
{firstPartyHostname, thirdPartyHostname, thirdPartyHost} = require('./utils'),
vhost = require('vhost');

let fpcookie = {name: '1pname', value: '1pvalue'},
Expand Down Expand Up @@ -33,23 +34,21 @@ class Channel {
}
}

function firstPartyApp(thirdPartyHostname, port) {
const app = express();
function firstPartyApp(app = express(), tpHost = thirdPartyHost) {
app.use(cookieParser());
app.requests = new Channel();

app.get('/', (req, res) => {
app.requests.push(req);
res.cookie(fpcookie.name, fpcookie.value);
return res.send(
`<script type="text/javascript" src="http://${thirdPartyHostname}:${port}/tracker.js"></script>`
`<script type="text/javascript" src="http://${tpHost}/tracker.js"></script>`
);
});
return app;
}

function thirdPartyApp() {
const app = express();
function thirdPartyApp(app = express()) {
app.use(cookieParser());
app.requests = new Channel();

Expand All @@ -61,12 +60,12 @@ function thirdPartyApp() {
return app;
}

function cookieApp(app, firstPartyHostname, thirdPartyHostname, port) {
let firstParty = firstPartyApp(thirdPartyHostname, port),
function cookieApp(app = express(), fpHostname = firstPartyHostname, tpHostname = thirdPartyHostname) {
let firstParty = firstPartyApp(),
thirdParty = thirdPartyApp();
app.use(vhost(firstPartyHostname, firstParty));
app.use(vhost(thirdPartyHostname, thirdParty));
Object.assign(app, {firstParty, thirdParty, firstPartyHostname, thirdPartyHostname, port});
app.use(vhost(fpHostname, firstParty));
app.use(vhost(tpHostname, thirdParty));
Object.assign(app, {firstParty, thirdParty});
return app;
}

Expand Down
6 changes: 2 additions & 4 deletions selenium/integration_tests.js
Expand Up @@ -2,14 +2,12 @@

const {assert} = require('chai');

const express = require('express'),
{newDriver, startApp, stopApp, PORT, firstPartyHostname, thirdPartyHostname, firstPartyHost} = require('./utils'),
const {newDriver, startApp, stopApp, firstPartyHost} = require('./utils'),
{cookieApp, fpcookie} = require("./cookies");

describe('cookie tests', function() {
beforeEach(function() {
// we need to only use xvfb when asked
this.app = cookieApp(module.exports = express(), firstPartyHostname, thirdPartyHostname, PORT);
this.app = cookieApp();
this.driver = newDriver();
startApp(this.app);
});
Expand Down

0 comments on commit a786f22

Please sign in to comment.