baseLayout.e2e.js 1.07 KB
Newer Older
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
import RouterConfig from '../../config/router.config';

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

function formatter(data) {
  return data
    .reduce((pre, item) => {
      pre.push(item.path);
      return pre;
    }, [])
    .filter(item => item);
}

describe('Homepage', async () => {
  const testPage = path =>
    new Promise(async reslove => {
      console.log(`test ${path}`);
      await page.goto(`${BASE_URL}${path}`, {
        timeout: 600000,
      });
      await page.waitForSelector('footer', {
        timeout: 600000,
      });
      reslove();
    });

  beforeAll(async () => {
    jest.setTimeout(1000000);
    await page.setCacheEnabled(false);
  });

  it(`test pages`, async () => {
    const routers = formatter(RouterConfig[1].routes);
    const testAll = index =>
      new Promise(async reslove => {
        await testPage(routers[index]);
        if (index < routers.length - 1) {
          const newIndex = index + 1;
          await testAll(newIndex);
          reslove();
        }
        reslove();
      });
    await testAll(0);
  });
});