import {oneLineTrim} from 'common-tags'; import {BaseHrefWebpackPlugin} from './base-href-webpack-plugin'; function mockCompiler(indexHtml: string, callback: Function) { return { plugin: function (event: any, compilerCallback: Function) { const compilation = { plugin: function (hook: any, compilationCallback: Function) { const htmlPluginData = { html: indexHtml }; compilationCallback(htmlPluginData, callback); } }; compilerCallback(compilation); } }; } describe('base href webpack plugin', () => { const html = oneLineTrim`
`; it('should do nothing when baseHref is null', () => { const plugin = new BaseHrefWebpackPlugin({ baseHref: null }); const compiler = mockCompiler(html, (x: any, htmlPluginData: any) => { expect(htmlPluginData.html).toEqual(''); }); plugin.apply(compiler); }); it('should insert base tag when not exist', function () { const plugin = new BaseHrefWebpackPlugin({ baseHref: '/' }); const compiler = mockCompiler(html, (x: any, htmlPluginData: any) => { expect(htmlPluginData.html).toEqual(oneLineTrim`