From 802930e76c55d6ada1525a334cead9b7f055e652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Thu, 15 Nov 2018 14:51:39 +0800 Subject: [PATCH] fix test script --- package.json | 4 ++-- src/e2e/baseLayout.e2e.js | 36 ++++++++++++------------------------ tests/run-tests.js | 2 +- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index eddfd95c..2e3a1a80 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "dva": "^2.4.0", "enquire-js": "^0.2.1", "hash.js": "^1.1.5", - "jest-puppeteer": "^3.5.1", "lodash": "^4.17.10", "lodash-decorators": "^6.0.0", "memoize-one": "^4.0.0", @@ -57,7 +56,7 @@ "react-router-dom": "^4.3.1" }, "devDependencies": { - "@types/react": "^16.4.16", + "@types/react": "^16.7.6", "@types/react-dom": "^16.0.9", "antd-pro-merge-less": "^0.2.0", "antd-theme-webpack-plugin": "^1.1.8", @@ -76,6 +75,7 @@ "eslint-plugin-react": "^7.11.1", "gh-pages": "^2.0.1", "husky": "^1.1.2", + "jest-puppeteer": "^3.5.1", "lint-staged": "^8.0.4", "merge-umi-mock-data": "^0.0.3", "mockjs": "^1.0.1-beta3", diff --git a/src/e2e/baseLayout.e2e.js b/src/e2e/baseLayout.e2e.js index 8487a758..93574661 100644 --- a/src/e2e/baseLayout.e2e.js +++ b/src/e2e/baseLayout.e2e.js @@ -12,35 +12,23 @@ function formatter(data) { } 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(); + const testPage = path => async () => { + await page.goto(`${BASE_URL}${path}`); + await page.waitForSelector('footer', { + timeout: 2000, }); + const haveFooter = await page.evaluate( + () => document.getElementsByTagName('footer').length > 0 + ); + expect(haveFooter).toBeTruthy(); + }; 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); + const routers = formatter(RouterConfig[1].routes); + routers.forEach(route => { + fit(`test pages ${route}`, testPage(route)); }); }); diff --git a/tests/run-tests.js b/tests/run-tests.js index 0a062352..2fc00c16 100644 --- a/tests/run-tests.js +++ b/tests/run-tests.js @@ -31,7 +31,7 @@ startServer.stdout.on('data', data => { console.log('Development server is started, ready to run tests.'); const testCmd = spawn( /^win/.test(process.platform) ? 'npm.cmd' : 'npm', - ['test', '--', '--maxWorkers=1'], + ['test', '--', '--maxWorkers=1', '--runInBand'], { stdio: 'inherit', } -- GitLab