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:
parent
46ef52cc7d
commit
ba50241fde
3 changed files with 150 additions and 168 deletions
|
@ -27,16 +27,11 @@ describe('Canary Schedules API', function () {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
before(function () {
|
before(async function () {
|
||||||
return ghost()
|
await ghost();
|
||||||
.then(() => {
|
|
||||||
request = supertest.agent(config.get('url'));
|
request = supertest.agent(config.get('url'));
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
before(function () {
|
|
||||||
return ghost()
|
|
||||||
.then(function () {
|
|
||||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||||
created_by: testUtils.existingData.users[0].id,
|
created_by: testUtils.existingData.users[0].id,
|
||||||
author_id: testUtils.existingData.users[0].id,
|
author_id: testUtils.existingData.users[0].id,
|
||||||
|
@ -83,13 +78,12 @@ describe('Canary Schedules API', function () {
|
||||||
type: 'page'
|
type: 'page'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return Promise.mapSeries(resources, function (post) {
|
const result = await Promise.mapSeries(resources, function (post) {
|
||||||
return models.Post.add(post, {context: {internal: true}});
|
return models.Post.add(post, {context: {internal: true}});
|
||||||
}).then(function (result) {
|
});
|
||||||
|
|
||||||
result.length.should.eql(5);
|
result.length.should.eql(5);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('publish', function () {
|
describe('publish', function () {
|
||||||
let token;
|
let token;
|
||||||
|
|
|
@ -27,16 +27,11 @@ describe('v2 Schedules API', function () {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
before(function () {
|
before(async function () {
|
||||||
return ghost()
|
await ghost();
|
||||||
.then(() => {
|
|
||||||
request = supertest.agent(config.get('url'));
|
request = supertest.agent(config.get('url'));
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
before(function () {
|
|
||||||
return ghost()
|
|
||||||
.then(function () {
|
|
||||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||||
created_by: testUtils.existingData.users[0].id,
|
created_by: testUtils.existingData.users[0].id,
|
||||||
author_id: testUtils.existingData.users[0].id,
|
author_id: testUtils.existingData.users[0].id,
|
||||||
|
@ -83,13 +78,12 @@ describe('v2 Schedules API', function () {
|
||||||
type: 'page'
|
type: 'page'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return Promise.mapSeries(resources, function (post) {
|
const result = await Promise.mapSeries(resources, function (post) {
|
||||||
return models.Post.add(post, {context: {internal: true}});
|
return models.Post.add(post, {context: {internal: true}});
|
||||||
}).then(function (result) {
|
});
|
||||||
|
|
||||||
result.length.should.eql(5);
|
result.length.should.eql(5);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('publish', function () {
|
describe('publish', function () {
|
||||||
let token;
|
let token;
|
||||||
|
|
|
@ -27,16 +27,11 @@ describe('v3 Schedules API', function () {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
before(function () {
|
before(async function () {
|
||||||
return ghost()
|
await ghost();
|
||||||
.then(() => {
|
|
||||||
request = supertest.agent(config.get('url'));
|
request = supertest.agent(config.get('url'));
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
before(function () {
|
|
||||||
return ghost()
|
|
||||||
.then(function () {
|
|
||||||
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
resources.push(testUtils.DataGenerator.forKnex.createPost({
|
||||||
created_by: testUtils.existingData.users[0].id,
|
created_by: testUtils.existingData.users[0].id,
|
||||||
author_id: testUtils.existingData.users[0].id,
|
author_id: testUtils.existingData.users[0].id,
|
||||||
|
@ -83,13 +78,12 @@ describe('v3 Schedules API', function () {
|
||||||
type: 'page'
|
type: 'page'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return Promise.mapSeries(resources, function (post) {
|
const result = await Promise.mapSeries(resources, function (post) {
|
||||||
return models.Post.add(post, {context: {internal: true}});
|
return models.Post.add(post, {context: {internal: true}});
|
||||||
}).then(function (result) {
|
});
|
||||||
|
|
||||||
result.length.should.eql(5);
|
result.length.should.eql(5);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('publish', function () {
|
describe('publish', function () {
|
||||||
let token;
|
let token;
|
||||||
|
|
Loading…
Add table
Reference in a new issue