Bladeren bron

:white_check_mark: improve e2e test

afc163 6 jaren geleden
bovenliggende
commit
f266f6602d
5 gewijzigde bestanden met toevoegingen van 17 en 23 verwijderingen
  1. 0 1
      jest.config.js
  2. 0 1
      package.json
  3. 17 16
      src/e2e/baseLayout.e2e.js
  4. 0 4
      src/e2e/topMenu.e2e.js
  5. 0 1
      tests/setupTests.js

+ 0 - 1
jest.config.js

@@ -1,7 +1,6 @@
 module.exports = {
   testURL: 'http://localhost:8000',
   preset: 'jest-puppeteer',
-  extraSetupFiles: ['./tests/setupTests.js'],
   globals: {
     ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false,
   },

+ 0 - 1
package.json

@@ -106,7 +106,6 @@
     "import-sort-parser-typescript": "^6.0.0",
     "import-sort-style-module": "^6.0.0",
     "jest-puppeteer": "^4.2.0",
-    "jsdom-global": "^3.0.2",
     "lint-staged": "^9.0.0",
     "mockjs": "^1.0.1-beta3",
     "netlify-lambda": "^1.4.13",

+ 17 - 16
src/e2e/baseLayout.e2e.js

@@ -1,21 +1,25 @@
 const RouterConfig = require('../../config/config').default.routes;
+const { uniq } = require('lodash');
 
 const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
 
-function formatter(data) {
-  return data
-    .reduce((pre, item) => {
-      if (item.routes) {
-        pre.push(item.routes[0].path);
-      } else {
-        pre.push(item.path);
-      }
-      return pre;
-    }, [])
-    .filter(item => item);
+function formatter(routes, parentPath = '') {
+  const fixedParentPath = parentPath.replace(/\/{1,}/g, '/');
+  let result = [];
+  routes.forEach(item => {
+    if (item.path) {
+      result.push(`${fixedParentPath}/${item.path}`.replace(/\/{1,}/g, '/'));
+    }
+    if (item.routes) {
+      result = result.concat(
+        formatter(item.routes, item.path ? `${fixedParentPath}/${item.path}` : parentPath),
+      );
+    }
+  });
+  return uniq(result.filter(item => !!item));
 }
 
-describe('Homepage', () => {
+describe('Ant Design Pro E2E test', () => {
   const testPage = path => async () => {
     await page.goto(`${BASE_URL}${path}`);
     await page.waitForSelector('footer', {
@@ -27,11 +31,8 @@ describe('Homepage', () => {
     expect(haveFooter).toBeTruthy();
   };
 
-  beforeAll(async () => {
-    jest.setTimeout(1000000);
-    await page.setCacheEnabled(false);
-  });
   const routers = formatter(RouterConfig);
+  console.log('routers', routers);
   routers.forEach(route => {
     it(`test pages ${route}`, testPage(route));
   });

+ 0 - 4
src/e2e/topMenu.e2e.js

@@ -1,10 +1,6 @@
 const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
 
 describe('Homepage', () => {
-  beforeAll(async () => {
-    jest.setTimeout(1000000);
-  });
-
   it('topmenu should have footer', async () => {
     const params = '/form/basic-form?navTheme=light&layout=topmenu';
     await page.goto(`${BASE_URL}${params}`);

+ 0 - 1
tests/setupTests.js

@@ -1 +0,0 @@
-import 'jsdom-global/register';