mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 16:42:17 +03:00
d81bc91bd2
refs #7116, refs #2001 - Changes the way Ghost errors are implemented to benefit from proper inheritance - Moves all error definitions into a single file - Changes the error constructor to take an options object, rather than needing the arguments to be passed in the correct order. - Provides a wrapper so that any errors that haven't already been converted to GhostErrors get converted before they are displayed. Summary of changes: * 🐛 set NODE_ENV in config handler * ✨ add GhostError implementation (core/server/errors.js) - register all errors in one file - inheritance from GhostError - option pattern * 🔥 remove all error files * ✨ wrap all errors into GhostError in case of HTTP * 🎨 adaptions - option pattern for errors - use GhostError when needed * 🎨 revert debug deletion and add TODO for error id's
86 lines
3.4 KiB
JavaScript
86 lines
3.4 KiB
JavaScript
|
|
var should = require('should'),
|
|
fs = require('fs'),
|
|
config = require(__dirname + '/../../../server/config'),
|
|
errors = require(config.get('paths').corePath + '/server/errors'),
|
|
schedulingUtils = require(config.get('paths').corePath + '/server/scheduling/utils');
|
|
|
|
describe('Scheduling: utils', function () {
|
|
describe('success', function () {
|
|
it('create good adapter', function (done) {
|
|
schedulingUtils.createAdapter({
|
|
active: __dirname + '/../../../server/scheduling/SchedulingDefault'
|
|
}).then(function (adapter) {
|
|
should.exist(adapter);
|
|
done();
|
|
}).catch(done);
|
|
});
|
|
|
|
it('create good adapter', function (done) {
|
|
var jsFile = '' +
|
|
'var util = require(\'util\');' +
|
|
'var SchedulingBase = require(__dirname + \'/../../../server/scheduling/SchedulingBase\');' +
|
|
'var AnotherAdapter = function (){ SchedulingBase.call(this); };' +
|
|
'util.inherits(AnotherAdapter, SchedulingBase);' +
|
|
'AnotherAdapter.prototype.run = function (){};' +
|
|
'AnotherAdapter.prototype.schedule = function (){};' +
|
|
'AnotherAdapter.prototype.reschedule = function (){};' +
|
|
'AnotherAdapter.prototype.unschedule = function (){};' +
|
|
'module.exports = AnotherAdapter';
|
|
|
|
fs.writeFileSync(__dirname + '/another-scheduler.js', jsFile);
|
|
|
|
schedulingUtils.createAdapter({
|
|
active: 'another-scheduler',
|
|
contentPath: __dirname + '/'
|
|
}).then(function (adapter) {
|
|
should.exist(adapter);
|
|
done();
|
|
}).finally(function () {
|
|
fs.unlinkSync(__dirname + '/another-scheduler.js');
|
|
}).catch(done);
|
|
});
|
|
});
|
|
|
|
describe('error', function () {
|
|
it('create without adapter path', function (done) {
|
|
schedulingUtils.createAdapter()
|
|
.catch(function (err) {
|
|
should.exist(err);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('create with unknown adapter', function (done) {
|
|
schedulingUtils.createAdapter({
|
|
active: '/follow/the/heart'
|
|
}).catch(function (err) {
|
|
should.exist(err);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('create with adapter, but missing fn\'s', function (done) {
|
|
var jsFile = '' +
|
|
'var util = require(\'util\');' +
|
|
'var SchedulingBase = require(__dirname + \'/../../../server/scheduling/SchedulingBase\');' +
|
|
'var BadAdapter = function (){ SchedulingBase.call(this); };' +
|
|
'util.inherits(BadAdapter, SchedulingBase);' +
|
|
'BadAdapter.prototype.schedule = function (){};' +
|
|
'module.exports = BadAdapter';
|
|
|
|
fs.writeFileSync(__dirname + '/bad-adapter.js', jsFile);
|
|
|
|
schedulingUtils.createAdapter({
|
|
active: __dirname + '/bad-adapter'
|
|
}).catch(function (err) {
|
|
should.exist(err);
|
|
(err instanceof errors.IncorrectUsageError).should.eql(true);
|
|
done();
|
|
}).finally(function () {
|
|
fs.unlinkSync(__dirname + '/bad-adapter.js');
|
|
});
|
|
});
|
|
});
|
|
});
|