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
Christopher Kolstad 3409b0c5a0
task: Add Unit test result check task (#3695)
After a Team Retro, one of our squads felt like we needed more data on
our test suites. This is the first effort to make our test results
easier to grab. It uses the test-reporter action to add a github check
to our main build and PR builds with our test results.

This at least should make it easier to parse which tests are failing.
However, it does not give us trends. So it does not yet make it easier
to decide which tests are flaky just from a quick view.

---------

Co-authored-by: Gastón Fournier <gaston@getunleash.io>
2023-05-25 11:03:54 +00:00

63 lines
1.9 KiB
TypeScript

import fs from 'fs';
import path from 'path';
import { rewriteHTML } from './rewriteHTML';
const input = fs
.readFileSync(path.join(__dirname, '../../test/examples', '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,
);
});