Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barjin committed Jun 18, 2024
1 parent 137ed57 commit f20915e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/core/playwright_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let serverAddress = 'http://localhost:';
let port: number;
let server: Server;

const launchContext = { launchOptions: { headless: true } };
const launchContext = { launchOptions: { headless: false } };

beforeAll(async () => {
[server, port] = await runExampleComServer();
Expand Down Expand Up @@ -159,6 +159,22 @@ describe('playwrightUtils', () => {
}
});

test('parseWithCheerio() iframe expansion works', async () => {
const browser = await launchPlaywright(launchContext);

try {
const page = await browser.newPage();
await page.goto(new URL('/special/outside-iframe', serverAddress).toString());

const $ = await playwrightUtils.parseWithCheerio(page);

const headings = $('h1').map((i, el) => $(el).text()).get();
expect(headings).toEqual(['Outside iframe', 'In iframe']);
} finally {
await browser.close();
}
});

describe('blockRequests()', () => {
let browser: Browser = null;
beforeAll(async () => {
Expand Down
16 changes: 16 additions & 0 deletions test/core/puppeteer_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ describe('puppeteerUtils', () => {
}
});

test('parseWithCheerio() iframe expansion works', async () => {
const browser = await launchPuppeteer(launchContext);

try {
const page = await browser.newPage();
await page.goto(new URL('/special/outside-iframe', serverAddress).toString());

const $ = await puppeteerUtils.parseWithCheerio(page);

const headings = $('h1').map((i, el) => $(el).text()).get();
expect(headings).toEqual(['Outside iframe', 'In iframe']);
} finally {
await browser.close();
}
});

describe('blockRequests()', () => {
let browser: Browser = null;
beforeAll(async () => {
Expand Down
30 changes: 30 additions & 0 deletions test/shared/_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ console.log('Hello world!');
</div>
</body>
</html>`,
outsideIframe: `
<!DOCTYPE html>
<html>
<head>
<title>Outside iframe</title>
</head>
<body>
<h1>Outside iframe</h1>
<iframe src="./inside-iframe"></iframe>
</body>
</html>`,
insideIframe: `
<!DOCTYPE html>
<html>
<head>
<title>In iframe</title>
</head>
<body>
<h1>In iframe</h1>
<p>Some content from inside of an iframe.</p>
</body>
</html>`,
};

export async function runExampleComServer(): Promise<[Server, number]> {
Expand Down Expand Up @@ -268,6 +290,14 @@ export async function runExampleComServer(): Promise<[Server, number]> {
special.get('/cloudflareBlocking', async (_req, res) => {
res.type('html').status(403).send(responseSamples.cloudflareBlocking);
});

special.get('/outside-iframe', (_req, res) => {
res.type('html').send(responseSamples.outsideIframe);
});

special.get('/inside-iframe', (_req, res) => {
res.type('html').send(responseSamples.insideIframe);
});
})();

// "cacheable" site with one page, scripts and stylesheets
Expand Down

0 comments on commit f20915e

Please sign in to comment.