From f266f6602d4efe9a5de44e6a503f5c5aadc6d1bb Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 4 Jul 2019 15:34:28 +0800 Subject: [PATCH] :white_check_mark: improve e2e test --- jest.config.js | 1 - package.json | 1 - src/e2e/baseLayout.e2e.js | 33 +++++++++++++++++---------------- src/e2e/topMenu.e2e.js | 4 ---- tests/setupTests.js | 1 - 5 files changed, 17 insertions(+), 23 deletions(-) delete mode 100644 tests/setupTests.js diff --git a/jest.config.js b/jest.config.js index c06625f4..502fe338 100644 --- a/jest.config.js +++ b/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, }, diff --git a/package.json b/package.json index edccb48a..da58d9dd 100644 --- a/package.json +++ b/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", diff --git a/src/e2e/baseLayout.e2e.js b/src/e2e/baseLayout.e2e.js index 589e76ce..78c500c7 100644 --- a/src/e2e/baseLayout.e2e.js +++ b/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)); }); diff --git a/src/e2e/topMenu.e2e.js b/src/e2e/topMenu.e2e.js index 09f2987f..7c5f8556 100644 --- a/src/e2e/topMenu.e2e.js +++ b/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}`); diff --git a/tests/setupTests.js b/tests/setupTests.js deleted file mode 100644 index 1b15573e..00000000 --- a/tests/setupTests.js +++ /dev/null @@ -1 +0,0 @@ -import 'jsdom-global/register';