jim vor 7 Jahren
Ursprung
Commit
3cfbae3b31
6 geänderte Dateien mit 69 neuen und 36 gelöschten Zeilen
  1. 12 3
      .babelrc.js
  2. 3 3
      package.json
  3. 48 25
      src/components/SiderMenu/SilderMenu.test.js
  4. 2 2
      src/e2e/home.e2e.js
  5. 2 2
      src/e2e/login.e2e.js
  6. 2 1
      tests/run-tests.js

+ 12 - 3
.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'
+      },
+    ],
   ],
-};
+};

+ 3 - 3
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}": [

+ 48 - 25
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',
+    ]);
   });
 });

+ 2 - 2
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('<h1>Ant Design Pro</h1>');

+ 2 - 2
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'));
   });
 

+ 2 - 1
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);
     });
   }
 });