mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Updated e2e tests to be async/await
- These test files were moved from regression, and were not up to date - Ensured they follow the right patterns
This commit is contained in:
parent
e4074286df
commit
8902cc85d6
2 changed files with 44 additions and 93 deletions
|
@ -9,57 +9,39 @@ const supertest = require('supertest');
|
|||
const cheerio = require('cheerio');
|
||||
const testUtils = require('../utils');
|
||||
const config = require('../../core/shared/config');
|
||||
const ghost = testUtils.startGhost;
|
||||
let request;
|
||||
|
||||
function assertCorrectFrontendHeaders(res) {
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
should.not.exist(res.headers['X-CSRF-Token']);
|
||||
should.not.exist(res.headers['set-cookie']);
|
||||
should.exist(res.headers.date);
|
||||
}
|
||||
|
||||
describe('Frontend Routing: Preview Routes', function () {
|
||||
function doEnd(done) {
|
||||
return function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
should.not.exist(res.headers['X-CSRF-Token']);
|
||||
should.not.exist(res.headers['set-cookie']);
|
||||
should.exist(res.headers.date);
|
||||
|
||||
done();
|
||||
};
|
||||
}
|
||||
|
||||
function addPosts(done) {
|
||||
testUtils.clearData().then(function () {
|
||||
return testUtils.initData();
|
||||
}).then(function () {
|
||||
return testUtils.fixtures.insertPostsAndTags();
|
||||
}).then(function () {
|
||||
done();
|
||||
});
|
||||
async function addPosts() {
|
||||
await testUtils.clearData();
|
||||
await testUtils.initData();
|
||||
await testUtils.fixtures.insertPostsAndTags();
|
||||
}
|
||||
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
before(function () {
|
||||
return ghost()
|
||||
.then(function () {
|
||||
request = supertest.agent(config.get('url'));
|
||||
});
|
||||
before(async function () {
|
||||
await testUtils.startGhost();
|
||||
request = supertest.agent(config.get('url'));
|
||||
});
|
||||
|
||||
before(addPosts);
|
||||
|
||||
it('should display draft posts accessed via uuid', function (done) {
|
||||
request.get('/p/d52c42ae-2755-455c-80ec-70b2ec55c903/')
|
||||
it('should display draft posts accessed via uuid', async function () {
|
||||
await request.get('/p/d52c42ae-2755-455c-80ec-70b2ec55c903/')
|
||||
.expect('Content-Type', /html/)
|
||||
.expect(200)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
.expect(assertCorrectFrontendHeaders)
|
||||
.expect((res) => {
|
||||
const $ = cheerio.load(res.text);
|
||||
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
|
@ -75,22 +57,20 @@ describe('Frontend Routing: Preview Routes', function () {
|
|||
// $('.poweredby').text().should.equal('Proudly published with Ghost');
|
||||
// $('body.post-template').length.should.equal(1);
|
||||
// $('article.post').length.should.equal(1);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should redirect published posts to their live url', function (done) {
|
||||
request.get('/p/2ac6b4f6-e1f3-406c-9247-c94a0496d39d/')
|
||||
it('should redirect published posts to their live url', async function () {
|
||||
await request.get('/p/2ac6b4f6-e1f3-406c-9247-c94a0496d39d/')
|
||||
.expect(301)
|
||||
.expect('Location', '/short-and-sweet/')
|
||||
.expect('Cache-Control', testUtils.cacheRules.year)
|
||||
.end(doEnd(done));
|
||||
.expect(assertCorrectFrontendHeaders);
|
||||
});
|
||||
|
||||
it('404s unknown uuids', function (done) {
|
||||
it('404s unknown uuids', async function () {
|
||||
request.get('/p/aac6b4f6-e1f3-406c-9247-c94a0496d39f/')
|
||||
.expect(404)
|
||||
.end(doEnd(done));
|
||||
.expect(assertCorrectFrontendHeaders);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,87 +10,58 @@ const testUtils = require('../utils');
|
|||
const configUtils = require('../utils/configUtils');
|
||||
const urlUtils = require('../utils/urlUtils');
|
||||
const adminUtils = require('../utils/admin-utils');
|
||||
const ghost = testUtils.startGhost;
|
||||
const i18n = require('../../core/shared/i18n');
|
||||
const config = require('../../core/shared/config');
|
||||
let request;
|
||||
|
||||
i18n.init();
|
||||
|
||||
function assertCorrectHeaders(res) {
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
should.exist(res.headers.date);
|
||||
}
|
||||
|
||||
describe('Admin Routing', function () {
|
||||
function doEnd(done) {
|
||||
return function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
should.exist(res.headers.date);
|
||||
|
||||
done();
|
||||
};
|
||||
}
|
||||
|
||||
function doEndNoAuth(done) {
|
||||
return function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
should.exist(res.headers.date);
|
||||
|
||||
done();
|
||||
};
|
||||
}
|
||||
|
||||
before(function () {
|
||||
before(async function () {
|
||||
adminUtils.stubClientFiles();
|
||||
|
||||
return ghost()
|
||||
.then(function () {
|
||||
request = supertest.agent(config.get('url'));
|
||||
});
|
||||
await testUtils.startGhost();
|
||||
request = supertest.agent(config.get('url'));
|
||||
});
|
||||
|
||||
describe('Assets', function () {
|
||||
it('should return 404 for unknown assets', function (done) {
|
||||
it('should return 404 for unknown assets', async function () {
|
||||
request.get('/ghost/assets/not-found.js')
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(404)
|
||||
.end(doEnd(done));
|
||||
.expect(assertCorrectHeaders);
|
||||
});
|
||||
|
||||
it('should retrieve built assets', function (done) {
|
||||
it('should retrieve built assets', async function () {
|
||||
request.get('/ghost/assets/vendor.js')
|
||||
.expect('Cache-Control', testUtils.cacheRules.year)
|
||||
.expect(200)
|
||||
.end(doEnd(done));
|
||||
.expect(assertCorrectHeaders);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Admin Redirects', function () {
|
||||
it('should redirect /GHOST/ to /ghost/', function (done) {
|
||||
it('should redirect /GHOST/ to /ghost/', async function () {
|
||||
request.get('/GHOST/')
|
||||
.expect('Location', '/ghost/')
|
||||
.expect(301)
|
||||
.end(doEndNoAuth(done));
|
||||
.expect(assertCorrectHeaders);
|
||||
});
|
||||
});
|
||||
|
||||
// we'll use X-Forwarded-Proto: https to simulate an 'https://' request behind a proxy
|
||||
describe('Require HTTPS - redirect', function () {
|
||||
let ghostServer;
|
||||
|
||||
before(function () {
|
||||
before(async function () {
|
||||
configUtils.set('url', 'https://localhost:2390');
|
||||
urlUtils.stubUrlUtilsFromConfig();
|
||||
|
||||
return ghost({forceStart: true})
|
||||
.then(function (_ghostServer) {
|
||||
ghostServer = _ghostServer;
|
||||
request = supertest.agent(config.get('server:host') + ':' + config.get('server:port'));
|
||||
});
|
||||
await testUtils.startGhost({forceStart: true});
|
||||
request = supertest.agent(config.get('server:host') + ':' + config.get('server:port'));
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
@ -98,18 +69,18 @@ describe('Admin Routing', function () {
|
|||
configUtils.restore();
|
||||
});
|
||||
|
||||
it('should redirect admin access over non-HTTPS', function (done) {
|
||||
it('should redirect admin access over non-HTTPS', async function () {
|
||||
request.get('/ghost/')
|
||||
.expect('Location', /^https:\/\/localhost:2390\/ghost\//)
|
||||
.expect(301)
|
||||
.end(doEnd(done));
|
||||
.expect(assertCorrectHeaders);
|
||||
});
|
||||
|
||||
it('should allow admin access over HTTPS', function (done) {
|
||||
it('should allow admin access over HTTPS', async function () {
|
||||
request.get('/ghost/')
|
||||
.set('X-Forwarded-Proto', 'https')
|
||||
.expect(200)
|
||||
.end(doEnd(done));
|
||||
.expect(assertCorrectHeaders);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue