Unit tests require config file to be present.

This commit is contained in:
Hannah Wolfe 2013-09-13 08:24:28 +01:00
parent 8cea12e728
commit 7d3eb512f6
3 changed files with 41 additions and 32 deletions

View File

@ -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']);
};

View File

@ -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();

View File

@ -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/"),