-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build a basic framework for functional testing
- Loading branch information
1 parent
9d72e50
commit 623a52e
Showing
9 changed files
with
143 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
"webservice": "http://localhost:3000/", | ||
"port": 4000, | ||
"noindex": true, | ||
"readonly": false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"port": 4000, | ||
"noindex": true, | ||
"readonly": false, | ||
|
||
"webservice": { | ||
"database": "mongodb://localhost/pa11y-webservice-test", | ||
"host": "0.0.0.0", | ||
"port": 3000, | ||
"cron": "0 30 0 * * *" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
var jsdom = require('jsdom'); | ||
var request = require('request'); | ||
|
||
module.exports = createNavigator; | ||
|
||
// Create a navigate function | ||
function createNavigator (baseUrl, store) { | ||
return function (opts, callback) { | ||
|
||
store.body = null; | ||
store.dom = null; | ||
store.request = null; | ||
store.response = null; | ||
store.status = null; | ||
store.window = null; | ||
|
||
request({ | ||
url: baseUrl + opts.endpoint, | ||
method: opts.method || 'GET', | ||
body: opts.body, | ||
json: true, | ||
qs: opts.query | ||
}, function (err, res, body) { | ||
|
||
store.body = body; | ||
store.request = res.request; | ||
store.response = res; | ||
store.status = res.statusCode; | ||
|
||
jsdom.env( | ||
store.body, | ||
function (err, window) { | ||
store.window = window; | ||
store.dom = window.document; | ||
callback(); | ||
} | ||
); | ||
|
||
}); | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* global beforeEach, describe, it */ | ||
/* jshint maxlen: 200, maxstatements: 20 */ | ||
'use strict'; | ||
|
||
var assert = require('proclaim'); | ||
|
||
describe('GET /', function () { | ||
|
||
describe('with no query', function () { | ||
|
||
beforeEach(function (done) { | ||
var req = { | ||
method: 'GET', | ||
endpoint: '/' | ||
}; | ||
this.navigate(req, done); | ||
}); | ||
|
||
it('should send a 200 status', function () { | ||
assert.strictEqual(this.last.status, 200); | ||
}); | ||
|
||
it('should have an "Add new URL" button', function () { | ||
var elem = this.last.dom.querySelectorAll('[data-test=add-task]'); | ||
assert.strictEqual(elem.length, 1); | ||
assert.strictEqual(elem[0].getAttribute('href'), '/new'); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* global before */ | ||
/* jshint maxlen: 200 */ | ||
'use strict'; | ||
|
||
var config = require('../../config/test.json'); | ||
var createNavigator = require('./helper/navigate'); | ||
var request = require('request'); | ||
|
||
// Run before all tests | ||
before(function (done) { | ||
this.baseUrl = 'http://localhost:' + config.port; | ||
this.last = {}; | ||
this.navigate = createNavigator(this.baseUrl, this.last); | ||
assertTestAppIsRunning(this.baseUrl, done); | ||
}); | ||
|
||
// Check that the test application is running, and exit if not | ||
function assertTestAppIsRunning (url, done) { | ||
request(url, function (err) { | ||
if (err) { | ||
console.error('Error: Test app not started; run with `grunt start-test`'); | ||
process.exit(1); | ||
} | ||
done(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters