diff --git a/.babelrc.js b/.babelrc.js index 96df80013f0ad6a1e734cfae1def7407e022e720..20a0892bb2d10d31f820b3f6e4b164a791aedc69 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 bdd6af68e0fd485b10b5970a29c8f9f38b2a12f9..994e37b041034074445a37e3bf5b394a028c61a9 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 6bff551b5cbb43ef3456dc4ed4bd6faac0576d8b..8f01f6695e45f4a8e6a808434666880944c00019 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 1a5d95136f5a7cc0f8739415cae3f13bd4b6b573..50447a4a12b5efcccdc2dbf55190a041af313245 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 5211a3b49f1d6dca169429871283f89dfc512c92..a102a351160a21eb4ff6805ebf4b821a0dc60ac7 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 d48a759f7a128e1cf6e1fe32d1f9816f5116b7da..7a51228c4138805c5ed43dd198cb6aeb4bd314a7 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); }); } });