Skip to content
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jlecomte committed Mar 3, 2015
1 parent e84ad87 commit 0d90c24
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
bower_components/
node_modules/
artifacts/
coverage/
build
npm-debug.log
deploy.json
Expand Down
6 changes: 5 additions & 1 deletion package.json
Expand Up @@ -60,15 +60,19 @@
"grunt-contrib-clean": "~0.5.0",
"grunt-pure-grids": "^1.0.0",
"grunt-shell-spawn": "^0.3.1",
"istanbul": "^0.3.2",
"mocha": "^2.0.1",
"chai": "^1.10.0",
"chai-as-promised": "~4.1.1",
"js-module-formats": "^0.1.0",
"mkdirp": "^0.5.0",
"rimraf": "^2.2.6",
"supertest": "~0.15.0",
"walk-sync": "^0.1.0"
},
"scripts": {
"postinstall": "bower install && grunt"
"postinstall": "bower install && grunt",
"test": "istanbul cover -- node_modules/mocha/bin/_mocha tests/unit/ --reporter spec"
},
"jshintConfig": {
"browser": true,
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/lib.layouts.js
@@ -0,0 +1,30 @@
/*global describe, it*/

process.env.NODE_ENV = 'production';

var liblayouts = require('../../lib/layouts');
var expect = require('chai').expect;

describe('lib/layouts', function () {
var layout;

describe('load()', function () {
it('returns an array', function (done) {
liblayouts.load(function (err, data) {
if (err) throw err;
expect(data).to.be.an('array');
expect(data).to.have.length(8);
layout = data[0];
done();
});
});
});

describe('archive()', function () {
it('does something', function () {
var stream = require('stream');
expect(liblayouts.archive(layout))
.to.be.an.instanceof(stream.Stream);
});
});
});
44 changes: 44 additions & 0 deletions tests/unit/lib.utils.js
@@ -0,0 +1,44 @@
/*global describe, it*/

process.env.NODE_ENV = 'production';

var libutils = require('../../lib/utils');
var expect = require('chai').expect;

describe('lib/utils', function () {
describe('error()', function () {
it('constructs an error object', function () {
expect(libutils.error(400))
.to.be.instanceof(Error)
.and.to.have.property('status')
.that.equals(400);
});
});

describe('extend()', function () {
it('augments an object', function () {
expect(libutils.extend({}, {a: 'foo'}, {b: 'bar'}))
.to.be.an('object')
.and.to.include.keys('a', 'b');
});
});

describe('passError()', function () {
it('passes an error asynchronously to a callback', function (done) {
libutils.passError(function (reason) {
expect(reason).to.equal('whatever');
done();
})('whatever');
});
});

describe('passValue()', function () {
it('passes a value asynchronously to a callback', function (done) {
libutils.passValue(function (err, value) {
expect(err).to.be.null;
expect(value).to.equal('whatever');
done();
})('whatever');
});
});
});
40 changes: 40 additions & 0 deletions tests/unit/middleware.error.js
@@ -0,0 +1,40 @@
/*global describe, it*/

process.env.NODE_ENV = 'production';

var app = require('../../app.js');
var request = require('supertest');
var expect = require('chai').expect;

app.get('/500', function (req, res) {
throw new Error('dummy error');
});

describe('Error cases', function () {
describe('GET /', function () {
it('should respond with 200', function (done) {
request(app).get('/')
.expect(200)
.expect('Content-Type', 'text/html; charset=utf-8')
.end(done);
});
});

describe('GET /404', function () {
it('should respond with 404', function (done) {
request(app).get('/404')
.expect(404)
.expect('Content-Type', 'text/html; charset=UTF-8')
.end(done);
});
});

describe('GET /500', function () {
it('should respond with 500', function (done) {
request(app).get('/500')
.expect(500)
.expect('Content-Type', 'text/html; charset=UTF-8')
.end(done);
});
});
});
39 changes: 39 additions & 0 deletions tests/unit/routes.layouts.js
@@ -0,0 +1,39 @@
/*global describe, it*/

process.env.NODE_ENV = 'production';

var express = require('express');
var layouts = require('../../routes/layouts');
var request = require('supertest');
var expect = require('chai').expect;

var app = require('../../app');

describe('routes/layouts', function () {
describe('/layouts/', function () {
it('should return 200', function (done) {
request(app).get('/layouts/')
.expect(200)
.expect('Content-Type', 'text/html; charset=utf-8')
.end(done);
});
});

describe('/layouts/blog/', function () {
it('should return 200', function (done) {
request(app).get('/layouts/blog/')
.expect(200)
.expect('Content-Type', 'text/html; charset=utf-8')
.end(done);
});
});

describe('/layouts/blog/download', function () {
it('should trigger the download of a layout', function (done) {
request(app).get('/layouts/blog/download')
.expect(200)
.expect('Content-Disposition', 'attachment; filename="pure-layout-blog.zip"')
.end(done);
});
});
});
48 changes: 48 additions & 0 deletions tests/unit/routes.start.js
@@ -0,0 +1,48 @@
/*global describe, it*/

process.env.NODE_ENV = 'production';

var express = require('express');
var layouts = require('../../routes/start');
var request = require('supertest');
var expect = require('chai').expect;

var app = require('../../app');

describe('routes/start', function () {
describe('/start/', function () {
it('should return 200', function (done) {
request(app).get('/start/')
.expect(200)
.expect('Content-Type', 'text/html; charset=utf-8')
.end(done);
});
});

describe('/start/css?mq=100', function () {
it('should return some JSON content', function (done) {
request(app).get('/start/css?mq=100')
.expect(200)
.expect('Content-Type', 'application/json; charset=utf-8')
.end(done);
});
});

describe('/start/css?mq=foo bar', function () {
it('should return 400', function (done) {
request(app).get('/start/css?mq=foo bar')
.expect(400)
.expect('Content-Type', 'text/html; charset=UTF-8')
.end(done);
});
});

describe('/start/download', function () {
it('should trigger the download of the starter kit', function (done) {
request(app).get('/start/download')
.expect(200)
.expect('Content-Disposition', 'attachment; filename="pure-start.zip"')
.end(done);
});
});
});

0 comments on commit 0d90c24

Please sign in to comment.