Ghost/test/unit/adapters/scheduling/utils_spec.js
Hannah Wolfe 22e13acd65 Updated var declarations to const/let and no lists
- All var declarations are now const or let as per ES6
- All comma-separated lists / chained declarations are now one declaration per line
- This is for clarity/readability but also made running the var-to-const/let switch smoother
- ESLint rules updated to match

How this was done:

- npm install -g jscodeshift
- git clone https://github.com/cpojer/js-codemod.git
- git clone git@github.com:TryGhost/Ghost.git shallow-ghost
- cd shallow-ghost
- jscodeshift -t ../js-codemod/transforms/unchain-variables.js . -v=2
- jscodeshift -t ../js-codemod/transforms/no-vars.js . -v=2
- yarn
- yarn test
- yarn lint / fix various lint errors (almost all indent) by opening files and saving in vscode
- grunt test-regression
- sorted!
2020-04-29 16:51:13 +01:00

89 lines
3.2 KiB
JavaScript

const should = require('should');
const fs = require('fs-extra');
const configUtils = require('../../../utils/configUtils');
const config = require('../../../../core/server/config');
const schedulingUtils = require('../../../../core/server/adapters/scheduling/utils');
const schedulingPath = configUtils.config.getContentPath('adapters') + 'scheduling/';
describe('Scheduling: utils', function () {
const scope = {adapter: null};
before(function () {
if (!fs.existsSync(schedulingPath)) {
fs.mkdirSync(schedulingPath);
}
});
afterEach(function () {
if (scope.adapter) {
fs.unlinkSync(scope.adapter);
scope.adapter = null;
}
configUtils.restore();
});
describe('success', function () {
it('create good adapter', function (done) {
schedulingUtils.createAdapter().then(function (adapter) {
should.exist(adapter);
done();
}).catch(done);
});
it('create good adapter', function (done) {
scope.adapter = schedulingPath + 'another-scheduler.js';
configUtils.set({
scheduling: {
active: 'another-scheduler'
}
});
const jsFile = '' +
'var util = require(\'util\');' +
'var SchedulingBase = require(\'../../../core/server/adapters/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(scope.adapter, jsFile);
schedulingUtils.createAdapter().then(function (adapter) {
should.exist(adapter);
done();
}).catch(done);
});
});
describe('error', function () {
it('create with adapter, but missing fn\'s', function (done) {
scope.adapter = schedulingPath + 'bad-adapter.js';
const jsFile = '' +
'var util = require(\'util\');' +
'var SchedulingBase = require(\'../../../core/server/adapters/scheduling/SchedulingBase\');' +
'var BadAdapter = function (){ SchedulingBase.call(this); };' +
'util.inherits(BadAdapter, SchedulingBase);' +
'BadAdapter.prototype.schedule = function (){};' +
'module.exports = BadAdapter';
fs.writeFileSync(scope.adapter, jsFile);
configUtils.set({
scheduling: {
active: 'bad-adapter'
}
});
schedulingUtils.createAdapter().catch(function (err) {
should.exist(err);
should.equal(err.errorType, 'IncorrectUsageError');
done();
});
});
});
});