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:
Sagar Gupta 2023-01-23 12:23:48 +01:00 committed by GitHub
parent 42b30ac613
commit bba4743739
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 9 additions and 28 deletions

View File

@ -2,7 +2,6 @@ const errors = require('@tryghost/errors');
const _ = require('lodash');
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const validators = require('../../../../../../../core/server/api/endpoints/utils/validators');
const models = require('../../../../../../../core/server/models');

View File

@ -2,7 +2,6 @@ const errors = require('@tryghost/errors');
const _ = require('lodash');
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const validators = require('../../../../../../../core/server/api/endpoints/utils/validators');
const models = require('../../../../../../../core/server/models');

View File

@ -2,7 +2,6 @@ const errors = require('@tryghost/errors');
const _ = require('lodash');
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const validators = require('../../../../../../../core/server/api/endpoints/utils/validators');
describe('Unit: endpoints/utils/validators/input/tags', function () {

View File

@ -2,7 +2,6 @@ const errors = require('@tryghost/errors');
const _ = require('lodash');
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const validators = require('../../../../../../../core/server/api/endpoints/utils/validators');
describe('Unit: endpoints/utils/validators/input/webhooks', function () {

View File

@ -1,6 +1,5 @@
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const {SafeString} = require('../../../../core/frontend/services/handlebars');
const configUtils = require('../../../utils/configUtils');
const logging = require('@tryghost/logging');

View File

@ -1,6 +1,5 @@
const errors = require('@tryghost/errors');
const sinon = require('sinon');
const Promise = require('bluebird');
const markdownToMobiledoc = require('../../../utils/fixtures/data-generator').markdownToMobiledoc;
const next_post = require('../../../../core/frontend/helpers/prev_post');
const api = require('../../../../core/frontend/services/proxy').api;

View File

@ -1,6 +1,5 @@
const errors = require('@tryghost/errors');
const sinon = require('sinon');
const Promise = require('bluebird');
const markdownToMobiledoc = require('../../../utils/fixtures/data-generator').markdownToMobiledoc;
const prev_post = require('../../../../core/frontend/helpers/prev_post');
const api = require('../../../../core/frontend/services/proxy').api;

View File

@ -1,6 +1,5 @@
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const testUtils = require('../../../utils');
const configUtils = require('../../../utils/configUtils');

View File

@ -1,6 +1,5 @@
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const testUtils = require('../../../../../utils');
const configUtils = require('../../../../../utils/configUtils');
const api = require('../../../../../../core/frontend/services/proxy').api;

View File

@ -1,6 +1,5 @@
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const rssCache = require('../../../../../core/frontend/services/rss/cache');
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) {
rssCacheStub.returns(new Promise.resolve('dummyxml'));
rssCacheStub.returns(Promise.resolve('dummyxml'));
renderer.render(res, baseUrl).then(function () {
rssCacheStub.calledOnce.should.be.true();
@ -43,7 +42,7 @@ describe('RSS: Renderer', function () {
});
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'};
@ -62,7 +61,7 @@ describe('RSS: Renderer', function () {
});
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'};
const data = {foo: 'baz', fizz: 'buzz'};
@ -82,7 +81,7 @@ describe('RSS: Renderer', function () {
});
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 () {
done('This should have errored');

View File

@ -57,7 +57,7 @@ describe('Scheduling: Post Scheduler', function () {
events.emit('post.scheduled', post);
// let the events bubble up
await Promise.delay(100);
await new Promise(resolve => setTimeout(resolve, 100));
adapter.schedule.called.should.eql(true);

View File

@ -1,6 +1,5 @@
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const errors = require('@tryghost/errors');
const db = require('../../../../../core/server/data/db');
const exporter = require('../../../../../core/server/data/exporter');
@ -157,7 +156,7 @@ describe('Exporter', function () {
describe('exportFileName', function () {
it('should return a correctly structured filename', function (done) {
const settingsStub = sinon.stub(models.Settings, 'findOne').returns(
new Promise.resolve({
Promise.resolve({
get: function () {
return 'testblog';
}
@ -175,7 +174,7 @@ describe('Exporter', function () {
it('should return a correctly structured filename if settings is empty', function (done) {
const settingsStub = sinon.stub(models.Settings, 'findOne').returns(
new Promise.resolve()
Promise.resolve()
);
exporter.fileName().then(function (result) {
@ -189,7 +188,7 @@ describe('Exporter', function () {
it('should return a correctly structured filename if settings errors', function (done) {
const settingsStub = sinon.stub(models.Settings, 'findOne').returns(
new Promise.reject()
Promise.reject()
);
exporter.fileName().then(function (result) {

View File

@ -1,6 +1,5 @@
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const models = require('../../../../../../core/server/models');
const baseUtils = require('../../../../../../core/server/models/base/utils');

View File

@ -2,7 +2,6 @@ const errors = require('@tryghost/errors');
const should = require('should');
const sinon = require('sinon');
const _ = require('lodash');
const Promise = require('bluebird');
const security = require('@tryghost/security');
const models = require('../../../../../core/server/models');
const urlUtils = require('../../../../../core/shared/url-utils');

View File

@ -1,6 +1,5 @@
const errors = require('@tryghost/errors');
const sinon = require('sinon');
const Promise = require('bluebird');
const models = require('../../../../core/server/models');
const settingsCache = require('../../../../core/shared/settings-cache');

View File

@ -1,6 +1,5 @@
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const errors = require('@tryghost/errors');
const models = require('../../../../core/server/models');
const permissions = require('../../../../core/server/services/permissions');

View File

@ -1,6 +1,5 @@
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const mail = require('../../../../../core/server/services/mail');
const settingsCache = require('../../../../../core/shared/settings-cache');
const configUtils = require('../../../../utils/configUtils');

View File

@ -1,7 +1,6 @@
const should = require('should');
const sinon = require('sinon');
const testUtils = require('../../../../utils');
const Promise = require('bluebird');
const _ = require('lodash');
const models = require('../../../../../core/server/models');
const permissions = require('../../../../../core/server/services/permissions');

View File

@ -1,7 +1,6 @@
const should = require('should');
const sinon = require('sinon');
const testUtils = require('../../../../utils');
const Promise = require('bluebird');
const _ = require('lodash');
const models = require('../../../../../core/server/models');
const actionsMap = require('../../../../../core/server/services/permissions/actions-map-cache');

View File

@ -1,7 +1,6 @@
const should = require('should');
const sinon = require('sinon');
const testUtils = require('../../../../utils');
const Promise = require('bluebird');
const models = require('../../../../../core/server/models');
const providers = require('../../../../../core/server/services/permissions/providers');
@ -206,7 +205,7 @@ describe('Permission Providers', function () {
describe('API Key', function () {
it('errors if api_key cannot be found', function (done) {
let findApiKeySpy = sinon.stub(models.ApiKey, 'findOne');
findApiKeySpy.returns(new Promise.resolve());
findApiKeySpy.returns(Promise.resolve());
providers.apiKey(1)
.then(() => {
done(new Error('Should have thrown an api key not found error'));