From 3cfbae3b31e5fdf665f312be4c11b5dcca25987c Mon Sep 17 00:00:00 2001 From: jim Date: Fri, 18 May 2018 15:16:04 +0800 Subject: [PATCH] fix ci --- .babelrc.js | 15 ++++- package.json | 6 +- src/components/SiderMenu/SilderMenu.test.js | 73 ++++++++++++++------- src/e2e/home.e2e.js | 4 +- src/e2e/login.e2e.js | 4 +- tests/run-tests.js | 3 +- 6 files changed, 69 insertions(+), 36 deletions(-) diff --git a/.babelrc.js b/.babelrc.js index 96df8001..20a0892b 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -1,12 +1,21 @@ +const path = require('path'); + module.exports = { plugins: [ [ - 'babel-plugin-module-resolver', + 'module-resolver', { alias: { - components: './src/components', + components: path.join(__dirname, './src/components'), }, }, ], + [ + 'import', + { + libraryName: 'antd', + style: true, // or 'css' + }, + ], ], -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index bdd6af68..994e37b0 100755 --- a/package.json +++ b/package.json @@ -75,14 +75,14 @@ "pro-download": "^1.0.1", "redbox-react": "^1.5.0", "regenerator-runtime": "^0.11.1", - "roadhog": "^2.3.0", - "roadhog-api-doc": "^1.0.2", + "roadhog": "^2.4.1", + "roadhog-api-doc": "^1.0.3", "stylelint": "^8.4.0", "stylelint-config-prettier": "^3.0.4", "stylelint-config-standard": "^18.0.0" }, "optionalDependencies": { - "puppeteer": "^1.1.1" + "puppeteer": "^1.4.0" }, "lint-staged": { "**/*.{js,jsx,less}": [ diff --git a/src/components/SiderMenu/SilderMenu.test.js b/src/components/SiderMenu/SilderMenu.test.js index 6bff551b..8f01f669 100644 --- a/src/components/SiderMenu/SilderMenu.test.js +++ b/src/components/SiderMenu/SilderMenu.test.js @@ -1,49 +1,72 @@ import { urlToList } from '../_utils/pathTools'; -import { getFlatMenuKeys, getMeunMatchKeys } from './SiderMenu'; - -const menu = [{ - path: '/dashboard', - children: [{ - path: '/dashboard/name', - }], -}, { - path: '/userinfo', - children: [{ - path: '/userinfo/:id', - children: [{ - path: '/userinfo/:id/info', - }], - }], -}]; +import { getFlatMenuKeys, getMenuMatchKeys } from './SiderMenu'; + +const menu = [ + { + path: '/dashboard', + children: [ + { + path: '/dashboard/name', + }, + ], + }, + { + path: '/userinfo', + children: [ + { + path: '/userinfo/:id', + children: [ + { + path: '/userinfo/:id/info', + }, + ], + }, + ], + }, +]; const flatMenuKeys = getFlatMenuKeys(menu); describe('test convert nested menu to flat menu', () => { it('simple menu', () => { - expect(flatMenuKeys).toEqual( - ['/dashboard', '/dashboard/name', '/userinfo', '/userinfo/:id', '/userinfo/:id/info'] - ); - }) + expect(flatMenuKeys).toEqual([ + '/dashboard', + '/dashboard/name', + '/userinfo', + '/userinfo/:id', + '/userinfo/:id/info', + ]); + }); }); describe('test menu match', () => { it('simple path', () => { - expect(getMeunMatchKeys(flatMenuKeys, urlToList('/dashboard'))).toEqual(['/dashboard']); + expect(getMenuMatchKeys(flatMenuKeys, urlToList('/dashboard'))).toEqual(['/dashboard']); }); it('error path', () => { - expect(getMeunMatchKeys(flatMenuKeys, urlToList('/dashboardname'))).toEqual([]); + expect(getMenuMatchKeys(flatMenuKeys, urlToList('/dashboardname'))).toEqual([]); }); it('Secondary path', () => { - expect(getMeunMatchKeys(flatMenuKeys, urlToList('/dashboard/name'))).toEqual(['/dashboard', '/dashboard/name']); + expect(getMenuMatchKeys(flatMenuKeys, urlToList('/dashboard/name'))).toEqual([ + '/dashboard', + '/dashboard/name', + ]); }); it('Parameter path', () => { - expect(getMeunMatchKeys(flatMenuKeys, urlToList('/userinfo/2144'))).toEqual(['/userinfo', '/userinfo/:id']); + expect(getMenuMatchKeys(flatMenuKeys, urlToList('/userinfo/2144'))).toEqual([ + '/userinfo', + '/userinfo/:id', + ]); }); it('three parameter path', () => { - expect(getMeunMatchKeys(flatMenuKeys, urlToList('/userinfo/2144/info'))).toEqual(['/userinfo', '/userinfo/:id', '/userinfo/:id/info']); + expect(getMenuMatchKeys(flatMenuKeys, urlToList('/userinfo/2144/info'))).toEqual([ + '/userinfo', + '/userinfo/:id', + '/userinfo/:id/info', + ]); }); }); diff --git a/src/e2e/home.e2e.js b/src/e2e/home.e2e.js index 1a5d9513..50447a4a 100644 --- a/src/e2e/home.e2e.js +++ b/src/e2e/home.e2e.js @@ -2,9 +2,9 @@ import puppeteer from 'puppeteer'; describe('Homepage', () => { it('it should have logo text', async () => { - const browser = await puppeteer.launch(); + const browser = await puppeteer.launch({ args: ['--no-sandbox'] }); const page = await browser.newPage(); - await page.goto('http://localhost:8000'); + await page.goto('http://localhost:8000', { waitUntil: 'networkidle2' }); await page.waitForSelector('h1'); const text = await page.evaluate(() => document.body.innerHTML); expect(text).toContain('

Ant Design Pro

'); diff --git a/src/e2e/login.e2e.js b/src/e2e/login.e2e.js index 5211a3b4..a102a351 100644 --- a/src/e2e/login.e2e.js +++ b/src/e2e/login.e2e.js @@ -5,12 +5,12 @@ describe('Login', () => { let page; beforeAll(async () => { - browser = await puppeteer.launch(); + browser = await puppeteer.launch({ args: ['--no-sandbox'] }); }); beforeEach(async () => { page = await browser.newPage(); - await page.goto('http://localhost:8000/#/user/login'); + await page.goto('http://localhost:8000/#/user/login', { waitUntil: 'networkidle2' }); await page.evaluate(() => window.localStorage.setItem('antd-pro-authority', 'guest')); }); diff --git a/tests/run-tests.js b/tests/run-tests.js index d48a759f..7a51228c 100644 --- a/tests/run-tests.js +++ b/tests/run-tests.js @@ -30,8 +30,9 @@ startServer.stdout.on('data', data => { const testCmd = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['test'], { stdio: 'inherit', }); - testCmd.on('exit', () => { + testCmd.on('exit', code => { startServer.kill(); + process.exit(code); }); } }); -- GitLab