Ghost/core/test/unit/helpers/asset_spec.js
Katharina Irrgang fb044e6d88
Bumped sinon from 4.4.6 to 7.3.2 (#10400)
refs #9389

- https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md

Breaking changes for Ghost:

- no need to create a sandbox anymore, each file get's it's own sandbox
- just require sinon and use this sandbox
- you can still create separate sandboxes with .createSandbox
- reset single stubs: use .resetHistory instead of .reset

This is a global replace for any sandbox creation.

---

From https://sinonjs.org/releases/v7.2.3/sandbox/

> Default sandbox
> Since sinon@5.0.0, the sinon object is a default sandbox. Unless you have a very advanced setup or need a special configuration, you probably want to just use that one.
2019-01-21 17:53:44 +01:00

128 lines
4.4 KiB
JavaScript

var should = require('should'),
sinon = require('sinon'),
configUtils = require('../../utils/configUtils'),
helpers = require('../../../server/helpers'),
settingsCache = require('../../../server/services/settings/cache');
describe('{{asset}} helper', function () {
var rendered, localSettingsCache = {};
before(function () {
configUtils.set({assetHash: 'abc'});
configUtils.set({useMinFiles: true});
sinon.stub(settingsCache, 'get').callsFake(function (key) {
return localSettingsCache[key];
});
});
after(function () {
configUtils.restore();
sinon.restore();
});
describe('no subdirectory', function () {
it('handles favicon correctly', function () {
rendered = helpers.asset('favicon.ico');
should.exist(rendered);
String(rendered).should.equal('/favicon.ico');
});
it('handles ghost.css for default templates correctly', function () {
rendered = helpers.asset('public/ghost.css');
should.exist(rendered);
String(rendered).should.equal('/public/ghost.css?v=abc');
});
it('handles custom favicon correctly', function () {
localSettingsCache.icon = '/content/images/favicon.png';
// with png
rendered = helpers.asset('favicon.png');
should.exist(rendered);
String(rendered).should.equal('/favicon.png');
localSettingsCache.icon = '/content/images/favicon.ico';
// with ico
rendered = helpers.asset('favicon.ico');
should.exist(rendered);
String(rendered).should.equal('/favicon.ico');
});
it('handles public assets correctly', function () {
localSettingsCache.icon = '';
rendered = helpers.asset('public/asset.js');
should.exist(rendered);
String(rendered).should.equal('/public/asset.js?v=abc');
});
it('handles theme assets correctly', function () {
rendered = helpers.asset('js/asset.js');
should.exist(rendered);
String(rendered).should.equal('/assets/js/asset.js?v=abc');
});
it('handles hasMinFile assets correctly', function () {
rendered = helpers.asset('js/asset.js', {hash: {hasMinFile: true}});
should.exist(rendered);
String(rendered).should.equal('/assets/js/asset.min.js?v=abc');
});
});
describe('with /blog subdirectory', function () {
before(function () {
configUtils.set({url: 'http://localhost:82832/blog'});
});
it('handles favicon correctly', function () {
rendered = helpers.asset('favicon.ico');
should.exist(rendered);
String(rendered).should.equal('/blog/favicon.ico');
});
it('handles ghost.css for default templates correctly', function () {
rendered = helpers.asset('public/ghost.css');
should.exist(rendered);
String(rendered).should.equal('/blog/public/ghost.css?v=abc');
});
it('handles custom favicon correctly', function () {
localSettingsCache.icon = '/content/images/favicon.png';
// with png
rendered = helpers.asset('favicon.png');
should.exist(rendered);
String(rendered).should.equal('/blog/favicon.png');
localSettingsCache.icon = '/content/images/favicon.ico';
// with ico
rendered = helpers.asset('favicon.ico');
should.exist(rendered);
String(rendered).should.equal('/blog/favicon.ico');
});
it('handles public assets correctly', function () {
rendered = helpers.asset('public/asset.js');
should.exist(rendered);
String(rendered).should.equal('/blog/public/asset.js?v=abc');
});
it('handles theme assets correctly', function () {
rendered = helpers.asset('js/asset.js');
should.exist(rendered);
String(rendered).should.equal('/blog/assets/js/asset.js?v=abc');
});
it('handles hasMinFile assets correctly', function () {
rendered = helpers.asset('js/asset.js', {hash: {hasMinFile: true}});
should.exist(rendered);
String(rendered).should.equal('/blog/assets/js/asset.min.js?v=abc');
});
configUtils.restore();
});
});