From 0a319e48c5f71d55b6081bf526ba7cf3a99f12e0 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Wed, 4 Jun 2014 22:26:03 +0100 Subject: [PATCH] Cleaning up the unit tests --- core/test/unit/admin_spec.js | 6 +- core/test/unit/apps_spec.js | 22 +- core/test/unit/bootstrap_spec.js | 13 +- core/test/unit/config_spec.js | 19 +- core/test/unit/errorHandling_spec.js | 72 ++- core/test/unit/export_spec.js | 34 +- core/test/unit/filters_spec.js | 27 +- core/test/unit/frontend_spec.js | 9 +- core/test/unit/import_spec.js | 170 +++--- core/test/unit/mail_spec.js | 17 +- core/test/unit/middleware_spec.js | 16 +- core/test/unit/permissions_spec.js | 79 +-- core/test/unit/server_helpers_index_spec.js | 218 ++++---- .../test/unit/server_helpers_template_spec.js | 14 +- core/test/unit/server_spec.js | 16 +- .../unit/showdown_client_integrated_spec.js | 511 +++++++++--------- core/test/unit/showdown_ghostGFM_spec.js | 344 ++++++------ .../unit/showdown_ghostimagepreview_spec.js | 47 +- .../test/unit/storage_localfilesystem_spec.js | 26 +- core/test/unit/xmlrpc_spec.js | 13 +- 20 files changed, 871 insertions(+), 802 deletions(-) diff --git a/core/test/unit/admin_spec.js b/core/test/unit/admin_spec.js index 52485bec06..9e4d250f1c 100644 --- a/core/test/unit/admin_spec.js +++ b/core/test/unit/admin_spec.js @@ -1,4 +1,5 @@ /*globals describe, beforeEach, afterEach, it*/ +/*jshint expr:true*/ var fs = require('fs-extra'), should = require('should'), sinon = require('sinon'), @@ -8,6 +9,9 @@ var fs = require('fs-extra'), // Stuff we are testing admin = require('../../server/controllers/admin'); +// To stop jshint complaining +should.equal(true, true); + describe('Admin Controller', function () { describe('upload', function () { @@ -17,7 +21,7 @@ describe('Admin Controller', function () { req = { files: { uploadimage: { - path: "/tmp/TMPFILEID" + path: '/tmp/TMPFILEID' } } }; diff --git a/core/test/unit/apps_spec.js b/core/test/unit/apps_spec.js index 9d37da8eda..b6ad4f5e57 100644 --- a/core/test/unit/apps_spec.js +++ b/core/test/unit/apps_spec.js @@ -1,6 +1,6 @@ -/*globals describe, beforeEach, afterEach, before, it*/ -var fs = require('fs'), - path = require('path'), +/*globals describe, beforeEach, afterEach, it*/ +/*jshint expr:true*/ +var path = require('path'), EventEmitter = require('events').EventEmitter, should = require('should'), sinon = require('sinon'), @@ -8,7 +8,6 @@ var fs = require('fs'), when = require('when'), helpers = require('../../server/helpers'), filters = require('../../server/filters'), - api = require('../../server/api'), // Stuff we are testing AppProxy = require('../../server/apps/proxy'), @@ -169,7 +168,8 @@ describe('Apps', function () { appProxy.filters.register('superSecretFilter', 5, filterStub); } - registerFilterWithoutPermission.should.throw('The App "TestApp" attempted to perform an action or access a resource (filters.superSecretFilter) without permission.'); + registerFilterWithoutPermission.should.throw('The App "TestApp" attempted to perform an action or access' + + ' a resource (filters.superSecretFilter) without permission.'); registerSpy.called.should.equal(false); }); @@ -222,7 +222,8 @@ describe('Apps', function () { appProxy.filters.deregister('superSecretFilter', 5, filterStub); } - deregisterFilterWithoutPermission.should.throw('The App "TestApp" attempted to perform an action or access a resource (filters.superSecretFilter) without permission.'); + deregisterFilterWithoutPermission.should.throw('The App "TestApp" attempted to perform an action or ' + + 'access a resource (filters.superSecretFilter) without permission.'); registerSpy.called.should.equal(false); }); @@ -260,7 +261,8 @@ describe('Apps', function () { appProxy.helpers.register('otherHelper', sandbox.stub().returns('test result')); } - registerWithoutPermissions.should.throw('The App "TestApp" attempted to perform an action or access a resource (helpers.otherHelper) without permission.'); + registerWithoutPermissions.should.throw('The App "TestApp" attempted to perform an action or access a ' + + 'resource (helpers.otherHelper) without permission.'); registerSpy.called.should.equal(false); }); @@ -294,8 +296,6 @@ describe('Apps', function () { it('does not allow apps to require blacklisted modules at top level', function () { var appBox = new AppSandbox(), badAppPath = path.join(__dirname, '..', 'utils', 'fixtures', 'app', 'badtop.js'), - BadApp, - app, loadApp = function () { appBox.loadApp(badAppPath); }; @@ -327,7 +327,6 @@ describe('Apps', function () { var appBox = new AppSandbox(), badAppPath = path.join(__dirname, '..', 'utils', 'fixtures', 'app', 'badrequire.js'), BadApp, - app, loadApp = function () { BadApp = appBox.loadApp(badAppPath); }; @@ -339,7 +338,6 @@ describe('Apps', function () { var appBox = new AppSandbox(), badAppPath = path.join(__dirname, '..', 'utils', 'fixtures', 'app', 'badoutside.js'), BadApp, - app, loadApp = function () { BadApp = appBox.loadApp(badAppPath); }; @@ -382,6 +380,7 @@ describe('Apps', function () { }); describe('Permissions', function () { + /*jshint quotmark:false*/ var noGhostPackageJson = { "name": "myapp", "version": "0.0.1", @@ -469,6 +468,7 @@ describe('Apps', function () { sandbox.stub(perms, "getPackageContents").returns(when.reject(new Error('package.json file is malformed'))); perms.read().then(function (readPerms) { + /*jshint unused:false*/ done(new Error('should not resolve')); }).catch(function (err) { err.message.should.equal('package.json file is malformed'); diff --git a/core/test/unit/bootstrap_spec.js b/core/test/unit/bootstrap_spec.js index fe338e1381..2c7fe92c88 100644 --- a/core/test/unit/bootstrap_spec.js +++ b/core/test/unit/bootstrap_spec.js @@ -1,12 +1,12 @@ /*globals describe, it, beforeEach, afterEach */ - +/*jshint expr:true*/ var should = require('should'), sinon = require('sinon'), when = require('when'), path = require('path'), fs = require('fs'), _ = require('lodash'), - rewire = require("rewire"), + rewire = require('rewire'), // Thing we are testing defaultConfig = require('../../../config.example')[process.env.NODE_ENV], @@ -17,7 +17,7 @@ describe('Bootstrap', function () { var sandbox, rejectMessage = bootstrap.__get__('rejectMessage'), overrideConfig = function (newConfig) { - bootstrap.__set__("readConfigFile", sandbox.stub().returns( + bootstrap.__set__('readConfigFile', sandbox.stub().returns( _.extend({}, defaultConfig, newConfig) )); }, @@ -37,7 +37,7 @@ describe('Bootstrap', function () { // the test infrastructure is setup so that there is always config present, // but we want to overwrite the test to actually load config.example.js, so that any local changes // don't break the tests - bootstrap.__set__("configFile", path.join(config().paths.appRoot, 'config.example.js')); + bootstrap.__set__('configFile', path.join(config().paths.appRoot, 'config.example.js')); bootstrap().then(function (config) { config.url.should.equal(defaultConfig.url); @@ -73,8 +73,8 @@ describe('Bootstrap', function () { deferred.resolve(); // ensure that the file creation is a stub, the tests shouldn't really create a file - bootstrap.__set__("writeConfigFile", resolvedPromise); - bootstrap.__set__("validateConfigEnvironment", resolvedPromise); + bootstrap.__set__('writeConfigFile', resolvedPromise); + bootstrap.__set__('validateConfigEnvironment', resolvedPromise); bootstrap().then(function () { existsStub.calledOnce.should.be.true; @@ -254,6 +254,7 @@ describe('Bootstrap', function () { overrideConfig({ server: false }); bootstrap().then(function (localConfig) { + /*jshint unused:false*/ done(expectedError); }).catch(function (err) { should.exist(err); diff --git a/core/test/unit/config_spec.js b/core/test/unit/config_spec.js index c0d076b2e2..b209c8b49a 100644 --- a/core/test/unit/config_spec.js +++ b/core/test/unit/config_spec.js @@ -1,12 +1,11 @@ /*globals describe, it, beforeEach, afterEach */ - +/*jshint expr:true*/ var should = require('should'), sinon = require('sinon'), when = require('when'), path = require('path'), - fs = require('fs'), _ = require('lodash'), - rewire = require("rewire"), + rewire = require('rewire'), testUtils = require('../utils'), @@ -16,6 +15,9 @@ var should = require('should'), config = rewire('../../server/config'), configUpdate = config.__get__('updateConfig'); +// To stop jshint complaining +should.equal(true, true); + describe('Config', function () { describe('Theme', function () { @@ -221,8 +223,8 @@ describe('Config', function () { permalinks: {value: '/:year/:month/:day/:slug/'} }, today = new Date(), - dd = ("0" + today.getDate()).slice(-2), - mm = ("0" + (today.getMonth() + 1)).slice(-2), + dd = ('0' + today.getDate()).slice(-2), + mm = ('0' + (today.getMonth() + 1)).slice(-2), yyyy = today.getFullYear(), postLink = '/' + yyyy + '/' + mm + '/' + dd + '/short-and-sweet/'; @@ -267,6 +269,7 @@ describe('Config', function () { settingsStub = sandbox.stub(settings, 'read', function () { return when({ settings: [{value: '/:slug/'}] }); }), + /*jshint unused:false*/ testData = testUtils.DataGenerator.Content.posts[2], postLink = '/short-and-sweet/'; @@ -304,10 +307,11 @@ describe('Config', function () { settingsStub = sandbox.stub(settings, 'read', function () { return when({ settings: [{value: '/:year/:month/:day/:slug/'}] }); }), + /*jshint unused:false*/ testData = testUtils.DataGenerator.Content.posts[2], today = new Date(), - dd = ("0" + today.getDate()).slice(-2), - mm = ("0" + (today.getMonth() + 1)).slice(-2), + dd = ('0' + today.getDate()).slice(-2), + mm = ('0' + (today.getMonth() + 1)).slice(-2), yyyy = today.getFullYear(), postLink = '/' + yyyy + '/' + mm + '/' + dd + '/short-and-sweet/'; @@ -344,6 +348,7 @@ describe('Config', function () { settingsStub = sandbox.stub(settings, 'read', function () { return when({ settings: [{value: '/:year/:month/:day/:slug/'}] }); }), + /*jshint unused:false*/ testData = testUtils.DataGenerator.Content.posts[5], postLink = '/static-page-test/'; diff --git a/core/test/unit/errorHandling_spec.js b/core/test/unit/errorHandling_spec.js index 585f38bae7..dd16656000 100644 --- a/core/test/unit/errorHandling_spec.js +++ b/core/test/unit/errorHandling_spec.js @@ -1,47 +1,51 @@ -/*globals describe, before, beforeEach, afterEach, it*/ -var testUtils = require('../utils'), - should = require('should'), +/*globals describe, after, before, beforeEach, afterEach, it*/ +/*jshint expr:true*/ +var should = require('should'), when = require('when'), sinon = require('sinon'), express = require('express'), - rewire = require('rewire') + rewire = require('rewire'), // Stuff we are testing + colors = require('colors'), errors = rewire('../../server/errors'), // storing current environment currentEnv = process.env.NODE_ENV; +// This is not useful but required for jshint +colors.setTheme({silly: 'rainbow'}); + describe('Error handling', function () { // Just getting rid of jslint unused error should.exist(errors); describe('Throwing', function () { - it("throws error objects", function () { - var toThrow = new Error("test1"), + it('throws error objects', function () { + var toThrow = new Error('test1'), runThrowError = function () { errors.throwError(toThrow); }; - runThrowError.should['throw']("test1"); + runThrowError.should['throw']('test1'); }); - it("throws error strings", function () { - var toThrow = "test2", + it('throws error strings', function () { + var toThrow = 'test2', runThrowError = function () { errors.throwError(toThrow); }; - runThrowError.should['throw']("test2"); + runThrowError.should['throw']('test2'); }); - it("throws error even if nothing passed", function () { + it('throws error even if nothing passed', function () { var runThrowError = function () { errors.throwError(); }; - runThrowError.should['throw']("An error occurred"); + runThrowError.should['throw']('An error occurred'); }); }); @@ -51,7 +55,7 @@ describe('Error handling', function () { beforeEach(function () { logStub = sinon.stub(console, 'error'); // give environment a value that will console log - process.env.NODE_ENV = "development"; + process.env.NODE_ENV = 'development'; }); afterEach(function () { @@ -88,7 +92,9 @@ describe('Error handling', function () { // Calls log with message on Error objects logStub.calledOnce.should.be.true; - logStub.calledWith('\nERROR:'.red, err.message.red, '\n', message.white, '\n', message.green, '\n', err.stack, '\n'); + logStub.calledWith( + '\nERROR:'.red, err.message.red, '\n', message.white, '\n', message.green, '\n', err.stack, '\n' + ); }); it('logs errors from three string arguments', function () { @@ -98,7 +104,9 @@ describe('Error handling', function () { // Calls log with message on Error objects logStub.calledOnce.should.be.true; - logStub.calledWith('\nERROR:'.red, message.red, '\n', message.white, '\n', message.green, '\n').should.be.true; + logStub.calledWith( + '\nERROR:'.red, message.red, '\n', message.white, '\n', message.green, '\n' + ).should.be.true; }); it('logs errors from an undefined error argument', function () { @@ -109,7 +117,9 @@ describe('Error handling', function () { // Calls log with message on Error objects logStub.calledOnce.should.be.true; - logStub.calledWith('\nERROR:'.red, 'An unknown error occurred.'.red, '\n', message.white, '\n', message.green , '\n').should.be.true; + logStub.calledWith( + '\nERROR:'.red, 'An unknown error occurred.'.red, '\n', message.white, '\n', message.green , '\n' + ).should.be.true; }); it('logs errors from an undefined context argument', function () { @@ -142,7 +152,9 @@ describe('Error handling', function () { // Calls log with message on Error objects logStub.calledOnce.should.be.true; - logStub.calledWith('\nERROR:'.red, 'An unknown error occurred.'.red, '\n', message.white, '\n', message.green, '\n').should.be.true; + logStub.calledWith( + '\nERROR:'.red, 'An unknown error occurred.'.red, '\n', message.white, '\n', message.green, '\n' + ).should.be.true; }); it('logs errors from a null context argument', function () { @@ -220,7 +232,7 @@ describe('Error handling', function () { } } } - } + }; }); errors.updateActiveTheme('casper'); }); @@ -242,6 +254,7 @@ describe('Error handling', function () { res = express.response; sandbox.stub(express.response, 'render', function (view, options, fn) { + /*jshint unused:false */ view.should.match(/user-error\.hbs/); // Test that the message is correct @@ -250,7 +263,9 @@ describe('Error handling', function () { this.statusCode.should.equal(404); // Test that the headers are correct - this._headers['cache-control'].should.equal('no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'); + this._headers['cache-control'].should.equal( + 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0' + ); done(); }); @@ -269,6 +284,7 @@ describe('Error handling', function () { res = express.response; sandbox.stub(express.response, 'render', function (view, options, fn) { + /*jshint unused:false */ view.should.match(/user-error\.hbs/); // Test that the message is correct @@ -277,7 +293,9 @@ describe('Error handling', function () { this.statusCode.should.equal(404); // Test that the headers are correct - this._headers['cache-control'].should.equal('no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'); + this._headers['cache-control'].should.equal( + 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0' + ); done(); }); @@ -298,6 +316,7 @@ describe('Error handling', function () { res = express.response; sandbox.stub(express.response, 'render', function (view, options, fn) { + /*jshint unused:false */ view.should.match(/user-error\.hbs/); // Test that the message is correct @@ -306,7 +325,9 @@ describe('Error handling', function () { this.statusCode.should.equal(500); // Test that the headers are correct - this._headers['cache-control'].should.equal('no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'); + this._headers['cache-control'].should.equal( + 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0' + ); done(); }); @@ -325,6 +346,7 @@ describe('Error handling', function () { res = express.response; sandbox.stub(express.response, 'render', function (view, options, fn) { + /*jshint unused:false */ view.should.match(/user-error\.hbs/); // Test that the message is correct @@ -333,7 +355,9 @@ describe('Error handling', function () { this.statusCode.should.equal(500); // Test that the headers are correct - this._headers['cache-control'].should.equal('no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'); + this._headers['cache-control'].should.equal( + 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0' + ); done(); }); @@ -346,7 +370,7 @@ describe('Error handling', function () { err.code = 500; errors.error500(err, req, res, null); }); - + it('Renders custom error template if one exists', function(done){ var code = 404, error = {message:'Custom view test'}, @@ -355,9 +379,11 @@ describe('Error handling', function () { }, res = { status: function(code) { + /*jshint unused:false*/ return this; }, render: function(view, model, fn){ + /*jshint unused:false*/ view.should.eql('error'); errors.updateActiveTheme('casper'); done(); diff --git a/core/test/unit/export_spec.js b/core/test/unit/export_spec.js index 57bd875bcb..2d295342e6 100644 --- a/core/test/unit/export_spec.js +++ b/core/test/unit/export_spec.js @@ -1,18 +1,16 @@ /*globals describe, before, beforeEach, afterEach, it*/ -var testUtils = require('../utils'), - should = require('should'), - sinon = require('sinon'), - when = require('when'), - _ = require("lodash"), - errors = require('../../server/errors'), +/*jshint expr:true*/ +var testUtils = require('../utils'), + should = require('should'), + sinon = require('sinon'), + when = require('when'), + _ = require('lodash'), // Stuff we are testing - migration = require('../../server/data/migration'), - versioning = require('../../server/data/versioning'), - exporter = require('../../server/data/export'), - Settings = require('../../server/models/settings').Settings; + versioning = require('../../server/data/versioning'), + exporter = require('../../server/data/export'); -describe("Exporter", function () { +describe('Exporter', function () { should.exist(exporter); @@ -38,23 +36,23 @@ describe("Exporter", function () { }).catch(done); }); - it("exports data", function (done) { + it('exports data', function (done) { // Stub migrations to return 000 as the current database version - var versioningStub = sandbox.stub(versioning, "getDatabaseVersion", function () { - return when.resolve("003"); + var versioningStub = sandbox.stub(versioning, 'getDatabaseVersion', function () { + return when.resolve('003'); }); exporter().then(function (exportData) { - var tables = ['posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles', 'permissions_users', - 'settings', 'tags', 'posts_tags']; + var tables = ['posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles', + 'permissions_users', 'settings', 'tags', 'posts_tags']; should.exist(exportData); should.exist(exportData.meta); should.exist(exportData.data); - exportData.meta.version.should.equal("003"); - _.findWhere(exportData.data.settings, {key: "databaseVersion"}).value.should.equal("003"); + exportData.meta.version.should.equal('003'); + _.findWhere(exportData.data.settings, {key: 'databaseVersion'}).value.should.equal('003'); _.each(tables, function (name) { should.exist(exportData.data[name]); diff --git a/core/test/unit/filters_spec.js b/core/test/unit/filters_spec.js index 68d63029e6..2736ab8e5a 100644 --- a/core/test/unit/filters_spec.js +++ b/core/test/unit/filters_spec.js @@ -1,15 +1,14 @@ -/*globals describe, before, beforeEach, afterEach, it*/ -var testUtils = require('../utils'), - should = require('should'), - sinon = require('sinon'), - when = require('when'), - path = require('path'), - _ = require('lodash'), +/*globals describe, beforeEach, afterEach, it*/ +/*jshint expr:true*/ +var should = require('should'), + sinon = require('sinon'), + when = require('when'), + _ = require('lodash'), // Stuff we are testing Filters = require('../../server/filters').Filters; -describe("Filters", function () { +describe('Filters', function () { var filters, sandbox; @@ -23,7 +22,7 @@ describe("Filters", function () { sandbox.restore(); }); - it("can register filters with specific priority", function () { + it('can register filters with specific priority', function () { var filterName = 'test', filterPriority = 9, testFilterHandler = sandbox.spy(); @@ -36,7 +35,7 @@ describe("Filters", function () { filters.filterCallbacks[filterName][filterPriority].should.include(testFilterHandler); }); - it("can register filters with default priority", function () { + it('can register filters with default priority', function () { var filterName = 'test', defaultPriority = 5, testFilterHandler = sandbox.spy(); @@ -49,7 +48,7 @@ describe("Filters", function () { filters.filterCallbacks[filterName][defaultPriority].should.include(testFilterHandler); }); - it("can register filters with priority null with default priority", function () { + it('can register filters with priority null with default priority', function () { var filterName = 'test', defaultPriority = 5, testFilterHandler = sandbox.spy(); @@ -62,7 +61,7 @@ describe("Filters", function () { filters.filterCallbacks[filterName][defaultPriority].should.include(testFilterHandler); }); - it("executes filters in priority order", function (done) { + it('executes filters in priority order', function (done) { var filterName = 'testpriority', testFilterHandler1 = sandbox.spy(), testFilterHandler2 = sandbox.spy(), @@ -83,7 +82,7 @@ describe("Filters", function () { }); }); - it("executes filters that return a promise", function (done) { + it('executes filters that return a promise', function (done) { var filterName = 'testprioritypromise', testFilterHandler1 = sinon.spy(function (args) { return when.promise(function (resolve) { @@ -128,7 +127,7 @@ describe("Filters", function () { }).catch(done); }); - it("executes filters with a context", function (done) { + it('executes filters with a context', function (done) { var filterName = 'textContext', testFilterHandler1 = sinon.spy(function (args, context) { args.context1 = _.isObject(context); diff --git a/core/test/unit/frontend_spec.js b/core/test/unit/frontend_spec.js index 118632a13f..c0acdc3202 100644 --- a/core/test/unit/frontend_spec.js +++ b/core/test/unit/frontend_spec.js @@ -1,4 +1,5 @@ /*globals describe, beforeEach, afterEach, it*/ +/*jshint expr:true*/ var assert = require('assert'), moment = require('moment'), should = require('should'), @@ -11,10 +12,12 @@ var assert = require('assert'), api = require('../../server/api'), frontend = rewire('../../server/controllers/frontend'); +// To stop jshint complaining +should.equal(true, true); + describe('Frontend Controller', function () { - var ghost, - sandbox, + var sandbox, apiSettingsStub, adminEditPagePath = '/ghost/editor/'; @@ -183,7 +186,7 @@ describe('Frontend Controller', function () { }; beforeEach(function () { - sandbox.stub(api.posts, 'browse', function (args) { + sandbox.stub(api.posts, 'browse', function () { return when({ posts: mockPosts, meta: { diff --git a/core/test/unit/import_spec.js b/core/test/unit/import_spec.js index 3add769955..33049d25eb 100644 --- a/core/test/unit/import_spec.js +++ b/core/test/unit/import_spec.js @@ -1,11 +1,11 @@ -/*globals describe, beforeEach, it*/ +/*globals describe, beforeEach, afterEach, it*/ +/*jshint expr:true*/ var testUtils = require('../utils'), should = require('should'), sinon = require('sinon'), when = require('when'), assert = require('assert'), - _ = require("lodash"), - errors = require('../../server/errors'), + _ = require('lodash'), // Stuff we are testing knex = require('../../server/models/base').knex, @@ -16,11 +16,9 @@ var testUtils = require('../utils'), Importer000 = require('../../server/data/import/000'), Importer001 = require('../../server/data/import/001'), Importer002 = require('../../server/data/import/002'), - Importer003 = require('../../server/data/import/003'), - fixtures = require('../../server/data/fixtures'), - Settings = require('../../server/models/settings').Settings; + Importer003 = require('../../server/data/import/003'); -describe("Import", function () { +describe('Import', function () { should.exist(exporter); should.exist(importer); @@ -39,13 +37,13 @@ describe("Import", function () { sandbox.restore(); }); - it("resolves 000", function (done) { - var importStub = sandbox.stub(Importer000, "importData", function () { + it('resolves 000', function (done) { + var importStub = sandbox.stub(Importer000, 'importData', function () { return when.resolve(); }), fakeData = { test: true }; - importer("000", fakeData).then(function () { + importer('000', fakeData).then(function () { importStub.calledWith(fakeData).should.equal(true); importStub.restore(); @@ -54,13 +52,13 @@ describe("Import", function () { }).catch(done); }); - it("resolves 001", function (done) { - var importStub = sandbox.stub(Importer001, "importData", function () { + it('resolves 001', function (done) { + var importStub = sandbox.stub(Importer001, 'importData', function () { return when.resolve(); }), fakeData = { test: true }; - importer("001", fakeData).then(function () { + importer('001', fakeData).then(function () { importStub.calledWith(fakeData).should.equal(true); importStub.restore(); @@ -69,13 +67,13 @@ describe("Import", function () { }).catch(done); }); - it("resolves 002", function (done) { - var importStub = sandbox.stub(Importer002, "importData", function () { + it('resolves 002', function (done) { + var importStub = sandbox.stub(Importer002, 'importData', function () { return when.resolve(); }), fakeData = { test: true }; - importer("002", fakeData).then(function () { + importer('002', fakeData).then(function () { importStub.calledWith(fakeData).should.equal(true); importStub.restore(); @@ -84,13 +82,13 @@ describe("Import", function () { }).catch(done); }); - it("resolves 003", function (done) { - var importStub = sandbox.stub(Importer003, "importData", function () { + it('resolves 003', function (done) { + var importStub = sandbox.stub(Importer003, 'importData', function () { return when.resolve(); }), fakeData = { test: true }; - importer("003", fakeData).then(function () { + importer('003', fakeData).then(function () { importStub.calledWith(fakeData).should.equal(true); importStub.restore(); @@ -99,7 +97,7 @@ describe("Import", function () { }).catch(done); }); - describe("000", function () { + describe('000', function () { should.exist(Importer000); beforeEach(function (done) { @@ -112,23 +110,23 @@ describe("Import", function () { }); - it("imports data from 000", function (done) { + it('imports data from 000', function (done) { var exportData, - versioningStub = sandbox.stub(versioning, "getDatabaseVersion", function () { - return when.resolve("000"); + versioningStub = sandbox.stub(versioning, 'getDatabaseVersion', function () { + return when.resolve('000'); }); testUtils.loadExportFixture('export-000').then(function (exported) { exportData = exported; - return importer("000", exportData); + return importer('000', exportData); }).then(function () { // Grab the data from tables return when.all([ - knex("users").select(), - knex("posts").select(), - knex("settings").select(), - knex("tags").select() + knex('users').select(), + knex('posts').select(), + knex('settings').select(), + knex('tags').select() ]); }).then(function (importedData) { should.exist(importedData); @@ -147,7 +145,7 @@ describe("Import", function () { // test settings settings.length.should.be.above(0, 'Wrong number of settings'); - _.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version'); + _.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version'); // test tags tags.length.should.equal(exportData.data.tags.length, 'no new tags'); @@ -159,7 +157,7 @@ describe("Import", function () { }); }); - describe("001", function () { + describe('001', function () { should.exist(Importer001); beforeEach(function (done) { @@ -171,7 +169,7 @@ describe("Import", function () { }).catch(done); }); - it("safely imports data from 001", function (done) { + it('safely imports data from 001', function (done) { var exportData, timestamp = 1349928000000; @@ -183,14 +181,14 @@ describe("Import", function () { exportData.data.posts[0].updated_at = timestamp; exportData.data.posts[0].published_at = timestamp; - return importer("001", exportData); + return importer('001', exportData); }).then(function () { // Grab the data from tables return when.all([ - knex("users").select(), - knex("posts").select(), - knex("settings").select(), - knex("tags").select() + knex('users').select(), + knex('posts').select(), + knex('settings').select(), + knex('tags').select() ]); }).then(function (importedData) { should.exist(importedData); @@ -219,14 +217,14 @@ describe("Import", function () { // test settings settings.length.should.be.above(0, 'Wrong number of settings'); - _.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version'); + _.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version'); // activeTheme should NOT have been overridden - _.findWhere(settings, {key: "activeTheme"}).value.should.equal("casper", 'Wrong theme'); + _.findWhere(settings, {key: 'activeTheme'}).value.should.equal('casper', 'Wrong theme'); // email address should have been overridden - exportEmail = _.findWhere(exportData.data.settings, {key: "email"}).value; - _.findWhere(settings, {key: "email"}).value.should.equal(exportEmail, 'Wrong email in settings'); + exportEmail = _.findWhere(exportData.data.settings, {key: 'email'}).value; + _.findWhere(settings, {key: 'email'}).value.should.equal(exportEmail, 'Wrong email in settings'); // test tags tags.length.should.equal(exportData.data.tags.length, 'no new tags'); @@ -244,7 +242,7 @@ describe("Import", function () { }).catch(done); }); - it("doesn't import invalid post data from 001", function (done) { + it('doesn\'t import invalid post data from 001', function (done) { var exportData; @@ -254,7 +252,7 @@ describe("Import", function () { //change title to 151 characters exportData.data.posts[0].title = new Array(152).join('a'); exportData.data.posts[0].tags = 'Tag'; - return importer("001", exportData); + return importer('001', exportData); }).then(function () { (1).should.eql(0, 'Data import should not resolve promise.'); }, function (error) { @@ -263,10 +261,10 @@ describe("Import", function () { error[0].type.should.eql('ValidationError'); when.all([ - knex("users").select(), - knex("posts").select(), - knex("settings").select(), - knex("tags").select() + knex('users').select(), + knex('posts').select(), + knex('settings').select(), + knex('tags').select() ]).then(function (importedData) { should.exist(importedData); @@ -284,7 +282,7 @@ describe("Import", function () { // test settings settings.length.should.be.above(0, 'Wrong number of settings'); - _.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version'); + _.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version'); // test tags tags.length.should.equal(exportData.data.tags.length, 'no new tags'); @@ -295,14 +293,14 @@ describe("Import", function () { }).catch(done); }); - it("doesn't import invalid settings data from 001", function (done) { + it('doesn\'t import invalid settings data from 001', function (done) { var exportData; testUtils.loadExportFixture('export-001').then(function (exported) { exportData = exported; //change to blank settings key exportData.data.settings[3].key = null; - return importer("001", exportData); + return importer('001', exportData); }).then(function () { (1).should.eql(0, 'Data import should not resolve promise.'); }, function (error) { @@ -311,10 +309,10 @@ describe("Import", function () { error[0].type.should.eql('ValidationError'); when.all([ - knex("users").select(), - knex("posts").select(), - knex("settings").select(), - knex("tags").select() + knex('users').select(), + knex('posts').select(), + knex('settings').select(), + knex('tags').select() ]).then(function (importedData) { should.exist(importedData); @@ -332,7 +330,7 @@ describe("Import", function () { // test settings settings.length.should.be.above(0, 'Wrong number of settings'); - _.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version'); + _.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version'); // test tags tags.length.should.equal(exportData.data.tags.length, 'no new tags'); @@ -344,7 +342,7 @@ describe("Import", function () { }); }); - describe("002", function () { + describe('002', function () { should.exist(Importer002); beforeEach(function (done) { @@ -356,7 +354,7 @@ describe("Import", function () { }).catch(done); }); - it("safely imports data from 002", function (done) { + it('safely imports data from 002', function (done) { var exportData, timestamp = 1349928000000; @@ -368,14 +366,14 @@ describe("Import", function () { exportData.data.posts[0].updated_at = timestamp; exportData.data.posts[0].published_at = timestamp; - return importer("002", exportData); + return importer('002', exportData); }).then(function () { // Grab the data from tables return when.all([ - knex("users").select(), - knex("posts").select(), - knex("settings").select(), - knex("tags").select() + knex('users').select(), + knex('posts').select(), + knex('settings').select(), + knex('tags').select() ]); }).then(function (importedData) { should.exist(importedData); @@ -404,14 +402,14 @@ describe("Import", function () { // test settings settings.length.should.be.above(0, 'Wrong number of settings'); - _.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version'); + _.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version'); // activeTheme should NOT have been overridden - _.findWhere(settings, {key: "activeTheme"}).value.should.equal("casper", 'Wrong theme'); + _.findWhere(settings, {key: 'activeTheme'}).value.should.equal('casper', 'Wrong theme'); // email address should have been overridden - exportEmail = _.findWhere(exportData.data.settings, {key: "email"}).value; - _.findWhere(settings, {key: "email"}).value.should.equal(exportEmail, 'Wrong email in settings'); + exportEmail = _.findWhere(exportData.data.settings, {key: 'email'}).value; + _.findWhere(settings, {key: 'email'}).value.should.equal(exportEmail, 'Wrong email in settings'); // test tags tags.length.should.equal(exportData.data.tags.length, 'no new tags'); @@ -431,7 +429,7 @@ describe("Import", function () { }); }); - it("doesn't import invalid post data from 002", function (done) { + it('doesn\'t import invalid post data from 002', function (done) { var exportData; @@ -441,7 +439,7 @@ describe("Import", function () { //change title to 151 characters exportData.data.posts[0].title = new Array(152).join('a'); exportData.data.posts[0].tags = 'Tag'; - return importer("002", exportData); + return importer('002', exportData); }).then(function () { (1).should.eql(0, 'Data import should not resolve promise.'); }, function (error) { @@ -450,10 +448,10 @@ describe("Import", function () { error[0].type.should.eql('ValidationError'); when.all([ - knex("users").select(), - knex("posts").select(), - knex("settings").select(), - knex("tags").select() + knex('users').select(), + knex('posts').select(), + knex('settings').select(), + knex('tags').select() ]).then(function (importedData) { should.exist(importedData); @@ -471,7 +469,7 @@ describe("Import", function () { // test settings settings.length.should.be.above(0, 'Wrong number of settings'); - _.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version'); + _.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version'); // test tags tags.length.should.equal(exportData.data.tags.length, 'no new tags'); @@ -482,14 +480,14 @@ describe("Import", function () { }).catch(done); }); - it("doesn't import invalid settings data from 002", function (done) { + it('doesn\'t import invalid settings data from 002', function (done) { var exportData; testUtils.loadExportFixture('export-002').then(function (exported) { exportData = exported; //change to blank settings key exportData.data.settings[3].key = null; - return importer("002", exportData); + return importer('002', exportData); }).then(function () { (1).should.eql(0, 'Data import should not resolve promise.'); }, function (error) { @@ -498,10 +496,10 @@ describe("Import", function () { error[0].type.should.eql('ValidationError'); when.all([ - knex("users").select(), - knex("posts").select(), - knex("settings").select(), - knex("tags").select() + knex('users').select(), + knex('posts').select(), + knex('settings').select(), + knex('tags').select() ]).then(function (importedData) { should.exist(importedData); @@ -519,7 +517,7 @@ describe("Import", function () { // test settings settings.length.should.be.above(0, 'Wrong number of settings'); - _.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version'); + _.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version'); // test tags tags.length.should.equal(exportData.data.tags.length, 'no new tags'); @@ -531,7 +529,7 @@ describe("Import", function () { }); }); - describe("003", function () { + describe('003', function () { should.exist(Importer003); beforeEach(function (done) { @@ -543,25 +541,25 @@ describe("Import", function () { }).catch(done); }); - it("safely imports data from 003", function (done) { + it('safely imports data from 003', function (done) { var exportData; testUtils.loadExportFixture('export-003').then(function (exported) { exportData = exported; - return importer("003", exportData); + return importer('003', exportData); }).then(function () { // Grab the data from tables return when.all([ - knex("apps").select(), - knex("app_settings").select() + knex('apps').select(), + knex('app_settings').select() ]); }).then(function (importedData) { should.exist(importedData); importedData.length.should.equal(2, 'Did not get data successfully'); - var apps = importedData[0], - app_settings = importedData[1]; + var apps = importedData[0]; + // app_settings = importedData[1]; // test apps apps.length.should.equal(exportData.data.apps.length, 'imported apps'); diff --git a/core/test/unit/mail_spec.js b/core/test/unit/mail_spec.js index 8df865b212..85ec41bdac 100644 --- a/core/test/unit/mail_spec.js +++ b/core/test/unit/mail_spec.js @@ -1,11 +1,10 @@ /*globals describe, beforeEach, afterEach, it*/ +/*jshint expr:true*/ var should = require('should'), sinon = require('sinon'), when = require('when'), - _ = require("lodash"), - cp = require('child_process'), - rewire = require("rewire"), - testUtils = require('../utils'), + _ = require('lodash'), + rewire = require('rewire'), // Stuff we are testing mailer = rewire('../../server/mail'), @@ -38,7 +37,7 @@ SENDMAIL = { } }; -describe("Mail", function () { +describe('Mail', function () { var overrideConfig = function (newConfig) { mailer.__set__('config', sandbox.stub().returns( _.extend({}, defaultConfig, newConfig) @@ -56,11 +55,11 @@ describe("Mail", function () { config = sinon.stub().returns(fakeConfig); - sandbox.stub(mailer, "isWindows", function () { + sandbox.stub(mailer, 'isWindows', function () { return false; }); - sandbox.stub(mailer, "detectSendmail", function () { + sandbox.stub(mailer, 'detectSendmail', function () { return when.resolve(fakeSendmail); }); }); @@ -119,7 +118,7 @@ describe("Mail", function () { it('should disable transport if config is empty & sendmail not found', function (done) { overrideConfig({mail: {}}); mailer.detectSendmail.restore(); - sandbox.stub(mailer, "detectSendmail", when.reject); + sandbox.stub(mailer, 'detectSendmail', when.reject); mailer.init().then(function () { should.not.exist(mailer.transport); done(); @@ -141,7 +140,7 @@ describe("Mail", function () { it('should fail to send messages when no transport is set', function (done) { mailer.detectSendmail.restore(); - sandbox.stub(mailer, "detectSendmail", when.reject); + sandbox.stub(mailer, 'detectSendmail', when.reject); mailer.init().then(function () { mailer.send().then(function () { should.fail(); diff --git a/core/test/unit/middleware_spec.js b/core/test/unit/middleware_spec.js index fede4ab9e1..de403da945 100644 --- a/core/test/unit/middleware_spec.js +++ b/core/test/unit/middleware_spec.js @@ -1,10 +1,9 @@ /*globals describe, beforeEach, afterEach, it*/ +/*jshint expr:true*/ var assert = require('assert'), should = require('should'), sinon = require('sinon'), - when = require('when'), _ = require('lodash'), - express = require('express'), api = require('../../server/api'), middleware = require('../../server/middleware').middleware; @@ -178,7 +177,10 @@ describe('Middleware', function () { middleware.cacheControl('private')(null, res, function (a) { should.not.exist(a); res.set.calledOnce.should.be.true; - res.set.calledWith({'Cache-Control': 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'}); + res.set.calledWith({ + 'Cache-Control': + 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0' + }); done(); }); }); @@ -275,16 +277,12 @@ describe('Middleware', function () { }); it('should call express.static if valid file type', function (done) { - var ghostStub = { - paths: function () { - return {activeTheme: 'ACTIVETHEME'}; - } - }, - req = { + var req = { url: 'myvalidfile.css' }; middleware.staticTheme(null)(req, null, function (reqArg, res, next) { + /*jshint unused:false */ middleware.forwardToExpressStatic.calledOnce.should.be.true; assert.deepEqual(middleware.forwardToExpressStatic.args[0][0], req); done(); diff --git a/core/test/unit/permissions_spec.js b/core/test/unit/permissions_spec.js index 5a9cadadd3..f284988a13 100644 --- a/core/test/unit/permissions_spec.js +++ b/core/test/unit/permissions_spec.js @@ -1,10 +1,10 @@ -/*globals describe, before, beforeEach, afterEach, it*/ -var testUtils = require('../utils'), - should = require('should'), - sinon = require('sinon'), - when = require('when'), - _ = require("lodash"), - errors = require('../../server/errors'), +/*globals describe, before, beforeEach, afterEach, after, it*/ +/*jshint expr:true*/ +var testUtils = require('../utils'), + should = require('should'), + sinon = require('sinon'), + when = require('when'), + _ = require('lodash'), // Stuff we are testing permissions = require('../../server/permissions'), @@ -39,22 +39,22 @@ describe('Permissions', function () { }); var testPerms = [ - { act: "edit", obj: "post" }, - { act: "edit", obj: "tag" }, - { act: "edit", obj: "user" }, - { act: "edit", obj: "page" }, - { act: "add", obj: "post" }, - { act: "add", obj: "user" }, - { act: "add", obj: "page" }, - { act: "remove", obj: "post" }, - { act: "remove", obj: "user" } + { act: 'edit', obj: 'post' }, + { act: 'edit', obj: 'tag' }, + { act: 'edit', obj: 'user' }, + { act: 'edit', obj: 'page' }, + { act: 'add', obj: 'post' }, + { act: 'add', obj: 'user' }, + { act: 'add', obj: 'page' }, + { act: 'remove', obj: 'post' }, + { act: 'remove', obj: 'user' } ], currTestPermId = 1, createPermission = function (name, act, obj) { if (!name) { currTestPermId += 1; - name = "test" + currTestPermId; + name = 'test' + currTestPermId; } var newPerm = { @@ -131,7 +131,7 @@ describe('Permissions', function () { it('can add user permissions', function (done) { UserProvider.findOne({id: 1}, { withRelated: ['permissions']}).then(function (testUser) { var testPermission = new Models.Permission({ - name: "test edit posts", + name: 'test edit posts', action_type: 'edit', object_type: 'post' }); @@ -154,8 +154,8 @@ describe('Permissions', function () { it('can add role permissions', function (done) { var testRole = new Models.Role({ - name: "test2", - description: "test2 description" + name: 'test2', + description: 'test2 description' }); testRole.save(null, {user: 1}) @@ -164,7 +164,7 @@ describe('Permissions', function () { }) .then(function () { var rolePermission = new Models.Permission({ - name: "test edit posts", + name: 'test edit posts', action_type: 'edit', object_type: 'post' }); @@ -227,7 +227,7 @@ describe('Permissions', function () { it('allows edit post with permission', function (done) { var fakePost = { - id: "1" + id: '1' }; createTestPermissions() @@ -237,9 +237,9 @@ describe('Permissions', function () { }) .then(function (foundUser) { var newPerm = new Models.Permission({ - name: "test3 edit post", - action_type: "edit", - object_type: "post" + name: 'test3 edit post', + action_type: 'edit', + object_type: 'post' }); return newPerm.save(null, {user: 1}).then(function () { @@ -281,7 +281,8 @@ describe('Permissions', function () { }) .then(function () { permissableStub.restore(); - permissableStub.calledWith(123, { user: testUser.id, app: null, internal: false }).should.equal(true); + permissableStub.calledWith(123, { user: testUser.id, app: null, internal: false }) + .should.equal(true); done(); }) @@ -310,16 +311,17 @@ describe('Permissions', function () { .then(function () { permissableStub.restore(); - done(new Error("Allowed testUser to edit post")); + done(new Error('Allowed testUser to edit post')); }) .catch(function () { - permissableStub.calledWith(123, { user: testUser.id, app: null, internal: false }).should.equal(true); + permissableStub.calledWith(123, { user: testUser.id, app: null, internal: false }) + .should.equal(true); permissableStub.restore(); done(); }); }); - it("can get effective user permissions", function (done) { + it('can get effective user permissions', function (done) { effectivePerms.user(1).then(function (effectivePermissions) { should.exist(effectivePermissions); @@ -349,9 +351,9 @@ describe('Permissions', function () { return UserProvider.findOne({id: 1}) .then(function (foundUser) { var newPerm = new Models.Permission({ - name: "app test edit post", - action_type: "edit", - object_type: "post" + name: 'app test edit post', + action_type: 'edit', + object_type: 'post' }); return newPerm.save(null, {user: 1}).then(function () { @@ -372,7 +374,8 @@ describe('Permissions', function () { return results; }) .catch(function (err) { - done(new Error("Did not allow user 1 to edit post 1")); + /*jshint unused:false */ + done(new Error('Did not allow user 1 to edit post 1')); }); }) .then(function (results) { @@ -384,7 +387,7 @@ describe('Permissions', function () { .edit .post(updatedPost.id) .then(function () { - done(new Error("Allowed an edit of post 1")); + done(new Error('Allowed an edit of post 1')); }).catch(done); }).catch(done); }); @@ -397,7 +400,7 @@ describe('Permissions', function () { done(); }) .catch(function () { - done(new Error("Allowed an edit of post 1")); + done(new Error('Allowed an edit of post 1')); }); }); @@ -406,7 +409,7 @@ describe('Permissions', function () { .edit .post(1) .then(function () { - done(new Error("Should not allow editing post")); + done(new Error('Should not allow editing post')); }) .catch(done); }); @@ -420,7 +423,7 @@ describe('Permissions', function () { done(); }) .catch(function () { - done(new Error("Should allow editing post with 'internal'")); + done(new Error('Should allow editing post with "internal"')); }); }); @@ -433,7 +436,7 @@ describe('Permissions', function () { done(); }) .catch(function () { - done(new Error("Should allow editing post with { internal: true }")); + done(new Error('Should allow editing post with { internal: true }')); }); }); }); diff --git a/core/test/unit/server_helpers_index_spec.js b/core/test/unit/server_helpers_index_spec.js index 80e668381c..fcafef1f42 100644 --- a/core/test/unit/server_helpers_index_spec.js +++ b/core/test/unit/server_helpers_index_spec.js @@ -1,10 +1,9 @@ -/*globals describe, beforeEach, afterEach, it*/ -var testUtils = require('../utils'), - should = require('should'), +/*globals describe, beforeEach, afterEach, before, after, it*/ +/*jshint expr:true*/ +var should = require('should'), sinon = require('sinon'), when = require('when'), _ = require('lodash'), - path = require('path'), rewire = require('rewire'), moment = require('moment'), Polyglot = require('node-polyglot'), @@ -33,7 +32,7 @@ describe('Core Helpers', function () { var adminHbs = hbs.create(); helpers = rewire('../../server/helpers'); sandbox = sinon.sandbox.create(); - apiStub = sandbox.stub(api.settings, 'read', function (arg) { + apiStub = sandbox.stub(api.settings, 'read', function () { return when({ settings: [{value: 'casper'}] }); @@ -81,7 +80,7 @@ describe('Core Helpers', function () { }); it('can render content', function () { - var html = "Hello World", + var html = 'Hello World', rendered = helpers.content.call({html: html}); should.exist(rendered); @@ -89,87 +88,88 @@ describe('Core Helpers', function () { }); it('can truncate html by word', function () { - var html = "

