mirror of
https://github.com/pa11y/pa11y-dashboard.git
synced 2025-09-24 14:21:13 +00:00
Build a basic framework for functional testing
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
# Config files
|
# Config files
|
||||||
config/development.json
|
config/development.json
|
||||||
config/production.json
|
config/production.json
|
||||||
|
config/test.json
|
||||||
|
|
||||||
# Generated npm files
|
# Generated npm files
|
||||||
node_modules
|
node_modules
|
||||||
|
25
Gruntfile.js
25
Gruntfile.js
@@ -34,6 +34,15 @@ module.exports = function (grunt) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mochaTest: {
|
||||||
|
functional: {
|
||||||
|
src: ['test/functional/*.js'],
|
||||||
|
options: {
|
||||||
|
reporter: 'spec'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
nodemon: {
|
nodemon: {
|
||||||
development: {
|
development: {
|
||||||
options: {
|
options: {
|
||||||
@@ -43,6 +52,15 @@ module.exports = function (grunt) {
|
|||||||
NODE_ENV: 'development'
|
NODE_ENV: 'development'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
test: {
|
||||||
|
options: {
|
||||||
|
cwd: __dirname,
|
||||||
|
file: 'index.js',
|
||||||
|
env: {
|
||||||
|
NODE_ENV: 'test'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -84,12 +102,15 @@ module.exports = function (grunt) {
|
|||||||
grunt.loadNpmTasks('grunt-contrib-less');
|
grunt.loadNpmTasks('grunt-contrib-less');
|
||||||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||||
grunt.loadNpmTasks('grunt-contrib-watch');
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||||
|
grunt.loadNpmTasks('grunt-mocha-test');
|
||||||
grunt.loadNpmTasks('grunt-nodemon');
|
grunt.loadNpmTasks('grunt-nodemon');
|
||||||
|
|
||||||
grunt.registerTask('lint', ['jshint']);
|
grunt.registerTask('lint', ['jshint']);
|
||||||
|
grunt.registerTask('test', ['mochaTest']);
|
||||||
grunt.registerTask('compile', ['less', 'uglify']);
|
grunt.registerTask('compile', ['less', 'uglify']);
|
||||||
grunt.registerTask('start', ['nodemon:development']);
|
grunt.registerTask('start', ['nodemon:development']);
|
||||||
grunt.registerTask('default', ['compile', 'lint']);
|
grunt.registerTask('start-test', ['nodemon:test']);
|
||||||
grunt.registerTask('ci', ['compile', 'lint']);
|
grunt.registerTask('default', ['compile', 'lint', 'test']);
|
||||||
|
grunt.registerTask('ci', ['lint', 'test']);
|
||||||
|
|
||||||
};
|
};
|
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"webservice": "http://localhost:3000/",
|
|
||||||
"port": 4000,
|
"port": 4000,
|
||||||
"noindex": true,
|
"noindex": true,
|
||||||
"readonly": false,
|
"readonly": false,
|
||||||
|
12
config/test.sample.json
Normal file
12
config/test.sample.json
Normal file
@@ -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 * * *"
|
||||||
|
}
|
||||||
|
}
|
@@ -36,7 +36,11 @@
|
|||||||
"grunt-contrib-less": "~0.8",
|
"grunt-contrib-less": "~0.8",
|
||||||
"grunt-contrib-uglify": "~0.2",
|
"grunt-contrib-uglify": "~0.2",
|
||||||
"grunt-contrib-watch": "~0.5",
|
"grunt-contrib-watch": "~0.5",
|
||||||
"grunt-nodemon": "~0.1"
|
"grunt-mocha-test": "~0.7",
|
||||||
|
"grunt-nodemon": "~0.1",
|
||||||
|
"jsdom": "~0.8",
|
||||||
|
"proclaim": "~2.0",
|
||||||
|
"request": "~2.27"
|
||||||
},
|
},
|
||||||
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
44
test/functional/helper/navigate.js
Normal file
44
test/functional/helper/navigate.js
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
31
test/functional/index.js
Normal file
31
test/functional/index.js
Normal file
@@ -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');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
26
test/functional/setup.js
Normal file
26
test/functional/setup.js
Normal file
@@ -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();
|
||||||
|
});
|
||||||
|
}
|
@@ -8,7 +8,7 @@
|
|||||||
<p class="supersize-me crunch">+</p>
|
<p class="supersize-me crunch">+</p>
|
||||||
</span>
|
</span>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a class="well task-card-link crunch-bottom" data-role="add-task" href="/new">
|
<a class="well task-card-link crunch-bottom" data-role="add-task" href="/new" data-test="add-task">
|
||||||
<p class="h3 crunch">Add new URL</p>
|
<p class="h3 crunch">Add new URL</p>
|
||||||
<p class="supersize-me crunch">+</p>
|
<p class="supersize-me crunch">+</p>
|
||||||
</a>
|
</a>
|
||||||
|
Reference in New Issue
Block a user