From 7d3eb512f62429ebff94d5ef2e67b634335f64aa Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Fri, 13 Sep 2013 08:24:28 +0100 Subject: [PATCH] Unit tests require config file to be present. --- Gruntfile.js | 53 +++++++++++++++++++++--------------- core/test/unit/admin_spec.js | 17 +++++++----- core/test/unit/testUtils.js | 3 -- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9f551b6f12..02b017705f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -3,10 +3,12 @@ var path = require('path'), semver = require("semver"), fs = require("fs"), path = require("path"), + _ = require('underscore'), spawn = require("child_process").spawn, buildDirectory = path.resolve(process.cwd(), '.build'), distDirectory = path.resolve(process.cwd(), '.dist'), - _ = require('underscore'), + configLoader = require('./core/config-loader.js'), + configureGrunt = function (grunt) { // load all grunt tasks @@ -346,6 +348,18 @@ var path = require('path'), grunt.initConfig(cfg); + grunt.registerTask('setTestEnv', function () { + // Use 'testing' Ghost config; unless we are running on travis (then show queries for debugging) + process.env.NODE_ENV = process.env.TRAVIS ? 'travis' : 'testing'; + }); + + grunt.registerTask('loadConfig', function () { + var done = this.async(); + configLoader.loadConfig().then(function () { + done(); + }); + }); + // Update the package information after changes grunt.registerTask('updateCurrentPackageInfo', function () { cfg.pkg = grunt.file.readJSON('package.json'); @@ -383,27 +397,6 @@ var path = require('path'), }); }); - // Prepare the project for development - // TODO: Git submodule init/update (https://github.com/jaubourg/grunt-update-submodules)? - grunt.registerTask("init", ["shell:bourbon", "sass:admin", 'handlebars']); - - // Run API tests only - grunt.registerTask("test-api", ["mochacli:api"]); - - // Run permisisons tests only - grunt.registerTask("test-p", ["mochacli:perm"]); - - // Run migrations tests only - grunt.registerTask("test-m", ["mochacli:migrate"]); - - // Run casperjs tests only - grunt.registerTask('test-functional', ['express:test', 'spawn-casperjs']); - - // Run tests and lint code - grunt.registerTask("validate", ["jslint", "mochacli:all", "test-functional"]); - - // Generate Docs - grunt.registerTask("docs", ["groc"]); /* Generate Changelog * - Pulls changelog from git, excluding merges. @@ -698,6 +691,22 @@ var path = require('path'), "watch" ]); + // Prepare the project for development + // TODO: Git submodule init/update (https://github.com/jaubourg/grunt-update-submodules)? + grunt.registerTask("init", ["shell:bourbon", "sass:admin", 'handlebars']); + + // Run unit tests + grunt.registerTask("test-unit", ['setTestEnv', 'loadConfig', "mochacli:all"]); + + // Run casperjs tests only + grunt.registerTask('test-functional', ['setTestEnv', 'express:test', 'spawn-casperjs']); + + // Run tests and lint code + grunt.registerTask("validate", ["jslint", "test-unit", "test-functional"]); + + // Generate Docs + grunt.registerTask("docs", ["groc"]); + // When you just say "grunt" grunt.registerTask("default", ['sass:admin', 'handlebars']); }; diff --git a/core/test/unit/admin_spec.js b/core/test/unit/admin_spec.js index e2faac7e3d..a9cf3dbd10 100644 --- a/core/test/unit/admin_spec.js +++ b/core/test/unit/admin_spec.js @@ -1,9 +1,12 @@ /*globals describe, beforeEach, it*/ -var admin = require('../../server/controllers/admin'), - fs = require('fs-extra'), +var testUtils = require('./testUtils'), should = require('should'), sinon = require('sinon'), - when = require('when'); + when = require('when'), + fs = require('fs-extra'), + + // Stuff we are testing + admin = require('../../server/controllers/admin'); describe('Admin Controller', function() { describe('uploader', function() { @@ -36,7 +39,7 @@ describe('Admin Controller', function() { }); }); - + describe('valid file', function() { var clock; @@ -56,7 +59,7 @@ describe('Admin Controller', function() { }); it('can upload jpg', function(done) { - clock = sinon.useFakeTimers(42); + clock = sinon.useFakeTimers(42); sinon.stub(res, 'send', function(data) { data.should.not.equal(404); return done(); @@ -67,7 +70,7 @@ describe('Admin Controller', function() { it('can upload png', function(done) { req.files.uploadimage.name = "IMAGE.png"; - clock = sinon.useFakeTimers(42); + clock = sinon.useFakeTimers(42); sinon.stub(res, 'send', function(data) { data.should.not.equal(404); return done(); @@ -78,7 +81,7 @@ describe('Admin Controller', function() { it('can upload gif', function(done) { req.files.uploadimage.name = "IMAGE.gif"; - clock = sinon.useFakeTimers(42); + clock = sinon.useFakeTimers(42); sinon.stub(res, 'send', function(data) { data.should.not.equal(404); return done(); diff --git a/core/test/unit/testUtils.js b/core/test/unit/testUtils.js index 2e27e1b6ae..e15e91345b 100644 --- a/core/test/unit/testUtils.js +++ b/core/test/unit/testUtils.js @@ -1,6 +1,3 @@ -// Use 'testing' Ghost config; unless we are running on travis (then show queries for debugging) -process.env.NODE_ENV = process.env.TRAVIS ? 'travis' : 'testing'; - var knex = require('../../server/models/base').Knex, when = require('when'), migration = require("../../server/data/migration/"),