Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic sanity check test suite #299

Merged
merged 4 commits into from
Nov 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
language: node_js
node_js:
- 4.0
- 6.0
before_install:
- npm install -g mocha
install:
- npm install
script:
- gulp test
- npm test
after_success:
- "./create-release-tag.sh"
Expand Down
19 changes: 15 additions & 4 deletions gulp/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

var gulp = require('gulp')
var gutil = require('gulp-util')
var mocha = require('gulp-mocha')
var runSequence = require('run-sequence')

gulp.task('default', function (done) {
Expand Down Expand Up @@ -35,7 +35,18 @@ gulp.task('watch', function (done) {
'watch-assets', done)
})

gulp.task('test', function (done) {
gutil.log('Test that the app runs')
done()
gulp.task('test', function () {
runSequence('generate-assets',
'mocha')
})

gulp.task('mocha', function () {
return gulp.src(['test/**/*.js'], { read: false })
.pipe(mocha({ reporter: 'spec' }))
.once('error', () => {
process.exit(1)
})
.once('end', () => {
process.exit()
})
})
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"start": "node start.js",
"lint": "standard",
"test": "npm run lint"
"test": "gulp test && npm run lint"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis is running the test suite twice, because Travis.yml is doing:

script:
- gulp test
- npm test

But npm test already runs gulp test. I would suggest updating Travis.yml to only run npm test

},
"dependencies": {
"basic-auth": "^1.0.3",
Expand Down Expand Up @@ -42,5 +42,9 @@
"serve-favicon": "2.3.0",
"standard": "^7.1.2",
"sync-request": "^3.0.1"
},
"devDependencies": {
"gulp-mocha": "^3.0.1",
"supertest": "^2.0.0"
}
}
2 changes: 2 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,5 @@ utils.findAvailablePort(app, function (port) {
})
}
})

module.exports = app
1 change: 1 addition & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--recursive
33 changes: 33 additions & 0 deletions test/spec/sanity-checks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-env mocha */
var request = require('supertest')
var app = require('../../server.js')
var path = require('path')
var fs = require('fs')
var assert = require('assert')

/**
* Basic sanity checks on the dev server
*/
describe('The prototype kit', function () {
it('should generate assets into the /public folder', function () {
assert.doesNotThrow(function () {
fs.accessSync(path.resolve(__dirname, '../../public/javascripts/application.js'))
fs.accessSync(path.resolve(__dirname, '../../public/images/favicon.ico'))
fs.accessSync(path.resolve(__dirname, '../../public/stylesheets/application.css'))
})
})

it('should send with a well formed response for the index page', function (done) {
request(app)
.get('/')
.expect('Content-Type', /text\/html/)
.expect(200)
.end(function (err, res) {
if (err) {
done(err)
} else {
done()
}
})
})
})