mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Removed bluebird dependency from unit tests in core (#16096)
refs https://github.com/TryGhost/Ghost/issues/14882 - Replaced `new Promise.reject()` / `new Promise.resolve()` with the static methods `Promise.reject` / `Promise/resolve` from native promises - Replaced `Promise.delay()` with a promisified `setTimeout()`
This commit is contained in:
parent
42b30ac613
commit
bba4743739
@ -2,7 +2,6 @@ const errors = require('@tryghost/errors');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const validators = require('../../../../../../../core/server/api/endpoints/utils/validators');
|
const validators = require('../../../../../../../core/server/api/endpoints/utils/validators');
|
||||||
const models = require('../../../../../../../core/server/models');
|
const models = require('../../../../../../../core/server/models');
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ const errors = require('@tryghost/errors');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const validators = require('../../../../../../../core/server/api/endpoints/utils/validators');
|
const validators = require('../../../../../../../core/server/api/endpoints/utils/validators');
|
||||||
const models = require('../../../../../../../core/server/models');
|
const models = require('../../../../../../../core/server/models');
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ const errors = require('@tryghost/errors');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const validators = require('../../../../../../../core/server/api/endpoints/utils/validators');
|
const validators = require('../../../../../../../core/server/api/endpoints/utils/validators');
|
||||||
|
|
||||||
describe('Unit: endpoints/utils/validators/input/tags', function () {
|
describe('Unit: endpoints/utils/validators/input/tags', function () {
|
||||||
|
@ -2,7 +2,6 @@ const errors = require('@tryghost/errors');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const validators = require('../../../../../../../core/server/api/endpoints/utils/validators');
|
const validators = require('../../../../../../../core/server/api/endpoints/utils/validators');
|
||||||
|
|
||||||
describe('Unit: endpoints/utils/validators/input/webhooks', function () {
|
describe('Unit: endpoints/utils/validators/input/webhooks', function () {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const {SafeString} = require('../../../../core/frontend/services/handlebars');
|
const {SafeString} = require('../../../../core/frontend/services/handlebars');
|
||||||
const configUtils = require('../../../utils/configUtils');
|
const configUtils = require('../../../utils/configUtils');
|
||||||
const logging = require('@tryghost/logging');
|
const logging = require('@tryghost/logging');
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const markdownToMobiledoc = require('../../../utils/fixtures/data-generator').markdownToMobiledoc;
|
const markdownToMobiledoc = require('../../../utils/fixtures/data-generator').markdownToMobiledoc;
|
||||||
const next_post = require('../../../../core/frontend/helpers/prev_post');
|
const next_post = require('../../../../core/frontend/helpers/prev_post');
|
||||||
const api = require('../../../../core/frontend/services/proxy').api;
|
const api = require('../../../../core/frontend/services/proxy').api;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const markdownToMobiledoc = require('../../../utils/fixtures/data-generator').markdownToMobiledoc;
|
const markdownToMobiledoc = require('../../../utils/fixtures/data-generator').markdownToMobiledoc;
|
||||||
const prev_post = require('../../../../core/frontend/helpers/prev_post');
|
const prev_post = require('../../../../core/frontend/helpers/prev_post');
|
||||||
const api = require('../../../../core/frontend/services/proxy').api;
|
const api = require('../../../../core/frontend/services/proxy').api;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const testUtils = require('../../../utils');
|
const testUtils = require('../../../utils');
|
||||||
|
|
||||||
const configUtils = require('../../../utils/configUtils');
|
const configUtils = require('../../../utils/configUtils');
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const testUtils = require('../../../../../utils');
|
const testUtils = require('../../../../../utils');
|
||||||
const configUtils = require('../../../../../utils/configUtils');
|
const configUtils = require('../../../../../utils/configUtils');
|
||||||
const api = require('../../../../../../core/frontend/services/proxy').api;
|
const api = require('../../../../../../core/frontend/services/proxy').api;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const rssCache = require('../../../../../core/frontend/services/rss/cache');
|
const rssCache = require('../../../../../core/frontend/services/rss/cache');
|
||||||
const renderer = require('../../../../../core/frontend/services/rss/renderer');
|
const renderer = require('../../../../../core/frontend/services/rss/renderer');
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ describe('RSS: Renderer', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('calls the cache and attempts to render, even without data', function (done) {
|
it('calls the cache and attempts to render, even without data', function (done) {
|
||||||
rssCacheStub.returns(new Promise.resolve('dummyxml'));
|
rssCacheStub.returns(Promise.resolve('dummyxml'));
|
||||||
|
|
||||||
renderer.render(res, baseUrl).then(function () {
|
renderer.render(res, baseUrl).then(function () {
|
||||||
rssCacheStub.calledOnce.should.be.true();
|
rssCacheStub.calledOnce.should.be.true();
|
||||||
@ -43,7 +42,7 @@ describe('RSS: Renderer', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('correctly merges locals into empty data before rendering', function (done) {
|
it('correctly merges locals into empty data before rendering', function (done) {
|
||||||
rssCacheStub.returns(new Promise.resolve('dummyxml'));
|
rssCacheStub.returns(Promise.resolve('dummyxml'));
|
||||||
|
|
||||||
res.locals = {foo: 'bar'};
|
res.locals = {foo: 'bar'};
|
||||||
|
|
||||||
@ -62,7 +61,7 @@ describe('RSS: Renderer', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('correctly merges locals into non-empty data before rendering', function (done) {
|
it('correctly merges locals into non-empty data before rendering', function (done) {
|
||||||
rssCacheStub.returns(new Promise.resolve('dummyxml'));
|
rssCacheStub.returns(Promise.resolve('dummyxml'));
|
||||||
|
|
||||||
res.locals = {foo: 'bar'};
|
res.locals = {foo: 'bar'};
|
||||||
const data = {foo: 'baz', fizz: 'buzz'};
|
const data = {foo: 'baz', fizz: 'buzz'};
|
||||||
@ -82,7 +81,7 @@ describe('RSS: Renderer', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does nothing if it gets an error', function (done) {
|
it('does nothing if it gets an error', function (done) {
|
||||||
rssCacheStub.returns(new Promise.reject(new Error('Fake Error')));
|
rssCacheStub.returns(Promise.reject(new Error('Fake Error')));
|
||||||
|
|
||||||
renderer.render(res, baseUrl).then(function () {
|
renderer.render(res, baseUrl).then(function () {
|
||||||
done('This should have errored');
|
done('This should have errored');
|
||||||
|
@ -57,7 +57,7 @@ describe('Scheduling: Post Scheduler', function () {
|
|||||||
events.emit('post.scheduled', post);
|
events.emit('post.scheduled', post);
|
||||||
|
|
||||||
// let the events bubble up
|
// let the events bubble up
|
||||||
await Promise.delay(100);
|
await new Promise(resolve => setTimeout(resolve, 100));
|
||||||
|
|
||||||
adapter.schedule.called.should.eql(true);
|
adapter.schedule.called.should.eql(true);
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
const db = require('../../../../../core/server/data/db');
|
const db = require('../../../../../core/server/data/db');
|
||||||
const exporter = require('../../../../../core/server/data/exporter');
|
const exporter = require('../../../../../core/server/data/exporter');
|
||||||
@ -157,7 +156,7 @@ describe('Exporter', function () {
|
|||||||
describe('exportFileName', function () {
|
describe('exportFileName', function () {
|
||||||
it('should return a correctly structured filename', function (done) {
|
it('should return a correctly structured filename', function (done) {
|
||||||
const settingsStub = sinon.stub(models.Settings, 'findOne').returns(
|
const settingsStub = sinon.stub(models.Settings, 'findOne').returns(
|
||||||
new Promise.resolve({
|
Promise.resolve({
|
||||||
get: function () {
|
get: function () {
|
||||||
return 'testblog';
|
return 'testblog';
|
||||||
}
|
}
|
||||||
@ -175,7 +174,7 @@ describe('Exporter', function () {
|
|||||||
|
|
||||||
it('should return a correctly structured filename if settings is empty', function (done) {
|
it('should return a correctly structured filename if settings is empty', function (done) {
|
||||||
const settingsStub = sinon.stub(models.Settings, 'findOne').returns(
|
const settingsStub = sinon.stub(models.Settings, 'findOne').returns(
|
||||||
new Promise.resolve()
|
Promise.resolve()
|
||||||
);
|
);
|
||||||
|
|
||||||
exporter.fileName().then(function (result) {
|
exporter.fileName().then(function (result) {
|
||||||
@ -189,7 +188,7 @@ describe('Exporter', function () {
|
|||||||
|
|
||||||
it('should return a correctly structured filename if settings errors', function (done) {
|
it('should return a correctly structured filename if settings errors', function (done) {
|
||||||
const settingsStub = sinon.stub(models.Settings, 'findOne').returns(
|
const settingsStub = sinon.stub(models.Settings, 'findOne').returns(
|
||||||
new Promise.reject()
|
Promise.reject()
|
||||||
);
|
);
|
||||||
|
|
||||||
exporter.fileName().then(function (result) {
|
exporter.fileName().then(function (result) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
|
|
||||||
const models = require('../../../../../../core/server/models');
|
const models = require('../../../../../../core/server/models');
|
||||||
const baseUtils = require('../../../../../../core/server/models/base/utils');
|
const baseUtils = require('../../../../../../core/server/models/base/utils');
|
||||||
|
@ -2,7 +2,6 @@ const errors = require('@tryghost/errors');
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const security = require('@tryghost/security');
|
const security = require('@tryghost/security');
|
||||||
const models = require('../../../../../core/server/models');
|
const models = require('../../../../../core/server/models');
|
||||||
const urlUtils = require('../../../../../core/shared/url-utils');
|
const urlUtils = require('../../../../../core/shared/url-utils');
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const models = require('../../../../core/server/models');
|
const models = require('../../../../core/server/models');
|
||||||
const settingsCache = require('../../../../core/shared/settings-cache');
|
const settingsCache = require('../../../../core/shared/settings-cache');
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
const models = require('../../../../core/server/models');
|
const models = require('../../../../core/server/models');
|
||||||
const permissions = require('../../../../core/server/services/permissions');
|
const permissions = require('../../../../core/server/services/permissions');
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const mail = require('../../../../../core/server/services/mail');
|
const mail = require('../../../../../core/server/services/mail');
|
||||||
const settingsCache = require('../../../../../core/shared/settings-cache');
|
const settingsCache = require('../../../../../core/shared/settings-cache');
|
||||||
const configUtils = require('../../../../utils/configUtils');
|
const configUtils = require('../../../../utils/configUtils');
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const testUtils = require('../../../../utils');
|
const testUtils = require('../../../../utils');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const models = require('../../../../../core/server/models');
|
const models = require('../../../../../core/server/models');
|
||||||
const permissions = require('../../../../../core/server/services/permissions');
|
const permissions = require('../../../../../core/server/services/permissions');
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const testUtils = require('../../../../utils');
|
const testUtils = require('../../../../utils');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const models = require('../../../../../core/server/models');
|
const models = require('../../../../../core/server/models');
|
||||||
const actionsMap = require('../../../../../core/server/services/permissions/actions-map-cache');
|
const actionsMap = require('../../../../../core/server/services/permissions/actions-map-cache');
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
const should = require('should');
|
const should = require('should');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const testUtils = require('../../../../utils');
|
const testUtils = require('../../../../utils');
|
||||||
const Promise = require('bluebird');
|
|
||||||
const models = require('../../../../../core/server/models');
|
const models = require('../../../../../core/server/models');
|
||||||
const providers = require('../../../../../core/server/services/permissions/providers');
|
const providers = require('../../../../../core/server/services/permissions/providers');
|
||||||
|
|
||||||
@ -206,7 +205,7 @@ describe('Permission Providers', function () {
|
|||||||
describe('API Key', function () {
|
describe('API Key', function () {
|
||||||
it('errors if api_key cannot be found', function (done) {
|
it('errors if api_key cannot be found', function (done) {
|
||||||
let findApiKeySpy = sinon.stub(models.ApiKey, 'findOne');
|
let findApiKeySpy = sinon.stub(models.ApiKey, 'findOne');
|
||||||
findApiKeySpy.returns(new Promise.resolve());
|
findApiKeySpy.returns(Promise.resolve());
|
||||||
providers.apiKey(1)
|
providers.apiKey(1)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
done(new Error('Should have thrown an api key not found error'));
|
done(new Error('Should have thrown an api key not found error'));
|
||||||
|
Loading…
Reference in New Issue
Block a user