Hello World! It's me!

", + var html = '

Hello World! It\'s me!

', rendered = ( helpers.content .call( {html: html}, - {"hash": {"words": 2}} + {'hash': {'words': 2}} ) ); should.exist(rendered); - rendered.string.should.equal("

Hello World

"); + rendered.string.should.equal('

Hello World

'); }); it('can truncate html to 0 words', function () { - var html = "

Hello World! It's me!

", + var html = '

Hello World! It\'s me!

', rendered = ( helpers.content .call( {html: html}, - {"hash": {"words": "0"}} + {'hash': {'words': '0'}} ) ); should.exist(rendered); - rendered.string.should.equal("

"); + rendered.string.should.equal('

'); }); it('can truncate html to 0 words, leaving image tag if it is first', function () { - var html = "

Hello World! It's me!

", + var html = '

Hello World! It\'s me!

', rendered = ( helpers.content .call( {html: html}, - {"hash": {"words": "0"}} + {'hash': {'words': '0'}} ) ); should.exist(rendered); - rendered.string.should.equal("

"); + rendered.string.should.equal('

'); }); - it('can truncate html to 0 words, leaving image tag if it is first and if it has an alt text with a single quote in the string', function () { - var html = "

\"It'sHello World! It's me!

", + it('can truncate html to 0 words, leaving first image tag & if alt text has a single quote', function () { + var html = '

