Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
no issue

- replace test themes
  - otherwise they are all invalid with the new GScan version
- fix general tests because of Ghost 2.0 logic
  • Loading branch information
kirrg001 committed Aug 16, 2018
1 parent dc96d2d commit bbde22a
Show file tree
Hide file tree
Showing 51 changed files with 9,112 additions and 196 deletions.
2 changes: 1 addition & 1 deletion core/server/api/themes.js
Expand Up @@ -95,7 +95,7 @@ themes = {
}

return localUtils
// Permissions
// Permissions
.handlePermissions('themes', 'add')(options)
// Validation
.then(function validateTheme() {
Expand Down
107 changes: 55 additions & 52 deletions core/test/functional/routes/api/themes_spec.js
Expand Up @@ -26,42 +26,8 @@ describe('Themes API', function () {
editor: null
}, ghostServer, contentFolder = path.join(os.tmpdir(), uuid.v1(), 'ghost-test');

/**
* Create a temporary folder that contains:
* - 1 valid theme that has warnings: test-theme
* - 1 invalid theme: broken-theme
*/
function setupThemesFolder(tmpContentPath) {
fs.ensureDirSync(tmpContentPath);

fs.mkdirSync(path.join(tmpContentPath, 'casper'));
fs.writeFileSync(
path.join(tmpContentPath, 'casper', 'package.json'),
JSON.stringify({name: 'casper', version: '0.1.2'})
);
fs.writeFileSync(path.join(tmpContentPath, 'casper', 'index.hbs'));
fs.writeFileSync(path.join(tmpContentPath, 'casper', 'post.hbs'));

fs.mkdirSync(path.join(tmpContentPath, 'test-theme'));
fs.writeFileSync(
path.join(tmpContentPath, 'test-theme', 'package.json'),
JSON.stringify({name: 'test-theme', version: '0.5.9', author: {email: 'test@example.org'}})
);
fs.writeFileSync(path.join(tmpContentPath, 'test-theme', 'index.hbs'));
fs.writeFileSync(path.join(tmpContentPath, 'test-theme', 'post.hbs'));

fs.mkdirSync(path.join(tmpContentPath, 'broken-theme'));
fs.writeFileSync(
path.join(tmpContentPath, 'broken-theme', 'package.json'),
JSON.stringify({name: 'broken-theme', version: '1.1.2'})
);
}

before(function () {
// extend content theme folder
setupThemesFolder(path.join(contentFolder, 'themes'));

return ghost({contentFolder: contentFolder, copyThemes: false})
return ghost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
request = supertest.agent(config.get('url'));
Expand Down Expand Up @@ -114,7 +80,7 @@ describe('Themes API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse.themes);
testUtils.API.checkResponse(jsonResponse, 'themes');
jsonResponse.themes.length.should.eql(3);
jsonResponse.themes.length.should.eql(5);

testUtils.API.checkResponse(jsonResponse.themes[0], 'theme');
jsonResponse.themes[0].name.should.eql('broken-theme');
Expand All @@ -125,13 +91,22 @@ describe('Themes API', function () {
jsonResponse.themes[1].name.should.eql('casper');
jsonResponse.themes[1].package.should.be.an.Object().with.properties('name', 'version');
jsonResponse.themes[1].active.should.be.true();
jsonResponse.themes[1].templates.should.eql([]);

testUtils.API.checkResponse(jsonResponse.themes[2], 'theme');
jsonResponse.themes[2].name.should.eql('test-theme');
jsonResponse.themes[2].name.should.eql('casper-1.4');
jsonResponse.themes[2].package.should.be.an.Object().with.properties('name', 'version');
jsonResponse.themes[2].active.should.be.false();

testUtils.API.checkResponse(jsonResponse.themes[3], 'theme');
jsonResponse.themes[3].name.should.eql('test-theme');
jsonResponse.themes[3].package.should.be.false;
jsonResponse.themes[3].active.should.be.false();

testUtils.API.checkResponse(jsonResponse.themes[4], 'theme');
jsonResponse.themes[4].name.should.eql('test-theme-channels');
jsonResponse.themes[4].package.should.be.false;
jsonResponse.themes[4].active.should.be.false();

done();
});
});
Expand Down Expand Up @@ -186,12 +161,26 @@ describe('Themes API', function () {
jsonResponse.themes[0].active.should.be.false();

// ensure tmp theme folder contains two themes now
var tmpFolderContents = fs.readdirSync(config.getContentPath('themes'));
tmpFolderContents.should.be.an.Array().with.lengthOf(4);
tmpFolderContents[0].should.eql('broken-theme');
tmpFolderContents[1].should.eql('casper');
tmpFolderContents[2].should.eql('test-theme');
tmpFolderContents[3].should.eql('valid');
const tmpFolderContents = fs.readdirSync(config.getContentPath('themes'));
tmpFolderContents.forEach((theme, index) => {
if (theme.match(/^\./)) {
tmpFolderContents.splice(index, 1);
}
});
tmpFolderContents.should.be.an.Array().with.lengthOf(10);

tmpFolderContents.should.eql([
'broken-theme',
'casper',
'casper-1.4',
'casper.zip',
'invalid.zip',
'test-theme',
'test-theme-channels',
'valid',
'valid.zip',
'warnings.zip'
]);

// Check the Themes API returns the correct result
request.get(testUtils.API.getApiQuery('themes/'))
Expand All @@ -207,7 +196,7 @@ describe('Themes API', function () {

should.exist(jsonResponse.themes);
testUtils.API.checkResponse(jsonResponse, 'themes');
jsonResponse.themes.length.should.eql(4);
jsonResponse.themes.length.should.eql(6);

// Casper should be present and still active
casperTheme = _.find(jsonResponse.themes, {name: 'casper'});
Expand Down Expand Up @@ -245,11 +234,25 @@ describe('Themes API', function () {
jsonResponse.should.eql({});

// ensure tmp theme folder contains one theme again now
var tmpFolderContents = fs.readdirSync(config.getContentPath('themes'));
tmpFolderContents.should.be.an.Array().with.lengthOf(3);
tmpFolderContents[0].should.eql('broken-theme');
tmpFolderContents[1].should.eql('casper');
tmpFolderContents[2].should.eql('test-theme');
const tmpFolderContents = fs.readdirSync(config.getContentPath('themes'));
tmpFolderContents.forEach((theme, index) => {
if (theme.match(/^\./)) {
tmpFolderContents.splice(index, 1);
}
});
tmpFolderContents.should.be.an.Array().with.lengthOf(9);

tmpFolderContents.should.eql([
'broken-theme',
'casper',
'casper-1.4',
'casper.zip',
'invalid.zip',
'test-theme',
'test-theme-channels',
'valid.zip',
'warnings.zip'
]);

// Check the themes API returns the correct result after deletion
request.get(testUtils.API.getApiQuery('themes/'))
Expand All @@ -265,7 +268,7 @@ describe('Themes API', function () {

should.exist(jsonResponse.themes);
testUtils.API.checkResponse(jsonResponse, 'themes');
jsonResponse.themes.length.should.eql(3);
jsonResponse.themes.length.should.eql(5);

// Casper should be present and still active
casperTheme = _.find(jsonResponse.themes, {name: 'casper'});
Expand Down Expand Up @@ -330,7 +333,7 @@ describe('Themes API', function () {

should.exist(jsonResponse.themes);
testUtils.API.checkResponse(jsonResponse, 'themes');
jsonResponse.themes.length.should.eql(3);
jsonResponse.themes.length.should.eql(5);

casperTheme = _.find(jsonResponse.themes, {name: 'casper'});
should.exist(casperTheme);
Expand Down
2 changes: 1 addition & 1 deletion core/test/unit/lib/fs/zip-folder_spec.js
Expand Up @@ -40,7 +40,7 @@ describe('lib/fs: read csv', function () {
return done(err);
}

files.length.should.eql(13);
files.length.should.eql(16);
done();
});
});
Expand Down
8 changes: 4 additions & 4 deletions core/test/unit/services/url/Resources_spec.js
Expand Up @@ -89,6 +89,7 @@ describe('Unit: services/url/Resources', function () {
'id',
'uuid',
'slug',
'comment_id',
'featured',
'page',
'status',
Expand All @@ -104,8 +105,7 @@ describe('Unit: services/url/Resources', function () {
'author',
'primary_author',
'primary_tag',
'url',
'comment_id'
'url'
]);

should.exist(resources.getByIdAndType(options.eventData.type, options.eventData.id));
Expand Down Expand Up @@ -188,6 +188,7 @@ describe('Unit: services/url/Resources', function () {
'id',
'uuid',
'slug',
'comment_id',
'featured',
'page',
'status',
Expand All @@ -203,8 +204,7 @@ describe('Unit: services/url/Resources', function () {
'author',
'primary_author',
'primary_tag',
'url',
'comment_id'
'url'
]);

should.exist(obj.tags);
Expand Down
4 changes: 4 additions & 0 deletions core/test/utils/fixtures/themes/broken-theme/package.json
@@ -0,0 +1,4 @@
{
"name": "broken-theme",
"version": "0.0.0"
}
Binary file modified core/test/utils/fixtures/themes/casper.zip
Binary file not shown.
22 changes: 22 additions & 0 deletions core/test/utils/fixtures/themes/casper/LICENSE
@@ -0,0 +1,22 @@
Copyright (c) 2013-2018 Ghost Foundation

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
14 changes: 10 additions & 4 deletions core/test/utils/fixtures/themes/casper/README.md
Expand Up @@ -12,7 +12,7 @@ The default theme for [Ghost](http://github.com/tryghost/ghost/). This is the la

Ghost uses a simple templating language called [Handlebars](http://handlebarsjs.com/) for its themes.

We've documented our default theme pretty heavily so that it should be fairly easy to work out what's going on just by reading the code and the comments. Once you feel comfortable with how everything works, we also have full [theme API documentation](https://themes.ghost.org/) which explains every possible Handlebars helper and template.
We've documented our default theme pretty heavily so that it should be fairly easy to work out what's going on just by reading the code and the comments. Once you feel comfortable with how everything works, we also have full [theme API documentation](https://themes.ghost.org) which explains every possible Handlebars helper and template.

**The main files are:**

Expand All @@ -34,12 +34,18 @@ One really neat trick is that you can also create custom one-off templates just

Casper styles are compiled using Gulp/PostCSS to polyfill future CSS spec. You'll need Node and Gulp installed globally. After that, from the theme's root directory:

`$ npm install`

`$ gulp`
```bash
$ yarn install
$ yarn dev
```

Now you can edit `/assets/css/` files, which will be compiled to `/assets/built/` automatically.

The `zip` Gulp task packages the theme files into `dist/<theme-name>.zip`, which you can then upload to your site.

```bash
$ yarn zip
```

# PostCSS Features Used

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bbde22a

Please sign in to comment.