Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular-devkit/build-angular): fix base href insertion when HTML… #13884

Merged
merged 1 commit into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class IndexHtmlWebpackPlugin {

treeAdapter.appendChild(baseFragment, baseElement);
indexSource.insert(
headElement.__location.startTag.endOffset + 1,
headElement.__location.startTag.endOffset,
parse5.serialize(baseFragment, { treeAdapter }),
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { runTargetSpec } from '@angular-devkit/architect/testing';
import { join, normalize, virtualFs } from '@angular-devkit/core';
import { join, normalize, tags, virtualFs } from '@angular-devkit/core';
import { tap } from 'rxjs/operators';
import { browserTargetSpec, host } from '../utils';

Expand Down Expand Up @@ -35,4 +35,24 @@ describe('Browser Builder base href', () => {
}),
).toPromise().then(done, done.fail);
});

it('should insert base href in the the correct position', (done) => {
host.writeMultipleFiles({
'src/index.html': tags.oneLine`
<html><head><meta charset="UTF-8"></head>
<body><app-root></app-root></body></html>
`,
});

const overrides = { baseHref: '/myUrl' };

runTargetSpec(host, browserTargetSpec, overrides).pipe(
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
tap(() => {
const fileName = join(outputPath, 'index.html');
const content = virtualFs.fileBufferToString(host.scopedSync().read(fileName));
expect(content).toContain('<head><base href="/myUrl"><meta charset="UTF-8"></head>');
}),
).toPromise().then(done, done.fail);
});
});