Skip to content

Commit

Permalink
Tests: Sort out usage of content folder in tests (#9034)
Browse files Browse the repository at this point in the history
no issue

- use latest casper in test fixtures
- never ever use the root content folder for tests
- if we start/fork Ghost for the tests, we use a tmp folder
- this change is required to for an upcoming PR (#9029)
- i've added a TODO to create a helper fn for stopping the ghost server, so we can cleanup the tmp folder

* Care about TODO's in our channels spec

- add the 1.4 compatible casper theme to fixtures
- so as soon as you start Ghost, the test env will provide the content folder in /tmp something with the activated latest default casper and the 1.4 compatible old casper
- there are tests which tests different logici e.g. pagination
- therefor we need a different theme, we are simply using our 1.4 casper
  • Loading branch information
kirrg001 authored and ErisDS committed Sep 21, 2017
1 parent e3fb5b8 commit 0fbf5e1
Show file tree
Hide file tree
Showing 40 changed files with 5,283 additions and 263 deletions.
2 changes: 1 addition & 1 deletion core/test/functional/routes/api/db_spec.js
Expand Up @@ -124,7 +124,7 @@ describe('DB API', function () {
if (err) {
return done(err);
}
res.body.should.match(/content\/data/);
res.body.should.match(/data/);
fsStub.calledOnce.should.eql(true);

done();
Expand Down
43 changes: 28 additions & 15 deletions core/test/functional/routes/channel_spec.js
Expand Up @@ -4,10 +4,13 @@
// tested with the unit tests
var should = require('should'),
supertest = require('supertest'),
sinon = require('sinon'),
testUtils = require('../../utils'),
cheerio = require('cheerio'),
config = require('../../../../core/server/config'),
settingsCache = require('../../../../core/server/settings/cache'),
ghost = testUtils.startGhost,
sandbox = sinon.sandbox.create(),
request;

describe('Channel Routes', function () {
Expand All @@ -29,6 +32,16 @@ describe('Channel Routes', function () {
}

before(function (done) {
// Default is always casper. We use the old compatible 1.4 casper theme for these tests. Available in the test content folder.
var originalSettingsCacheGetFn = settingsCache.get;
sandbox.stub(settingsCache, 'get', function (key, options) {
if (key === 'active_theme') {
return 'casper-1.4';
}

return originalSettingsCacheGetFn(key, options);
});

ghost().then(function (_ghostServer) {
ghostServer = _ghostServer;
return ghostServer.start();
Expand All @@ -45,6 +58,7 @@ describe('Channel Routes', function () {
after(testUtils.teardown);

after(function () {
sandbox.restore();
return ghostServer.stop();
});

Expand All @@ -66,13 +80,12 @@ describe('Channel Routes', function () {
should.not.exist(res.headers['set-cookie']);
should.exist(res.headers.date);

// @TODO: use theme from fixtures and don't rely on content/themes/casper
$('title').text().should.equal('Ghost');
// $('.content .post').length.should.equal(5);
// $('.poweredby').text().should.equal('Proudly published with Ghost');
// $('body.home-template').length.should.equal(1);
// $('article.post').length.should.equal(5);
// $('article.tag-getting-started').length.should.equal(5);
$('.content .post').length.should.equal(5);
$('.poweredby').text().should.equal('Proudly published with Ghost');
$('body.home-template').length.should.equal(1);
$('article.post').length.should.equal(5);
$('article.tag-getting-started').length.should.equal(5);

done();
});
Expand Down Expand Up @@ -139,7 +152,6 @@ describe('Channel Routes', function () {

describe('Paged', function () {
// Add enough posts to trigger pages for both the index (25 pp) and rss (15 pp)
// @TODO: change this whole thing to use the casper theme from fixtures
before(function (done) {
testUtils.initData().then(function () {
return testUtils.fixtures.insertPostsAndTags();
Expand All @@ -160,7 +172,6 @@ describe('Channel Routes', function () {
.end(doEnd(done));
});

// @TODO: use theme from fixtures and don't rely on content/themes/casper
it('should respond with html', function (done) {
request.get('/page/2/')
.expect('Content-Type', /html/)
Expand All @@ -186,7 +197,8 @@ describe('Channel Routes', function () {
});

it('should 404 if page too high', function (done) {
request.get('/page/5/')
// We have 7 default welcome posts + 8 fixture posts + 25 more posts = 40 (5 pages per post is default). So the 9th page 404's.
request.get('/page/9/')
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(404)
.expect(/Page not found/)
Expand Down Expand Up @@ -270,8 +282,11 @@ describe('Channel Routes', function () {
should.not.exist(res.headers['set-cookie']);
should.exist(res.headers.date);

// @TODO: use theme from fixtures and don't rely on content/themes/casper
$('body').attr('class').should.eql('tag-template tag-getting-started');
$('body').attr('class').should.eql('tag-template tag-getting-started nav-closed');
$('.content .post').length.should.equal(5);
$('.poweredby').text().should.equal('Proudly published with Ghost');
$('article.post').length.should.equal(5);
$('article.tag-getting-started').length.should.equal(5);

done();
});
Expand Down Expand Up @@ -345,8 +360,7 @@ describe('Channel Routes', function () {
.end(doEnd(done));
});

// @TODO: use theme from fixtures and don't rely on content/themes/casper
it.skip('should respond with html', function (done) {
it('should respond with html', function (done) {
request.get('/tag/injection/page/2/')
.expect('Content-Type', /html/)
.expect('Cache-Control', testUtils.cacheRules.public)
Expand Down Expand Up @@ -569,8 +583,7 @@ describe('Channel Routes', function () {
.end(doEnd(done));
});

// @TODO: use theme from fixtures and don't rely on content/themes/casper
it.skip('should respond with html', function (done) {
it('should respond with html', function (done) {
request.get('/author/ghost-owner/page/2/')
.expect('Content-Type', /html/)
.expect('Cache-Control', testUtils.cacheRules.public)
Expand Down
2 changes: 1 addition & 1 deletion core/test/unit/utils/zip-folder_spec.js
Expand Up @@ -40,7 +40,7 @@ describe('Utils: zip-folder', function () {
return done(err);
}

files.length.should.eql(10);
files.length.should.eql(12);
done();
});
});
Expand Down
1 change: 0 additions & 1 deletion core/test/utils/fixtures/theme/partials/test.hbs

This file was deleted.

7 changes: 7 additions & 0 deletions core/test/utils/fixtures/themes/casper-1.4/README.md
@@ -0,0 +1,7 @@
# Casper

The default theme for [Ghost](http://github.com/tryghost/ghost/). Casper 1.4 is the last release of Casper's original design, created to be compatible **ONLY with Ghost 1.0** and above. If you are running an earlier version of Ghost, you will need [Casper 1.3.7](https://github.com/TryGhost/Casper/releases/tag/1.3.7). For all other versions of Ghost, we recommend switching to the [latest release](https://github.com/TryGhost/Casper/releases) of Casper, with an updated design.

## Copyright & License

Copyright (c) 2013-2017 Ghost Foundation - Released under the [MIT license](LICENSE).

0 comments on commit 0fbf5e1

Please sign in to comment.