2022-05-10 15:47:54 +02:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2021-04-30 15:31:54 +02:00
|
|
|
import { rewriteHTML } from './rewriteHTML';
|
2022-08-26 09:25:31 +02:00
|
|
|
import { findPublicFolder } from './findPublicFolder';
|
2021-04-30 15:31:54 +02:00
|
|
|
|
2022-08-26 09:25:31 +02:00
|
|
|
const input = fs
|
|
|
|
.readFileSync(path.join(findPublicFolder(), 'index.html'))
|
|
|
|
.toString();
|
2021-04-30 15:31:54 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('rewriteHTML substitutes meta tag with existing rewrite value', () => {
|
2021-04-30 15:31:54 +02:00
|
|
|
const result = rewriteHTML(input, '/hosted');
|
2021-08-12 15:04:37 +02:00
|
|
|
expect(
|
2022-05-10 14:05:53 +02:00
|
|
|
result.includes('<meta name="baseUriPath" content="/hosted" />'),
|
2021-08-12 15:04:37 +02:00
|
|
|
).toBe(true);
|
2021-04-30 15:31:54 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('rewriteHTML substitutes meta tag with empty value', () => {
|
2021-04-30 15:31:54 +02:00
|
|
|
const result = rewriteHTML(input, '');
|
2022-05-10 14:05:53 +02:00
|
|
|
expect(result.includes('<meta name="baseUriPath" content="" />')).toBe(
|
|
|
|
true,
|
|
|
|
);
|
2021-04-30 15:31:54 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('rewriteHTML substitutes asset paths correctly with baseUriPath', () => {
|
2021-04-30 15:31:54 +02:00
|
|
|
const result = rewriteHTML(input, '/hosted');
|
2022-05-10 14:05:53 +02:00
|
|
|
expect(
|
|
|
|
result.includes(
|
2022-05-10 15:47:54 +02:00
|
|
|
'<script type="module" crossorigin src="/hosted/static/index',
|
2022-05-10 14:05:53 +02:00
|
|
|
),
|
|
|
|
).toBe(true);
|
2021-04-30 15:31:54 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('rewriteHTML substitutes asset paths correctly without baseUriPath', () => {
|
2021-04-30 15:31:54 +02:00
|
|
|
const result = rewriteHTML(input, '');
|
2022-05-10 14:05:53 +02:00
|
|
|
expect(
|
2022-05-10 15:47:54 +02:00
|
|
|
result.includes('<script type="module" crossorigin src="/static/index'),
|
2022-05-10 14:05:53 +02:00
|
|
|
).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('rewriteHTML substitutes asset paths correctly with cdnPrefix', () => {
|
|
|
|
const result = rewriteHTML(input, '', 'https://cdn.getunleash.io/v4.1.0');
|
|
|
|
expect(
|
|
|
|
result.includes(
|
2022-05-10 15:47:54 +02:00
|
|
|
'<script type="module" crossorigin src="https://cdn.getunleash.io/v4.1.0/static/index',
|
2022-05-10 14:05:53 +02:00
|
|
|
),
|
|
|
|
).toBe(true);
|
2021-04-30 15:31:54 +02:00
|
|
|
});
|
2022-05-02 12:49:48 +02:00
|
|
|
|
|
|
|
test('rewriteHTML swaps out faviconPath if cdnPrefix is set', () => {
|
|
|
|
const result = rewriteHTML(input, '', 'https://cdn.getunleash.io/v4.1.0');
|
|
|
|
expect(
|
|
|
|
result.includes(
|
2022-05-10 14:05:53 +02:00
|
|
|
'<link rel="icon" href="https://cdn.getunleash.io/favicon.ico" />',
|
2022-05-02 12:49:48 +02:00
|
|
|
),
|
|
|
|
).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('rewriteHTML sets favicon path to root', () => {
|
|
|
|
const result = rewriteHTML(input, '');
|
2022-05-10 14:05:53 +02:00
|
|
|
expect(result.includes('<link rel="icon" href="/favicon.ico" />')).toBe(
|
2022-05-02 12:49:48 +02:00
|
|
|
true,
|
|
|
|
);
|
|
|
|
});
|