From 9ec2396213716150de389c6e869c2608a52212e1 Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Sun, 26 May 2013 12:17:46 -0500 Subject: [PATCH 1/3] Fix JSLInt errors and port existing nodeunit tests to mocha --- .gitignore | 1 + Gruntfile.js | 13 ++--- core/admin/controllers/index.js | 3 +- .../models/dataProvider.bookshelf.users.js | 3 +- core/test/ghost/dataProvider.json_spec.js | 20 +++++++ core/test/ghost/ghost_spec.js | 20 +++++++ core/test/ghost/helpers.js | 3 +- core/test/ghost/test-api.js | 56 ------------------- core/test/ghost/test-dataProvider.json.js | 16 ------ core/test/ghost/test-ghost.js | 16 ------ 10 files changed, 51 insertions(+), 100 deletions(-) create mode 100644 core/test/ghost/dataProvider.json_spec.js create mode 100644 core/test/ghost/ghost_spec.js delete mode 100644 core/test/ghost/test-api.js delete mode 100644 core/test/ghost/test-dataProvider.json.js delete mode 100644 core/test/ghost/test-ghost.js diff --git a/.gitignore b/.gitignore index 8f567c00f0..2e1e7839aa 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ projectFilesBackup /core/admin/assets/sass/config.rb /core/admin/assets/sass/layouts/config.rb /core/admin/assets/sass/modules/config.rb +/core/admin/assets/sass/modules/bourbon /ghost/.idea/ \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index d24e84629c..24641dccdb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -21,12 +21,6 @@ ] }, - // Unit test all the things! - nodeunit: { - all: ['core/test/ghost/**/test-*.js'], - api: ['core/test/ghost/test-api.js'] - }, - mochaTest: { options: { ui: "bdd", @@ -35,6 +29,10 @@ all: { src: ['core/test/**/*_spec.js'] + }, + + api: { + src: ['core/test/**/api*_spec.js'] } }, @@ -57,7 +55,6 @@ grunt.initConfig(cfg); grunt.loadNpmTasks("grunt-jslint"); - grunt.loadNpmTasks("grunt-contrib-nodeunit"); grunt.loadNpmTasks("grunt-mocha-test"); grunt.loadNpmTasks("grunt-contrib-sass"); grunt.loadNpmTasks("grunt-shell"); @@ -67,7 +64,7 @@ grunt.registerTask("init", ["shell:bourbon", "sass:admin"]); // Run API tests only - grunt.registerTask("test-api", ["nodeunit:api", "mochaTest:all"]); + grunt.registerTask("test-api", ["mochaTest:api"]); // Run tests and lint code grunt.registerTask("validate", ["jslint", "mochaTest:all"]); diff --git a/core/admin/controllers/index.js b/core/admin/controllers/index.js index dc43607551..e71561896d 100755 --- a/core/admin/controllers/index.js +++ b/core/admin/controllers/index.js @@ -86,8 +86,7 @@ api.users.add({email_address: req.body.email_address, password: req.body.password}).then(function (user) { console.log('user added', user); res.redirect('/ghost/login/'); - }, - function(error) { + }, function (error) { console.log('there was an error', error); }); } else { diff --git a/core/shared/models/dataProvider.bookshelf.users.js b/core/shared/models/dataProvider.bookshelf.users.js index f123b92390..e4e7271d4a 100644 --- a/core/shared/models/dataProvider.bookshelf.users.js +++ b/core/shared/models/dataProvider.bookshelf.users.js @@ -66,7 +66,8 @@ var test = { email_address: _userdata.email }; - models.User.forge(test).fetch().then(function (user) { + + this.model.forge(test).fetch().then(function (user) { var _user; bcrypt.compare(_userdata.pw, user.attributes.password, function (err, res) { if (err) { diff --git a/core/test/ghost/dataProvider.json_spec.js b/core/test/ghost/dataProvider.json_spec.js new file mode 100644 index 0000000000..88cec4f975 --- /dev/null +++ b/core/test/ghost/dataProvider.json_spec.js @@ -0,0 +1,20 @@ +/*globals describe, beforeEach, it*/ + +(function () { + "use strict"; + + var should = require('should'), + DataProvider = require('../../shared/models/dataProvider.json'); + + describe("dataProvider.json", function () { + + it("is a singleton", function() { + var provider1 = new DataProvider(), + provider2 = new DataProvider(); + + should.strictEqual(provider1, provider2); + }); + + }); + +}()); \ No newline at end of file diff --git a/core/test/ghost/ghost_spec.js b/core/test/ghost/ghost_spec.js new file mode 100644 index 0000000000..78440c7f28 --- /dev/null +++ b/core/test/ghost/ghost_spec.js @@ -0,0 +1,20 @@ +/*globals describe, beforeEach, it*/ + +(function () { + "use strict"; + + var should = require('should'), + Ghost = require('../../ghost'); + + describe("Ghost API", function () { + + it("is a singleton", function() { + var ghost1 = new Ghost(), + ghost2 = new Ghost(); + + should.strictEqual(ghost1, ghost2); + }); + + }); + +}()); \ No newline at end of file diff --git a/core/test/ghost/helpers.js b/core/test/ghost/helpers.js index e6e3460573..ca507b733a 100644 --- a/core/test/ghost/helpers.js +++ b/core/test/ghost/helpers.js @@ -11,9 +11,10 @@ helpers = { resetData: function () { - return migrations.one.down().then(function () { return migrations.one.up(); + }, function() { + throw new Error("Failed to reset data"); }); } }; diff --git a/core/test/ghost/test-api.js b/core/test/ghost/test-api.js deleted file mode 100644 index 1f9de952c8..0000000000 --- a/core/test/ghost/test-api.js +++ /dev/null @@ -1,56 +0,0 @@ -/*global require, module */ -(function () { - "use strict"; - - // Use 'testing' Ghost config - process.env.NODE_ENV = 'testing'; - - var _ = require('underscore'), - assert = require('assert'), - helpers = require('./helpers'), - fixtures = require('../../shared/data/fixtures/001'), - api = require('../../shared/data/api'); - - function fail(err) { - process.nextTick(function () { - assert.ifError(err); - }); - } - - module.exports = { - setUp: function (done) { - // Clear database - helpers.resetData().then(function () { - done(); - }, fail); - }, - - 'settings:browse': function (test) { - test.expect(1); - api.settings.browse().then(function (settings) { - settings = _.map(settings.toJSON(), function (item) { - return _.omit(item, 'id', 'updated_at', 'created_at'); - }); - test.deepEqual(settings, fixtures.settings); - test.done(); - }).then(null, fail); - }, - - 'settings:read': function (test) { - api.settings.read('title', function (setting) { - test.done(); - }).then(null, fail); - }, - - 'settings:edit': function (test) { - test.expect(2); - api.settings.edit('title', "Jenna O'Neil").then(function (title) { - title = title.toJSON(); - test.equal(title.key, 'title'); - test.equal(title.value, "Jenna O'Neil"); - test.done(); - }).then(null, fail); - } - }; - -}()); \ No newline at end of file diff --git a/core/test/ghost/test-dataProvider.json.js b/core/test/ghost/test-dataProvider.json.js deleted file mode 100644 index 99832a23b8..0000000000 --- a/core/test/ghost/test-dataProvider.json.js +++ /dev/null @@ -1,16 +0,0 @@ -/*global require, module */ -(function () { - "use strict"; - - var DataProvider = require('../../shared/models/dataProvider.json'); - - module.exports = { - 'singleton': function (test) { - var provider1 = new DataProvider(), - provider2 = new DataProvider(); - - test.equal(provider1, provider2); - test.done(); - } - }; -}()); \ No newline at end of file diff --git a/core/test/ghost/test-ghost.js b/core/test/ghost/test-ghost.js deleted file mode 100644 index ecd116f329..0000000000 --- a/core/test/ghost/test-ghost.js +++ /dev/null @@ -1,16 +0,0 @@ -/*global require, module */ -(function () { - "use strict"; - - var Ghost = require('../../ghost'); - - module.exports = { - 'singleton': function (test) { - var ghost1 = new Ghost(), - ghost2 = new Ghost(); - - test.equal(ghost1, ghost2); - test.done(); - } - }; -}()); \ No newline at end of file From b54b7400e4c749c40907dffac897c762764593c9 Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Sun, 26 May 2013 12:39:55 -0500 Subject: [PATCH 2/3] Remove grunt-contrib-nodeunit dependency --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index e9bdc87e11..a938a4a821 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ }, "devDependencies": { "grunt": "~0.4.1", - "grunt-contrib-nodeunit": "0.1.x", "nodeunit": "0.8.x", "grunt-jslint": "0.2.x", "should": "~1.2.2", From c41a84c45d337c79220ac001a0c9d60600b85cf9 Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Sun, 26 May 2013 12:40:25 -0500 Subject: [PATCH 3/3] Remove nodeunit dependency --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index a938a4a821..cc15aa7174 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ }, "devDependencies": { "grunt": "~0.4.1", - "nodeunit": "0.8.x", "grunt-jslint": "0.2.x", "should": "~1.2.2", "grunt-mocha-test": "~0.4.0",