mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
refactor: use vite html in test (#1561)
This commit is contained in:
parent
0fd26e26bc
commit
ce2714713a
@ -1,86 +1,43 @@
|
||||
import { rewriteHTML } from './rewriteHTML';
|
||||
|
||||
const input = `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="::faviconPrefix::/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>`;
|
||||
const input = `<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="::faviconPrefix::/favicon.ico"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="baseUriPath" content="::baseUriPath::"/><meta name="cdnPrefix" content="::cdnPrefix::"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="description" content="unleash"/><title>Unleash</title><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/><link href="https://fonts.googleapis.com/css2?family=Sen:wght@400;700;800&display=swap" rel="stylesheet"/><script defer="defer" src="/static/js/main.84c7ff99.js"></script><link href="/static/css/main.9558c71e.css" rel="stylesheet"></head><body><div id="app"></div></body></html>`;
|
||||
|
||||
test('rewriteHTML substitutes meta tag with existing rewrite value', () => {
|
||||
const result = rewriteHTML(input, '/hosted');
|
||||
expect(
|
||||
result.includes('<meta name="baseUriPath" content="/hosted" />'),
|
||||
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,
|
||||
);
|
||||
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);
|
||||
expect(result.includes('<script defer="defer" src="/hosted/')).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);
|
||||
expect(result.includes('<script defer="defer" src="/static/js/')).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('rewriteHTML swaps out faviconPath if cdnPrefix is set', () => {
|
||||
const result = rewriteHTML(input, '', 'https://cdn.getunleash.io/v4.1.0');
|
||||
expect(
|
||||
result.includes(
|
||||
'<link rel="icon" href="https://cdn.getunleash.io/favicon.ico" />',
|
||||
'<link rel="icon" href="https://cdn.getunleash.io/favicon.ico"/>',
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test('rewriteHTML sets favicon path to root', () => {
|
||||
const result = rewriteHTML(input, '');
|
||||
expect(result.includes('<link rel="icon" href="/favicon.ico" />')).toBe(
|
||||
expect(result.includes('<link rel="icon" href="/favicon.ico"/>')).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user