0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00
ghost/core/test/unit/themes_spec.js
Hannah Wolfe c70fbc2c7e 🎨 Collect & simplify package utils (#8080)
closes #8056

🎨 Collect together the package-related utils
- read directory actually reads a directory of packages
- parse package json is very tighly related to this

🎨 Move filterPaths -> packages.filterPackages
- this function is related to packages, not settings
- move the function to the new utils/packages
- add 100% test coverage

🎨 Simplify filterPackages code
🎨 Simplify reading of packages & themes
- This massively reduces all the complex code in the read packages & themes utils
- Added full test coverage

🎨 Improve & clarify active prop in filterPackages
- active is returned from API endpoints to combine data from multiple sources
- see https://github.com/TryGhost/Ghost/pull/8064#discussion_r103514810

🎨 Better error handling
🔥 Temporarily remove custom error templates
- we will reimplement this later when we have got a better concept of loading the active theme in place
- refs #8079
2017-03-01 14:09:31 +01:00

129 lines
4.8 KiB
JavaScript

var should = require('should'),
fs = require('fs'),
tmp = require('tmp'),
join = require('path').join,
readThemes = require('../../server/themes/read');
// To stop jshint complaining
should.equal(true, true);
describe('Themes', function () {
describe('Read All', function () {
it('should read directory and include only folders', function (done) {
var themePath = tmp.dirSync({unsafeCleanup: true});
// create trash
fs.writeFileSync(join(themePath.name, 'casper.zip'));
fs.writeFileSync(join(themePath.name, '.DS_Store'));
// create actual theme
fs.mkdirSync(join(themePath.name, 'casper'));
fs.mkdirSync(join(themePath.name, 'casper', 'partials'));
fs.writeFileSync(join(themePath.name, 'casper', 'index.hbs'));
fs.writeFileSync(join(themePath.name, 'casper', 'partials', 'navigation.hbs'));
readThemes.all(themePath.name)
.then(function (themeList) {
themeList.should.eql({
casper: {
name: 'casper',
path: join(themePath.name, 'casper'),
'package.json': null
}
});
done();
})
.catch(done)
.finally(themePath.removeCallback);
});
it('should read directory and read package.json if present', function (done) {
var themePath = tmp.dirSync({unsafeCleanup: true});
// create trash
fs.writeFileSync(join(themePath.name, 'README.md'));
fs.writeFileSync(join(themePath.name, 'Thumbs.db'));
// create actual theme
fs.mkdirSync(join(themePath.name, 'casper'));
fs.mkdirSync(join(themePath.name, 'not-casper'));
fs.writeFileSync(
join(themePath.name, 'casper', 'package.json'),
JSON.stringify({name: 'casper', version: '0.1.2'})
);
readThemes.all(themePath.name)
.then(function (themeList) {
themeList.should.eql({
casper: {
name: 'casper',
path: join(themePath.name, 'casper'),
'package.json': {name: 'casper', version: '0.1.2'}
},
'not-casper': {
name: 'not-casper',
path: join(themePath.name, 'not-casper'),
'package.json': null
}
});
done();
})
.catch(done)
.finally(themePath.removeCallback);
});
});
describe('Read One', function () {
it('should read directory and include only single requested theme', function (done) {
var themePath = tmp.dirSync({unsafeCleanup: true});
// create trash
fs.writeFileSync(join(themePath.name, 'casper.zip'));
fs.writeFileSync(join(themePath.name, '.DS_Store'));
// create actual theme
fs.mkdirSync(join(themePath.name, 'casper'));
fs.writeFileSync(join(themePath.name, 'casper', 'index.hbs'));
fs.writeFileSync(
join(themePath.name, 'casper', 'package.json'),
JSON.stringify({name: 'casper', version: '0.1.2'})
);
fs.mkdirSync(join(themePath.name, 'not-casper'));
fs.writeFileSync(join(themePath.name, 'not-casper', 'index.hbs'));
readThemes.one(themePath.name, 'casper')
.then(function (themeList) {
themeList.should.eql({
casper: {
name: 'casper',
path: join(themePath.name, 'casper'),
'package.json': {name: 'casper', version: '0.1.2'}
}
});
done();
})
.catch(done)
.finally(themePath.removeCallback);
});
it('should return empty object if theme cannot be found', function (done) {
var themePath = tmp.dirSync({unsafeCleanup: true});
// create trash
fs.writeFileSync(join(themePath.name, 'casper.zip'));
fs.writeFileSync(join(themePath.name, '.DS_Store'));
readThemes.one(themePath.name, 'casper')
.then(function (themeList) {
themeList.should.eql({});
done();
})
.catch(done)
.finally(themePath.removeCallback);
});
});
});