Skip to content

Commit

Permalink
fix(puppeteer-page): add existing head content to page
Browse files Browse the repository at this point in the history
Read the existing head element content, add that content to the e2e page that is being created. This prevents a user losing script or style tags that may have been added to the page before using the setContent method. Fixes ionic-team#3229
  • Loading branch information
Trendy committed Feb 25, 2022
1 parent 5dccc85 commit 1b00732
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/testing/puppeteer/puppeteer-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ async function e2eSetContent(page: E2EPageInternal, html: string, options: WaitF

const output: string[] = [];

const headContent: string = await page.$eval('head', async (headElement: Element) => {
return headElement ? headElement.innerHTML : '';
});

const appScriptUrl = env.__STENCIL_APP_SCRIPT_URL__;
if (typeof appScriptUrl !== 'string') {
throw new Error('invalid e2eSetContent() app script url');
Expand All @@ -222,6 +226,8 @@ async function e2eSetContent(page: E2EPageInternal, html: string, options: WaitF
output.push(`<html>`);
output.push(`<head>`);

output.push(headContent);

const appStyleUrl = env.__STENCIL_APP_STYLE_URL__;
if (typeof appStyleUrl === 'string') {
output.push(`<link rel="stylesheet" href="${appStyleUrl}">`);
Expand Down

0 comments on commit 1b00732

Please sign in to comment.