0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/packages/middleware/test/template.test.ts

70 lines
1.7 KiB
TypeScript
Raw Normal View History

import template from '../src/middlewares/web/utils/template';
const manifest = require('./partials/manifest/manifest.json');
// manifest expected to have leading slash
// see packages\middleware\test\partials\manifest\manifest.json
const exampleManifest = {
css: ['main.css'],
js: ['runtime.js', 'main.js'],
ico: 'favicon.ico',
};
// "base" is expected to be result of getPublicUrl
// i.e. it must be valid URL with trailing slash
describe('template', () => {
test('custom render', () => {
2021-04-02 08:59:47 -05:00
expect(
template({ options: { base: 'http://domain.com/' }, manifest: exampleManifest }, manifest)
2021-04-02 08:59:47 -05:00
).toMatchSnapshot();
});
test('custom title', () => {
expect(
2021-04-02 08:59:47 -05:00
template(
{ options: { base: 'http://domain.com/', title: 'foo title' }, manifest: exampleManifest },
2021-04-02 08:59:47 -05:00
manifest
)
).toMatchSnapshot();
});
test('meta scripts', () => {
expect(
template(
{
options: { base: 'http://domain.com/' },
2021-04-02 08:59:47 -05:00
metaScripts: [`<style>.someclass{font-size:10px;}</style>`],
manifest: exampleManifest,
},
manifest
)
).toMatchSnapshot();
});
test('custom body after', () => {
expect(
2021-04-02 08:59:47 -05:00
template(
{
options: { base: 'http://domain.com/' },
2021-04-02 08:59:47 -05:00
scriptsBodyAfter: [`<script src="foo"/>`],
manifest: exampleManifest,
},
manifest
)
).toMatchSnapshot();
});
test('custom body before', () => {
expect(
template(
{
options: { base: 'http://domain.com/' },
2021-04-02 08:59:47 -05:00
scriptsbodyBefore: [`<script src="fooBefore"/>`, `<script src="barBefore"/>`],
manifest: exampleManifest,
},
manifest
)
).toMatchSnapshot();
});
});