blob: 49dfd846c3ed647f984c4dd98ebfa8f783d4410e [file] [log] [blame]
/**
* @license
* Copyright 2020 The Go Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
import puppeteer, { Page } from 'puppeteer';
import { toMatchImageSnapshot } from 'jest-image-snapshot';
expect.extend({ toMatchImageSnapshot });
describe('Homepage', () => {
const baseUrl = process.env.FRONTEND_URL ?? '';
let page: Page;
let browser: puppeteer.Browser;
beforeAll(async () => {
browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-dev-shm-usage'],
defaultViewport: { height: 800, width: 1280 },
});
});
beforeEach(async () => {
page = await browser.newPage();
await page.goto(baseUrl);
});
afterEach(async () => await page.close());
afterAll(async () => await browser.close());
test('accessibility tree matches snapshot', async () => {
const a11yTree = await page.accessibility.snapshot();
expect(a11yTree).toMatchSnapshot();
});
test('desktop viewport matches image snapshot', async () => {
const image = await page.screenshot({ fullPage: true });
expect(image).toMatchImageSnapshot();
});
test('mobile viewport matches image snapshot', async () => {
await page.emulate(puppeteer.devices['Pixel 2']);
const image = await page.screenshot({ fullPage: true });
expect(image).toMatchImageSnapshot();
});
});