From c919f6a2f6404533250420d1f4f001366a75bf14 Mon Sep 17 00:00:00 2001 From: Andy Mantell Date: Mon, 17 Oct 2016 13:41:18 +0100 Subject: [PATCH] Setting up a very simple test suite to check the server and build tasks run across nodejs 4, 5 & 6 --- .travis.yml | 6 ++++-- Gruntfile.js | 8 -------- package.json | 5 ++++- server.js | 2 ++ test/mocha.opts | 1 + test/spec/sanity-checks.js | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 test/mocha.opts create mode 100644 test/spec/sanity-checks.js diff --git a/.travis.yml b/.travis.yml index 4cddccc4cf..edbc8519f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,14 @@ language: node_js node_js: -- 4.0 +- "4" +- "5" +- "6" before_install: - npm install -g grunt-cli +- npm install -g mocha install: - npm install script: -- "./node_modules/grunt-cli/bin/grunt test" - npm test after_success: - "./create-release-tag.sh" diff --git a/Gruntfile.js b/Gruntfile.js index 587bb93973..18a29f773a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -137,12 +137,4 @@ module.exports = function (grunt) { 'generate-assets', 'concurrent:target' ]) - - grunt.registerTask( - 'test', - 'default', - function () { - grunt.log.writeln('Test that the app runs') - } - ) } diff --git a/package.json b/package.json index 765c5624ee..b2fdabc28e 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "start": "node start.js", "lint": "standard", - "test": "npm run lint" + "test": "mocha && npm run lint" }, "dependencies": { "basic-auth": "^1.0.3", @@ -40,5 +40,8 @@ "serve-favicon": "2.3.0", "standard": "^7.1.2", "sync-request": "^3.0.1" + }, + "devDependencies": { + "supertest": "^2.0.0" } } diff --git a/server.js b/server.js index 9f4176c1aa..010334a5b9 100644 --- a/server.js +++ b/server.js @@ -206,3 +206,5 @@ utils.findAvailablePort(app, function (port) { }) } }) + +module.exports = app diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000000..4a52320178 --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1 @@ +--recursive diff --git a/test/spec/sanity-checks.js b/test/spec/sanity-checks.js new file mode 100644 index 0000000000..9dde2eadbc --- /dev/null +++ b/test/spec/sanity-checks.js @@ -0,0 +1,34 @@ +/* global describe, it, before */ +var request = require('supertest') +var assert = require('assert') +var path = require('path') +var fs = require('fs') + +/** + * Basic sanity checks on the dev server + */ +describe('The prototype kit', function () { + var app + + before(function (done) { + require('grunt').tasks(['generate-assets'], {}, function () { + app = require('../../server') + done() + }) + }) + + 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, done) + }) +})