It\'s me!Hello World! It\'s me!

', rendered = ( helpers.content .call( { html: html }, - { "hash": { "words": "0" } } + { 'hash': { 'words': '0' } } ) ); should.exist(rendered); - rendered.string.should.equal("

\"It's

"); + rendered.string.should.equal('

It\'s me!

'); }); - it('can truncate html to 0 words, leaving image tag if it is first and if it has an alt text with a double quote in the string', function () { - var html = "

A double quote is \"Hello World! It's me!

", + it('can truncate html to 0 words, leaving first image tag & if alt text has a double quote', function () { + var html = '

A double quote is \'' + + 'Hello World! It\'s me!

', rendered = ( helpers.content .call( { html: html }, - { "hash": { "words": "0" } } + { 'hash': { 'words': '0' } } ) ); should.exist(rendered); - rendered.string.should.equal("

A double quote is \"

"); + rendered.string.should.equal('

A double quote is \'

'); }); it('can truncate html by character', function () { - var html = "

Hello World! It's me!

", + var html = '

Hello World! It\'s me!

', rendered = ( helpers.content .call( {html: html}, - {"hash": {"characters": 8}} + {'hash': {'characters': 8}} ) ); should.exist(rendered); - rendered.string.should.equal("

Hello Wo

"); + rendered.string.should.equal('

