layout.e2e.js 1.06 KB
Newer Older
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
1 2 3
import puppeteer from 'puppeteer';
import RouterConfig from '../../config/router.config';

4 5
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;

ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
function formatter(data) {
  return data
    .reduce((pre, item) => {
      if (item.routes) {
        return pre.concat(formatter(item.routes));
      }
      pre.push(item.path);
      return pre;
    }, [])
    .filter(item => item);
}

describe('Homepage', () => {
  let browser;
  let page;

afc163's avatar
afc163 committed
22 23 24 25 26 27 28
  const testPage = path => async () => {
    await page.goto(`${BASE_URL}${path}`, { waitUntil: 'networkidle2' });
    const haveFooter = await page.evaluate(
      () => document.getElementsByTagName('footer').length > 0
    );
    expect(haveFooter).toBeTruthy();
  };
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
29 30

  beforeAll(async () => {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
31
    jest.setTimeout(1000000);
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
32 33 34 35
    browser = await puppeteer.launch({ args: ['--no-sandbox'] });
    page = await browser.newPage();
  });

afc163's avatar
afc163 committed
36 37 38 39
  RouterConfig.forEach(({ routes = [] }) => {
    formatter(routes).forEach(route => {
      it(`test pages ${route}`, testPage(route));
    });
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
40 41 42 43
  });

  afterAll(() => browser.close());
});