41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import { readFileSync } from 'node:fs';
|
|
import { runInNewContext } from 'node:vm';
|
|
|
|
const customBrand = {
|
|
INSTALLATION_NAME: 'Acme Support',
|
|
BRAND_NAME: 'Acme',
|
|
LOGO: '/acme/logo.svg',
|
|
LOGO_DARK: '/acme/logo-dark.svg',
|
|
LOGO_THUMBNAIL: '/acme/icon.svg',
|
|
};
|
|
|
|
const initializeEntrypoint = filename => {
|
|
const html = readFileSync(filename, 'utf8');
|
|
const inlineScript = html.match(
|
|
/<script(?: type="module")?>\s*([\s\S]*?)<\/script>/
|
|
);
|
|
const runtimeConfigIndex = html.indexOf('/runtime-config.js');
|
|
|
|
expect(runtimeConfigIndex).toBeGreaterThan(-1);
|
|
expect(runtimeConfigIndex).toBeLessThan(inlineScript.index);
|
|
|
|
const entrypointWindow = {
|
|
__GOCHAT_CONFIG__: { globalConfig: customBrand },
|
|
location: { search: '' },
|
|
};
|
|
runInNewContext(inlineScript[1], {
|
|
window: entrypointWindow,
|
|
navigator: { userAgent: 'test' },
|
|
URLSearchParams,
|
|
localStorage: { getItem: () => null, setItem: () => {} },
|
|
});
|
|
return entrypointWindow.globalConfig;
|
|
};
|
|
|
|
it.each(['widget.html', 'super_admin.html'])(
|
|
'applies custom runtime branding in %s',
|
|
filename => {
|
|
expect(initializeEntrypoint(filename)).toMatchObject(customBrand);
|
|
}
|
|
);
|