baseLayout.e2e.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const { uniq } = require('lodash');
  2. const RouterConfig = require('../../config/config').default.routes;
  3. const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
  4. const getBrowser = require('./getBrowser');
  5. function formatter(routes, parentPath = '') {
  6. const fixedParentPath = parentPath.replace(/\/{1,}/g, '/');
  7. let result = [];
  8. routes.forEach((item) => {
  9. if (item.path) {
  10. result.push(`${fixedParentPath}/${item.path}`.replace(/\/{1,}/g, '/'));
  11. }
  12. if (item.routes) {
  13. result = result.concat(
  14. formatter(item.routes, item.path ? `${fixedParentPath}/${item.path}` : parentPath),
  15. );
  16. }
  17. });
  18. return uniq(result.filter((item) => !!item));
  19. }
  20. let browser;
  21. let page;
  22. beforeAll(async () => {
  23. browser = await getBrowser();
  24. });
  25. beforeEach(async () => {
  26. page = await browser.newPage();
  27. await page.goto(`${BASE_URL}`);
  28. await page.evaluate(() => {
  29. localStorage.setItem('antd-pro-authority', '["admin"]');
  30. });
  31. });
  32. describe('Ant Design Pro E2E test', () => {
  33. const testPage = (path) => async () => {
  34. await page.goto(`${BASE_URL}${path}`);
  35. await page.waitForSelector('footer', {
  36. timeout: 2000,
  37. });
  38. const haveFooter = await page.evaluate(
  39. () => document.getElementsByTagName('footer').length > 0,
  40. );
  41. expect(haveFooter).toBeTruthy();
  42. };
  43. const routers = formatter(RouterConfig);
  44. routers.forEach((route) => {
  45. it(`test pages ${route}`, testPage(route));
  46. });
  47. });
  48. afterAll(() => {
  49. browser.close();
  50. });