Hello Wo

'); }); }); @@ -179,18 +179,18 @@ describe('Core Helpers', function () { should.exist(handlebars.helpers.author); }); - it("Returns the full name of the author from the context", function () { - var data = {"author": {"name": "abc123"}}, + it('Returns the full name of the author from the context', function () { + var data = {'author': {'name': 'abc123'}}, result = helpers.author.call(data); - String(result).should.equal("abc123"); + String(result).should.equal('abc123'); }); - it("Returns a blank string where author data is missing", function () { - var data = {"author": null}, + it('Returns a blank string where author data is missing', function () { + var data = {'author': null}, result = helpers.author.call(data); - String(result).should.equal(""); + String(result).should.equal(''); }); }); @@ -202,8 +202,8 @@ describe('Core Helpers', function () { }); it('can escape URI', function () { - var uri = "$pecial!Charact3r(De[iver]y)Foo #Bar", - expected = "%24pecial!Charact3r(De%5Biver%5Dy)Foo%20%23Bar", + var uri = '$pecial!Charact3r(De[iver]y)Foo #Bar', + expected = '%24pecial!Charact3r(De%5Biver%5Dy)Foo%20%23Bar', escaped = handlebars.helpers.encode(uri); should.exist(escaped); @@ -218,7 +218,7 @@ describe('Core Helpers', function () { }); it('can render excerpt', function () { - var html = "Hello World", + var html = 'Hello World', rendered = helpers.excerpt.call({html: html}); should.exist(rendered); @@ -226,12 +226,12 @@ describe('Core Helpers', function () { }); it('does not output HTML', function () { - var html = '

