1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/src/lib/util/rewriteHTML.test.ts
sjaanus a1ce89bedc
Merge frontend with backend (#1962)
* fix: use the frontend dir from the backend

* Build is now working

* Fix workflows

* Fix workflows

* Fix build PRs

* Test coverage workflow

* Test coverage

* Test coverage run

* Fix jest report

* refactor: add missing frontend build

* refactor: ignore frontend dir for coverage

* refactor: run frontend build in PRs

* refactor: run backend tests in PRs

* Revert "refactor: run backend tests in PRs"

This reverts commit 22cabddfd1.

* refactor: remove unused frontend build file

* refactor: test workflows in PR

* refactor: use a prepare script for the frontend

* refactor: simplify yarn build scripts

* refactor: fix check-release script

* Revert "refactor: test workflows in PR"

This reverts commit 496ae19404.

* refactor: remove unused gitignore lines

* refactor: remove renovate config from the frontend repo

* refactor: remove frontend repo license

* refactor: remove frontend repo changelog

* refactor: update frontend repo readme

* refactor: add frontend node_modules to dockerignore

* refactor: update the docker yarn.lock snapshot

Co-authored-by: olav <mail@olav.io>
2022-08-26 07:25:31 +00:00

64 lines
2.0 KiB
TypeScript

import fs from 'fs';
import path from 'path';
import { rewriteHTML } from './rewriteHTML';
import { findPublicFolder } from './findPublicFolder';
const input = fs
.readFileSync(path.join(findPublicFolder(), 'index.html'))
.toString();
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 type="module" crossorigin src="/hosted/static/index',
),
).toBe(true);
});
test('rewriteHTML substitutes asset paths correctly without baseUriPath', () => {
const result = rewriteHTML(input, '');
expect(
result.includes('<script type="module" crossorigin src="/static/index'),
).toBe(true);
});
test('rewriteHTML substitutes asset paths correctly with cdnPrefix', () => {
const result = rewriteHTML(input, '', 'https://cdn.getunleash.io/v4.1.0');
expect(
result.includes(
'<script type="module" crossorigin src="https://cdn.getunleash.io/v4.1.0/static/index',
),
).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" />',
),
).toBe(true);
});
test('rewriteHTML sets favicon path to root', () => {
const result = rewriteHTML(input, '');
expect(result.includes('<link rel="icon" href="/favicon.ico" />')).toBe(
true,
);
});