Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxakuru committed Dec 15, 2022
1 parent 977e98f commit 66c8d55
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ logs/*
node_modules/*

helix-importer-ui
.DS_Store
14 changes: 9 additions & 5 deletions scripts/lib-franklin.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ export async function waitForLCP(lcpBlocks) {
/**
* loads a block named 'header' into header
*/

export function loadHeader(header) {
const headerBlock = buildBlock('header', '');
header.append(headerBlock);
Expand All @@ -538,7 +537,6 @@ export function loadHeader(header) {
/**
* loads a block named 'footer' into footer
*/

export function loadFooter(footer) {
const footerBlock = buildBlock('footer', '');
footer.append(footerBlock);
Expand All @@ -547,12 +545,12 @@ export function loadFooter(footer) {
}

/**
* init block utils
* setup block utils
*/

function init() {
export function setup() {
window.hlx = window.hlx || {};
window.hlx.codeBasePath = '';
window.hlx.lighthouse = new URLSearchParams(window.location.search).get('lighthouse') === 'on';

const scriptEl = document.querySelector('script[src$="/scripts/scripts.js"]');
if (scriptEl) {
Expand All @@ -563,7 +561,13 @@ function init() {
console.log(error);
}
}
}

/**
* auto init
*/
function init() {
setup();
sampleRUM('top');

window.addEventListener('load', () => sampleRUM('load'));
Expand Down
9 changes: 7 additions & 2 deletions test/scripts/scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@

import { readFile } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';
import sinon from 'sinon';

/** @type {import('./types').Scripts} */
let scripts;
/** @type {import('./types').LibFranklin} */
let lib;

document.body.innerHTML = await readFile({ path: './dummy.html' });
document.head.innerHTML = await readFile({ path: './head.html' });

describe('Core Helix features', () => {
before(async () => {
scripts = await import('../../scripts/scripts.js');
lib = await import('../../scripts/lib-franklin.js');

document.body.innerHTML = await readFile({ path: './body.html' });
});

it('Initializes window.hlx', async () => {
// simulate code base path and turn on lighthouse
/* needs fixing
document.head.appendChild(document.createElement('script')).src = '/foo/scripts/scripts.js';
window.history.pushState({}, '', `${window.location.href}&lighthouse=on`);
lib.setup();

expect(window.hlx.codeBasePath).to.equal('/foo');
expect(window.hlx.lighthouse).to.equal(true);
Expand All @@ -32,7 +38,6 @@ describe('Core Helix features', () => {
window.hlx.codeBasePath = '';
window.hlx.lighthouse = false;
Array.from(document.querySelectorAll('script')).pop().remove();
*/
});

it('Adds favicon', async () => {
Expand Down
5 changes: 5 additions & 0 deletions test/scripts/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type * as ScriptsModule from '../../scripts/scripts';
import type * as LibModule from '../../scripts/lib-franklin';

export type Scripts = typeof ScriptsModule;
export type LibFranklin = typeof LibModule;

0 comments on commit 66c8d55

Please sign in to comment.