There are
10
types
of people in the world:' - + '\"c\" those who ' - + "understand trinary

, those who don't
and" - + "< test > those<<< test >>> who mistake it <for> binary.", - expected = "There are 10 types of people in the world: those who understand trinary, those who don't " - + "and those>> who mistake it <for> binary.", + var html = '

There are
10
types
of people in the world:' + + 'c those who ' + + 'understand trinary

, those who don\'t
and' + + '< test > those<<< test >>> who mistake it <for> binary.', + expected = 'There are 10 types of people in the world: those who understand trinary, those who ' + + 'don\'t and those>> who mistake it <for> binary.', rendered = helpers.excerpt.call({html: html}); should.exist(rendered); @@ -240,12 +240,12 @@ describe('Core Helpers', function () { }); it('can truncate html by word', function () { - var html = "

Hello World! It's me!

", - expected = "Hello World", + var html = '

Hello World! It\'s me!

', + expected = 'Hello World', rendered = ( helpers.excerpt.call( {html: html}, - {"hash": {"words": "2"}} + {'hash': {'words': '2'}} ) ); @@ -254,12 +254,12 @@ describe('Core Helpers', function () { }); it('can truncate html with non-ascii characters by word', function () { - var html = "

Едквюэ опортэат праэчынт ючю но, квуй эю

", - expected = "Едквюэ опортэат", + var html = '

Едквюэ опортэат праэчынт ючю но, квуй эю

', + expected = 'Едквюэ опортэат', rendered = ( helpers.excerpt.call( {html: html}, - {"hash": {"words": "2"}} + {'hash': {'words': '2'}} ) ); @@ -268,12 +268,12 @@ describe('Core Helpers', function () { }); it('can truncate html by character', function () { - var html = "

Hello World! It's me!

", - expected = "Hello Wo", + var html = '

Hello World! It\'s me!

', + expected = 'Hello Wo', rendered = ( helpers.excerpt.call( {html: html}, - {"hash": {"characters": "8"}} + {'hash': {'characters': '8'}} ) ); @@ -404,7 +404,7 @@ describe('Core Helpers', function () { it('returns meta tag string', function (done) { configUpdate({url: 'http://testurl.com/'}); - helpers.ghost_head.call({version: "0.3.0"}).then(function (rendered) { + helpers.ghost_head.call({version: '0.3.0'}).then(function (rendered) { should.exist(rendered); rendered.string.should.equal('\n' + '\n' + @@ -416,7 +416,7 @@ describe('Core Helpers', function () { it('returns meta tag string even if version is invalid', function (done) { configUpdate({url: 'http://testurl.com/'}); - helpers.ghost_head.call({version: "0.9"}).then(function (rendered) { + helpers.ghost_head.call({version: '0.9'}).then(function (rendered) { should.exist(rendered); rendered.string.should.equal('\n' + '\n' + @@ -428,7 +428,7 @@ describe('Core Helpers', function () { it('returns correct rss url with subdirectory', function (done) { configUpdate({url: 'http://testurl.com/blog/'}); - helpers.ghost_head.call({version: "0.3.0"}).then(function (rendered) { + helpers.ghost_head.call({version: '0.3.0'}).then(function (rendered) { should.exist(rendered); rendered.string.should.equal('\n' + '\n' + @@ -440,7 +440,7 @@ describe('Core Helpers', function () { it('returns canonical URL', function (done) { configUpdate({url: 'http://testurl.com'}); - helpers.ghost_head.call({version: "0.3.0", relativeUrl: '/about/'}).then(function (rendered) { + helpers.ghost_head.call({version: '0.3.0', relativeUrl: '/about/'}).then(function (rendered) { should.exist(rendered); rendered.string.should.equal('\n' + '\n' + @@ -552,7 +552,9 @@ describe('Core Helpers', function () { }); it('should return the slug with a prefix slash if the context is a post', function (done) { - helpers.url.call({html: 'content', markdown: "ff", title: "title", slug: "slug", created_at: new Date(0)}).then(function (rendered) { + helpers.url.call({ + html: 'content', markdown: 'ff', title: 'title', slug: 'slug', created_at: new Date(0) + }).then(function (rendered) { should.exist(rendered); rendered.should.equal('/slug/'); done(); @@ -563,7 +565,7 @@ describe('Core Helpers', function () { configUpdate({ url: 'http://testurl.com/' }); helpers.url.call( - {html: 'content', markdown: "ff", title: "title", slug: "slug", created_at: new Date(0)}, + {html: 'content', markdown: 'ff', title: 'title', slug: 'slug', created_at: new Date(0)}, {hash: { absolute: 'true'}} ).then(function (rendered) { should.exist(rendered); @@ -573,7 +575,9 @@ describe('Core Helpers', function () { }); it('should return the slug with a prefixed /tag/ if the context is a tag', function (done) { - helpers.url.call({name: 'the tag', slug: "the-tag", description: null, parent_id: null}).then(function (rendered) { + helpers.url.call({ + name: 'the tag', slug: 'the-tag', description: null, parent_id: null + }).then(function (rendered) { should.exist(rendered); rendered.should.equal('/tag/the-tag/'); done(); @@ -600,7 +604,7 @@ describe('Core Helpers', function () { }).catch(done); }); }); - + describe('Page Url Helper', function () { it('has loaded page_url helper', function () { should.exist(handlebars.helpers.page_url); @@ -693,7 +697,7 @@ describe('Core Helpers', function () { }); }); - describe("Pagination helper", function () { + describe('Pagination helper', function () { var paginationRegex = /class="pagination"/, newerRegex = /class="newer-posts"/, olderRegex = /class="older-posts"/, @@ -707,7 +711,7 @@ describe('Core Helpers', function () { var runHelper = function (data) { return function () { helpers.pagination.call(data); - } + }; }; runHelper('not an object').should.throwError('pagination data is not an object or is a function'); @@ -715,7 +719,9 @@ describe('Core Helpers', function () { }); it('can render single page with no pagination necessary', function () { - var rendered = helpers.pagination.call({pagination: {page: 1, prev: null, next: null, limit: 15, total: 8, pages: 1}, tag: {slug: 'slug'}}); + var rendered = helpers.pagination.call({ + pagination: {page: 1, prev: null, next: null, limit: 15, total: 8, pages: 1}, tag: {slug: 'slug'} + }); should.exist(rendered); // strip out carriage returns and compare. rendered.string.should.match(paginationRegex); @@ -726,7 +732,9 @@ describe('Core Helpers', function () { }); it('can render first page of many with older posts link', function () { - var rendered = helpers.pagination.call({pagination: {page: 1, prev: null, next: 2, limit: 15, total: 8, pages: 3}}); + var rendered = helpers.pagination.call({ + pagination: {page: 1, prev: null, next: 2, limit: 15, total: 8, pages: 3} + }); should.exist(rendered); rendered.string.should.match(paginationRegex); @@ -737,7 +745,9 @@ describe('Core Helpers', function () { }); it('can render middle pages of many with older and newer posts link', function () { - var rendered = helpers.pagination.call({pagination: {page: 2, prev: 1, next: 3, limit: 15, total: 8, pages: 3}}); + var rendered = helpers.pagination.call({ + pagination: {page: 2, prev: 1, next: 3, limit: 15, total: 8, pages: 3} + }); should.exist(rendered); rendered.string.should.match(paginationRegex); @@ -748,7 +758,9 @@ describe('Core Helpers', function () { }); it('can render last page of many with newer posts link', function () { - var rendered = helpers.pagination.call({pagination: {page: 3, prev: 2, next: null, limit: 15, total: 8, pages: 3}}); + var rendered = helpers.pagination.call({ + pagination: {page: 3, prev: 2, next: null, limit: 15, total: 8, pages: 3} + }); should.exist(rendered); rendered.string.should.match(paginationRegex); @@ -791,7 +803,7 @@ describe('Core Helpers', function () { }); }); - describe("tags helper", function () { + describe('tags helper', function () { it('has loaded tags helper', function () { should.exist(handlebars.helpers.tags); @@ -801,7 +813,7 @@ describe('Core Helpers', function () { var tags = [{name: 'foo'}, {name: 'bar'}], rendered = handlebars.helpers.tags.call( {tags: tags}, - {"hash": {autolink: 'false'}} + {'hash': {autolink: 'false'}} ); should.exist(rendered); @@ -812,7 +824,7 @@ describe('Core Helpers', function () { var tags = [{name: 'haunted'}, {name: 'ghost'}], rendered = handlebars.helpers.tags.call( {tags: tags}, - {"hash": {separator: '|', autolink: 'false'}} + {'hash': {separator: '|', autolink: 'false'}} ); should.exist(rendered); @@ -824,7 +836,7 @@ describe('Core Helpers', function () { var tags = [{name: 'haunted'}, {name: 'ghost'}], rendered = handlebars.helpers.tags.call( {tags: tags}, - {"hash": {prefix: 'on ', autolink: 'false'}} + {'hash': {prefix: 'on ', autolink: 'false'}} ); should.exist(rendered); @@ -836,7 +848,7 @@ describe('Core Helpers', function () { var tags = [{name: 'haunted'}, {name: 'ghost'}], rendered = handlebars.helpers.tags.call( {tags: tags}, - {"hash": {suffix: ' forever', autolink: 'false'}} + {'hash': {suffix: ' forever', autolink: 'false'}} ); should.exist(rendered); @@ -848,7 +860,7 @@ describe('Core Helpers', function () { var tags = [{name: 'haunted'}, {name: 'ghost'}], rendered = handlebars.helpers.tags.call( {tags: tags}, - {"hash": {suffix: ' forever', prefix: 'on ', autolink: 'false'}} + {'hash': {suffix: ' forever', prefix: 'on ', autolink: 'false'}} ); should.exist(rendered); @@ -860,7 +872,7 @@ describe('Core Helpers', function () { var tags = [{name: 'haunted'}, {name: 'ghost'}], rendered = handlebars.helpers.tags.call( {tags: tags}, - {"hash": {suffix: ' •', prefix: '… ', autolink: 'false'}} + {'hash': {suffix: ' •', prefix: '… ', autolink: 'false'}} ); should.exist(rendered); @@ -871,7 +883,7 @@ describe('Core Helpers', function () { it('does not add prefix or suffix if no tags exist', function () { var rendered = handlebars.helpers.tags.call( {}, - {"hash": {prefix: 'on ', suffix: ' forever', autolink: 'false'}} + {'hash': {prefix: 'on ', suffix: ' forever', autolink: 'false'}} ); should.exist(rendered); @@ -883,7 +895,7 @@ describe('Core Helpers', function () { var tags = [{name: 'foo', slug: 'foo-bar'}, {name: 'bar', slug: 'bar'}], rendered = handlebars.helpers.tags.call( {tags: tags}, - {"hash": {}} + {'hash': {}} ); should.exist(rendered); @@ -891,7 +903,7 @@ describe('Core Helpers', function () { }); }); - describe("meta_title helper", function () { + describe('meta_title helper', function () { it('has loaded meta_title helper', function () { should.exist(handlebars.helpers.meta_title); @@ -915,7 +927,7 @@ describe('Core Helpers', function () { done(); }).then(null, done); }); - + it('can return escaped title of a post', function (done) { var post = {relativeUrl: '/nice-escaped-post', post: {title: 'Post Title "'}}; helpers.meta_title.call(post).then(function (rendered) { @@ -937,7 +949,7 @@ describe('Core Helpers', function () { }); }); - describe("meta_description helper", function () { + describe('meta_description helper', function () { it('has loaded meta_description helper', function () { should.exist(handlebars.helpers.meta_description); @@ -951,7 +963,7 @@ describe('Core Helpers', function () { done(); }).catch(done); }); - + it('can return empty description on post', function (done) { var post = {relativeUrl: '/nice-post', post: {title: 'Post Title'}}; helpers.meta_description.call(post).then(function (rendered) { @@ -964,7 +976,7 @@ describe('Core Helpers', function () { }); - describe("asset helper", function () { + describe('asset helper', function () { var rendered, configOriginal; @@ -985,9 +997,9 @@ describe('Core Helpers', function () { should.exist(handlebars.helpers.asset); }); - it("handles favicon correctly", function () { + it('handles favicon correctly', function () { // with ghost set - rendered = helpers.asset('favicon.ico', {"hash": {ghost: 'true'}}); + rendered = helpers.asset('favicon.ico', {'hash': {ghost: 'true'}}); should.exist(rendered); String(rendered).should.equal('/favicon.ico'); @@ -1001,7 +1013,7 @@ describe('Core Helpers', function () { }); // with subdirectory - rendered = helpers.asset('favicon.ico', {"hash": {ghost: 'true'}}); + rendered = helpers.asset('favicon.ico', {'hash': {ghost: 'true'}}); should.exist(rendered); String(rendered).should.equal('/blog/favicon.ico'); @@ -1013,7 +1025,7 @@ describe('Core Helpers', function () { it('handles shared assets correctly', function () { // with ghost set - rendered = helpers.asset('shared/asset.js', {"hash": {ghost: 'true'}}); + rendered = helpers.asset('shared/asset.js', {'hash': {ghost: 'true'}}); should.exist(rendered); String(rendered).should.equal('/shared/asset.js?v=abc'); @@ -1027,7 +1039,7 @@ describe('Core Helpers', function () { }); // with subdirectory - rendered = helpers.asset('shared/asset.js', {"hash": {ghost: 'true'}}); + rendered = helpers.asset('shared/asset.js', {'hash': {ghost: 'true'}}); should.exist(rendered); String(rendered).should.equal('/blog/shared/asset.js?v=abc'); @@ -1039,7 +1051,7 @@ describe('Core Helpers', function () { it('handles admin assets correctly', function () { // with ghost set - rendered = helpers.asset('js/asset.js', {"hash": {ghost: 'true'}}); + rendered = helpers.asset('js/asset.js', {'hash': {ghost: 'true'}}); should.exist(rendered); String(rendered).should.equal('/ghost/js/asset.js?v=abc'); @@ -1048,7 +1060,7 @@ describe('Core Helpers', function () { }); // with subdirectory - rendered = helpers.asset('js/asset.js', {"hash": {ghost: 'true'}}); + rendered = helpers.asset('js/asset.js', {'hash': {ghost: 'true'}}); should.exist(rendered); String(rendered).should.equal('/blog/ghost/js/asset.js?v=abc'); }); @@ -1081,7 +1093,7 @@ describe('Core Helpers', function () { // to test the output of the helper against static strings instead // of calling moment(). Without timezone support the output of this // helper may differ depending on what timezone the tests are run in. - + it('creates properly formatted date strings', function () { var testDates = [ '2013-12-31T11:28:58.593Z', @@ -1205,7 +1217,7 @@ describe('Core Helpers', function () { context = 'hello world this is ghost'.split(' '); rendered = helpers.foreach.call(_this, context, options); - rendered.should.equal('hello\n\world\nthis\nis\nghost\n'); + rendered.should.equal('hello\nworld\nthis\nis\nghost\n'); // test with context as an object @@ -1218,7 +1230,7 @@ describe('Core Helpers', function () { }; rendered = helpers.foreach.call(_this, context, options); - rendered.should.equal('hello\n\world\nthis\nis\nghost\n'); + rendered.should.equal('hello\nworld\nthis\nis\nghost\n'); }); it('should return the correct result when private data is supplied', function () { @@ -1249,7 +1261,7 @@ describe('Core Helpers', function () { result[4].should.equal('ghost,false,false,false,true,false,true'); }); - it('should return the correct result when private data is supplied and there are multiple columns', function () { + it('should return the correct result when private data is supplied & there are multiple columns', function () { var options = {}, context = [], _this = {}, @@ -1327,7 +1339,7 @@ describe('Core Helpers', function () { var args = arguments; return function () { helperMissing.apply(null, args); - } + }; } runHelper('test helper').should.not.throwError(); @@ -1336,7 +1348,7 @@ describe('Core Helpers', function () { }); // ## Admin only helpers - describe("ghostScriptTags helper", function () { + describe('ghostScriptTags helper', function () { var rendered, configOriginal; @@ -1431,26 +1443,26 @@ describe('Core Helpers', function () { // no trailing slash configUpdate({url: 'http://testurl.com'}); - rendered = helpers.admin_url({"hash": {absolute: true}}); + rendered = helpers.admin_url({'hash': {absolute: true}}); should.exist(rendered); rendered.should.equal('http://testurl.com/ghost'); // test trailing slash configUpdate({url: 'http://testurl.com/'}); - rendered = helpers.admin_url({"hash": {absolute: true}}); + rendered = helpers.admin_url({'hash': {absolute: true}}); should.exist(rendered); rendered.should.equal('http://testurl.com/ghost'); }); it('should output absolute path with subdirectory', function () { configUpdate({url: 'http://testurl.com/blog'}); - rendered = helpers.admin_url({"hash": {absolute: true}}); + rendered = helpers.admin_url({'hash': {absolute: true}}); should.exist(rendered); rendered.should.equal('http://testurl.com/blog/ghost'); }); it('should output the path to frontend if frontend is set', function () { - rendered = helpers.admin_url({"hash": {frontend: true}}); + rendered = helpers.admin_url({'hash': {frontend: true}}); should.exist(rendered); rendered.should.equal('/'); }); @@ -1458,32 +1470,32 @@ describe('Core Helpers', function () { it('should output the absolute path to frontend if both are set', function () { configUpdate({url: 'http://testurl.com'}); - rendered = helpers.admin_url({"hash": {frontend: true, absolute: true}}); + rendered = helpers.admin_url({'hash': {frontend: true, absolute: true}}); should.exist(rendered); rendered.should.equal('http://testurl.com/'); configUpdate({url: 'http://testurl.com/'}); - rendered = helpers.admin_url({"hash": {frontend: true, absolute: true}}); + rendered = helpers.admin_url({'hash': {frontend: true, absolute: true}}); should.exist(rendered); rendered.should.equal('http://testurl.com/'); }); it('should output the path to frontend with subdirectory', function () { configUpdate({url: 'http://testurl.com/blog/'}); - rendered = helpers.admin_url({"hash": {frontend: true}}); + rendered = helpers.admin_url({'hash': {frontend: true}}); should.exist(rendered); rendered.should.equal('/blog/'); }); it('should output the absolute path to frontend with subdirectory', function () { configUpdate({url: 'http://testurl.com/blog/'}); - rendered = helpers.admin_url({"hash": {frontend: true, absolute: true}}); + rendered = helpers.admin_url({'hash': {frontend: true, absolute: true}}); should.exist(rendered); rendered.should.equal('http://testurl.com/blog/'); }); }); describe('updateNotification', function () { - it('outputs a correctly formatted notification when db version is higher than package version', function (done) { + it('outputs a correctly formatted notification when db version is higher than pkg version', function (done) { var defaultOutput = '
' + 'A new version of Ghost is available! Hot damn. ' + 'Upgrade now
', @@ -1514,7 +1526,7 @@ describe('Core Helpers', function () { }).catch(done); }); - it('does NOT output a correctly formatted notification when db version equals package version', function (done) { + it('does NOT output a correctly formatted notification when db version equals pkg version', function (done) { apiStub.restore(); apiStub = sandbox.stub(api.settings, 'read', function () { return when({ settings: [{value: packageInfo.version}] }); @@ -1581,7 +1593,7 @@ describe('Core Helpers', function () { }); _.extend(cfg, configStub); - + helpers.__set__('config', cfg); fileStorage = helpers.file_storage(); @@ -1614,7 +1626,7 @@ describe('Core Helpers', function () { }); _.extend(cfg, configStub); - + helpers.__set__('config', cfg); apps = helpers.apps(); diff --git a/core/test/unit/server_helpers_template_spec.js b/core/test/unit/server_helpers_template_spec.js index fddc5cf5c5..cc2a11056b 100644 --- a/core/test/unit/server_helpers_template_spec.js +++ b/core/test/unit/server_helpers_template_spec.js @@ -1,20 +1,14 @@ -/*globals describe, beforeEach, it*/ -var testUtils = require('../utils'), - should = require('should'), - sinon = require('sinon'), - when = require('when'), - _ = require('lodash'), - path = require('path'), +/*globals describe, it*/ +/*jshint expr:true*/ +var should = require('should'), hbs = require('express-hbs'), // Stuff we are testing - config = require('../../server/config'), - api = require('../../server/api'), template = require('../../server/helpers/template'); describe('Helpers Template', function () { - it("can execute a template", function () { + it('can execute a template', function () { hbs.registerPartial('test', '

Hello {{name}}

'); var safeString = template.execute('test', {name: 'world'}); diff --git a/core/test/unit/server_spec.js b/core/test/unit/server_spec.js index a348e3f102..20bca1ce1a 100644 --- a/core/test/unit/server_spec.js +++ b/core/test/unit/server_spec.js @@ -1,9 +1,7 @@ -/*globals describe, beforeEach, it*/ -var net = require('net'), - assert = require('assert'), - should = require('should'), +/*globals describe, it*/ +/*jshint expr:true*/ +var should = require('should'), request = require('request'), - server = require('../../server'), config = require('../../../config'); describe('Server', function () { @@ -14,10 +12,10 @@ describe('Server', function () { it('should not start a connect server when required', function (done) { request(url, function (error, response, body) { - assert.equal(response, undefined); - assert.equal(body, undefined); - assert.notEqual(error, undefined); - assert.equal(error.code, 'ECONNREFUSED'); + should(response).equal(undefined); + should(body).equal(undefined); + should(error).not.equal(undefined); + should(error.code).equal('ECONNREFUSED'); done(); }); }); diff --git a/core/test/unit/showdown_client_integrated_spec.js b/core/test/unit/showdown_client_integrated_spec.js index 0f4cefeab4..bd08c18f30 100644 --- a/core/test/unit/showdown_client_integrated_spec.js +++ b/core/test/unit/showdown_client_integrated_spec.js @@ -5,8 +5,8 @@ */ /*globals describe, it */ -var testUtils = require('../utils'), - should = require('should'), +/*jshint expr:true*/ +var should = require('should'), // Stuff we are testing Showdown = require('showdown'), @@ -15,43 +15,46 @@ var testUtils = require('../utils'), converter = new Showdown.converter({extensions: [ghostimagepreview, ghostgfm]}); -describe("Showdown client side converter", function () { +// To stop jshint complaining +should.equal(true, true); + +describe('Showdown client side converter', function () { /*jslint regexp: true */ - it("should replace showdown strike through with html", function () { - var testPhrase = {input: "~~foo_bar~~", output: /^

foo_bar<\/del><\/p>$/}, + it('should replace showdown strike through with html', function () { + var testPhrase = {input: '~~foo_bar~~', output: /^

foo_bar<\/del><\/p>$/}, processedMarkup = converter.makeHtml(testPhrase.input); // The image is the entire markup, so the image box should be too processedMarkup.should.match(testPhrase.output); }); - it("should not touch single underscores inside words", function () { - var testPhrase = {input: "foo_bar", output: /^

foo_bar<\/p>$/}, + it('should not touch single underscores inside words', function () { + var testPhrase = {input: 'foo_bar', output: /^

foo_bar<\/p>$/}, processedMarkup = converter.makeHtml(testPhrase.input); processedMarkup.should.match(testPhrase.output); }); // Currently failing - fixing this causes other issues -// it("should not create italic words between lines", function () { -// var testPhrase = {input: "foo_bar\nbar_foo", output: /^

foo_bar
\nbar_foo<\/p>$/}, +// it('should not create italic words between lines', function () { +// var testPhrase = {input: 'foo_bar\nbar_foo', output: /^

foo_bar
\nbar_foo<\/p>$/}, // processedMarkup = converter.makeHtml(testPhrase.input); // // processedMarkup.should.match(testPhrase.output); // }); - it("should not touch underscores in code blocks", function () { - var testPhrase = {input: " foo_bar_baz", output: /^

