1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/util/rewriteHTML.test.ts
Christopher Kolstad 3a65847aa7
Migrate to jest (#854)
* Migrate to jest
* Use --force-exit until dns close handle issue https://github.com/facebook/jest/issues/9982

Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
2021-05-28 11:10:24 +02:00

59 lines
2.1 KiB
TypeScript

import { rewriteHTML } from './rewriteHTML';
const input = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="baseUriPath" content="::baseUriPath::" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="unleash" />
<title>Unleash - Enterprise ready feature toggles</title>
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700"
rel="stylesheet"
/>
</head>
<body>
<div id="app"></div>
</body>
<script src="/static/js/2.5ff09a33.chunk.js"></script>
<script src="/static/js/main.6bcf6c41.chunk.js"></script>
</html>`;
test('rewriteHTML substitutes meta tag with existing rewrite value', () => {
const result = rewriteHTML(input, '/hosted');
expect(result.includes(`<meta name="baseUriPath" content="/hosted" />`)).toBe(true);
});
test('rewriteHTML substitutes meta tag with empty value', () => {
const result = rewriteHTML(input, '');
expect(result.includes(`<meta name="baseUriPath" content="" />`)).toBe(true);
});
test('rewriteHTML substitutes asset paths correctly with baseUriPath', () => {
const result = rewriteHTML(input, '/hosted');
expect(result.includes(
`<script src="/hosted/static/js/2.5ff09a33.chunk.js"></script>`,
)).toBe(true);
expect(result.includes(
` <script src="/hosted/static/js/main.6bcf6c41.chunk.js"></script>`,
)).toBe(true);
});
test('rewriteHTML substitutes asset paths correctly without baseUriPath', () => {
const result = rewriteHTML(input, '');
expect(result.includes(
`<script src="/static/js/2.5ff09a33.chunk.js"></script>`,
)).toBe(true);
expect(result.includes(
` <script src="/static/js/main.6bcf6c41.chunk.js"></script>`,
)).toBe(true);
});