0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Refactored scheduling tests setup using async/await

refs https://github.com/TryGhost/Team/issues/694

- The previous `.then` chaining was outdated and was causing 2x ghost instance initialization per test suite
- With a refactor there's only one intance initialization per suite (saves running time!) and we use more readable async/await syntax, which should make things more maintainable
This commit is contained in:
Naz 2021-05-24 13:11:33 +04:00
parent 46ef52cc7d
commit ba50241fde
3 changed files with 150 additions and 168 deletions

View file

@ -27,16 +27,11 @@ describe('Canary Schedules API', function () {
sinon.restore();
});
before(function () {
return ghost()
.then(() => {
request = supertest.agent(config.get('url'));
});
});
before(async function () {
await ghost();
request = supertest.agent(config.get('url'));
before(function () {
return ghost()
.then(function () {
resources.push(testUtils.DataGenerator.forKnex.createPost({
created_by: testUtils.existingData.users[0].id,
author_id: testUtils.existingData.users[0].id,
@ -83,13 +78,12 @@ describe('Canary Schedules API', function () {
type: 'page'
}));
return Promise.mapSeries(resources, function (post) {
const result = await Promise.mapSeries(resources, function (post) {
return models.Post.add(post, {context: {internal: true}});
}).then(function (result) {
});
result.length.should.eql(5);
});
});
});
describe('publish', function () {
let token;

View file

@ -27,16 +27,11 @@ describe('v2 Schedules API', function () {
sinon.restore();
});
before(function () {
return ghost()
.then(() => {
request = supertest.agent(config.get('url'));
});
});
before(async function () {
await ghost();
request = supertest.agent(config.get('url'));
before(function () {
return ghost()
.then(function () {
resources.push(testUtils.DataGenerator.forKnex.createPost({
created_by: testUtils.existingData.users[0].id,
author_id: testUtils.existingData.users[0].id,
@ -83,13 +78,12 @@ describe('v2 Schedules API', function () {
type: 'page'
}));
return Promise.mapSeries(resources, function (post) {
const result = await Promise.mapSeries(resources, function (post) {
return models.Post.add(post, {context: {internal: true}});
}).then(function (result) {
});
result.length.should.eql(5);
});
});
});
describe('publish', function () {
let token;

View file

@ -27,16 +27,11 @@ describe('v3 Schedules API', function () {
sinon.restore();
});
before(function () {
return ghost()
.then(() => {
request = supertest.agent(config.get('url'));
});
});
before(async function () {
await ghost();
request = supertest.agent(config.get('url'));
before(function () {
return ghost()
.then(function () {
resources.push(testUtils.DataGenerator.forKnex.createPost({
created_by: testUtils.existingData.users[0].id,
author_id: testUtils.existingData.users[0].id,
@ -83,13 +78,12 @@ describe('v3 Schedules API', function () {
type: 'page'
}));
return Promise.mapSeries(resources, function (post) {
const result = await Promise.mapSeries(resources, function (post) {
return models.Post.add(post, {context: {internal: true}});
}).then(function (result) {
});
result.length.should.eql(5);
});
});
});
describe('publish', function () {
let token;