mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-23 07:19:58 +08:00
Those 2 packages were still using the wrong scope (@angular-cli) and were not used by anyone outside the CLI. Just moving the code in the main package is enough.
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
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`
|
|
<html>
|
|
<head></head>
|
|
<body></body>
|
|
</html>
|
|
`;
|
|
|
|
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('<body><head></head></body>');
|
|
});
|
|
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`
|
|
<html>
|
|
<head><base href="/"></head>
|
|
<body></body>
|
|
</html>
|
|
`);
|
|
});
|
|
|
|
plugin.apply(compiler);
|
|
});
|
|
|
|
it('should replace href attribute when base tag already exists', function () {
|
|
const plugin = new BaseHrefWebpackPlugin({ baseHref: '/myUrl/' });
|
|
|
|
const compiler = mockCompiler(oneLineTrim`
|
|
<head><base href="/" target="_blank"></head>
|
|
<body></body>
|
|
`, (x: any, htmlPluginData: any) => {
|
|
expect(htmlPluginData.html).toEqual(oneLineTrim`
|
|
<head><base href="/myUrl/" target="_blank"></head>
|
|
<body></body>
|
|
`);
|
|
});
|
|
plugin.apply(compiler);
|
|
});
|
|
});
|