foo_bar_baz\n<\/code><\/pre>$/},
+    it('should not touch underscores in code blocks', function () {
+        var testPhrase = {input: '    foo_bar_baz', output: /^
foo_bar_baz\n<\/code><\/pre>$/},
             processedMarkup = converter.makeHtml(testPhrase.input);
 
         processedMarkup.should.match(testPhrase.output);
     });
 
-    it("should not touch underscores in pre blocks", function () {
+    it('should not touch underscores in pre blocks', function () {
         var testPhrases = [
-                {input: "
\nfoo_bar_baz\n
", output: /^
\nfoo_bar_baz\n<\/pre>$/},
-                {input: "
foo_bar_baz
", output: /^
foo_bar_baz<\/pre>$/}
+                {input: '
\nfoo_bar_baz\n
', output: /^
\nfoo_bar_baz\n<\/pre>$/},
+                {input: '
foo_bar_baz
', output: /^
foo_bar_baz<\/pre>$/}
             ],
             processedMarkup;
 
@@ -61,9 +64,9 @@ describe("Showdown client side converter", function () {
         });
     });
 
-    it("should not escape double underscores at the beginning of a line", function () {
+    it('should not escape double underscores at the beginning of a line', function () {
         var testPhrases = [
-                {input: "\n__test__\n", output: /^

test<\/strong><\/p>$/} + {input: '\n__test__\n', output: /^

test<\/strong><\/p>$/} ], processedMarkup; @@ -73,10 +76,35 @@ describe("Showdown client side converter", function () { }); }); - it("should not treat pre blocks with pre-text differently", function () { + it('should not treat pre blocks with pre-text differently', function () { var testPhrases = [ - {input: "

\nthis is `a\\_test` and this\\_too and finally_this_is\n
", output: /^
\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>$/},
-                {input: "hmm
\nthis is `a\\_test` and this\\_too and finally_this_is\n
", output: /^

hmm<\/p>\n\n

\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>$/}
+            {
+                input: '
\nthis is `a\\_test` and this\\_too and finally_this_is\n
', + output: /^
\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>$/
+            },
+            {
+                input: 'hmm
\nthis is `a\\_test` and this\\_too and finally_this_is\n
', + output: /^

hmm<\/p>\n\n

\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>$/
+            }
+        ],
+        processedMarkup;
+
+        testPhrases.forEach(function (testPhrase) {
+            processedMarkup = converter.makeHtml(testPhrase.input);
+            processedMarkup.should.match(testPhrase.output);
+        });
+    });
+
+    it('should escape two or more underscores inside words', function () {
+        var testPhrases = [
+                {input: 'foo_bar_baz', output: /^

foo_bar_baz<\/p>$/}, + {input: 'foo_bar_baz_bat', output: /^

foo_bar_baz_bat<\/p>$/}, + {input: 'foo_bar_baz_bat_boo', output: /^

foo_bar_baz_bat_boo<\/p>$/}, + {input: 'FOO_BAR', output: /^

FOO_BAR<\/p>$/}, + {input: 'FOO_BAR_BAZ', output: /^

FOO_BAR_BAZ<\/p>$/}, + {input: 'FOO_bar_BAZ_bat', output: /^

FOO_bar_BAZ_bat<\/p>$/}, + {input: 'FOO_bar_BAZ_bat_BOO', output: /^

FOO_bar_BAZ_bat_BOO<\/p>$/}, + {input: 'foo_BAR_baz_BAT_boo', output: /^

foo_BAR_baz_BAT_boo<\/p>$/} ], processedMarkup; @@ -86,16 +114,12 @@ describe("Showdown client side converter", function () { }); }); - it("should escape two or more underscores inside words", function () { + it('should turn newlines into br tags in simple cases', function () { var testPhrases = [ - {input: "foo_bar_baz", output: /^

foo_bar_baz<\/p>$/}, - {input: "foo_bar_baz_bat", output: /^

foo_bar_baz_bat<\/p>$/}, - {input: "foo_bar_baz_bat_boo", output: /^

foo_bar_baz_bat_boo<\/p>$/}, - {input: "FOO_BAR", output: /^

FOO_BAR<\/p>$/}, - {input: "FOO_BAR_BAZ", output: /^

FOO_BAR_BAZ<\/p>$/}, - {input: "FOO_bar_BAZ_bat", output: /^

FOO_bar_BAZ_bat<\/p>$/}, - {input: "FOO_bar_BAZ_bat_BOO", output: /^

FOO_bar_BAZ_bat_BOO<\/p>$/}, - {input: "foo_BAR_baz_BAT_boo", output: /^

foo_BAR_baz_BAT_boo<\/p>$/} + {input: 'fizz\nbuzz', output: /^

fizz
\nbuzz<\/p>$/}, + {input: 'Hello world\nIt is a fine day', output: /^

Hello world
\nIt is a fine day<\/p>$/}, + {input: '\'first\nsecond', output: /^

\'first
\nsecond<\/p>$/}, + {input: '\'first\nsecond', output: /^

\'first
\nsecond<\/p>$/} ], processedMarkup; @@ -105,14 +129,18 @@ describe("Showdown client side converter", function () { }); }); - it("should turn newlines into br tags in simple cases", function () { + it('should convert newlines in all groups', function () { var testPhrases = [ - {input: "fizz\nbuzz", output: /^

fizz
\nbuzz<\/p>$/}, - {input: "Hello world\nIt is a fine day", output: /^

Hello world
\nIt is a fine day<\/p>$/}, - {input: "\"first\nsecond", output: /^

\"first
\nsecond<\/p>$/}, - {input: "\'first\nsecond", output: /^

\'first
\nsecond<\/p>$/} - ], - processedMarkup; + { + input: 'ruby\npython\nerlang', + output: /^

ruby
\npython
\nerlang<\/p>$/ + }, + { + input: 'Hello world\nIt is a fine day\nout', + output: /^

Hello world
\nIt is a fine day
\nout<\/p>$/ + } + ], + processedMarkup; testPhrases.forEach(function (testPhrase) { processedMarkup = converter.makeHtml(testPhrase.input); @@ -120,27 +148,14 @@ describe("Showdown client side converter", function () { }); }); - it("should convert newlines in all groups", function () { - var testPhrases = [ - {input: "ruby\npython\nerlang", output: /^

ruby
\npython
\nerlang<\/p>$/}, - {input: "Hello world\nIt is a fine day\nout", output: /^

Hello world
\nIt is a fine day
\nout<\/p>$/} - ], - processedMarkup; - - testPhrases.forEach(function (testPhrase) { - processedMarkup = converter.makeHtml(testPhrase.input); - processedMarkup.should.match(testPhrase.output); - }); - }); - - it("should convert newlines in even long groups", function () { + it('should convert newlines in even long groups', function () { var testPhrases = [ { - input: "ruby\npython\nerlang\ngo", + input: 'ruby\npython\nerlang\ngo', output: /^

ruby
\npython
\nerlang
\ngo<\/p>$/ }, { - input: "Hello world\nIt is a fine day\noutside\nthe window", + input: 'Hello world\nIt is a fine day\noutside\nthe window', output: /^

Hello world
\nIt is a fine day
\noutside
\nthe window<\/p>$/ } ], @@ -152,14 +167,14 @@ describe("Showdown client side converter", function () { }); }); - it("should not convert newlines in lists", function () { + it('should not convert newlines in lists', function () { var testPhrases = [ { - input: "#fizz\n# buzz\n### baz", + input: '#fizz\n# buzz\n### baz', output: /^

fizz<\/h1>\n\n

buzz<\/h1>\n\n

baz<\/h3>$/ }, { - input: "* foo\n* bar", + input: '* foo\n* bar', output: /^