瀏覽代碼

feat: win add test script (#3845)

* feat: win add test script

* bugfix: fix test error

* use new config
陈帅 6 年之前
父節點
當前提交
b86048b4db
共有 6 個文件被更改,包括 17 次插入11 次删除
  1. 4 0
      azure-pipelines.yml
  2. 1 0
      jest-puppeteer.config.js
  3. 6 2
      src/e2e/baseLayout.e2e.js
  4. 1 0
      src/e2e/topMenu.e2e.js
  5. 0 9
      src/pages/Result/Success.test.js
  6. 5 0
      src/utils/authority.js

+ 4 - 0
azure-pipelines.yml

@@ -52,6 +52,10 @@ jobs:
         displayName: install
       - script: npm run lint
         displayName: lint
+      - script: npm run test:all
+        env:
+          PROGRESS: none
+        displayName: test
       - script: npm run build
         env:
           PROGRESS: none

+ 1 - 0
jest-puppeteer.config.js

@@ -6,6 +6,7 @@ module.exports = {
       '--disable-dev-shm-usage',
       '--no-first-run',
       '--no-zygote',
+      '--no-sandbox'
     ],
   },
 };

+ 6 - 2
src/e2e/baseLayout.e2e.js

@@ -5,13 +5,17 @@ const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
 function formatter(data) {
   return data
     .reduce((pre, item) => {
-      pre.push(item.path);
+      if (item.routes) {
+        pre.push(item.routes[0].path);
+      } else {
+        pre.push(item.path);
+      }
       return pre;
     }, [])
     .filter(item => item);
 }
 
-describe('Homepage', async () => {
+describe('Homepage', () => {
   const testPage = path => async () => {
     await page.goto(`${BASE_URL}${path}`);
     await page.waitForSelector('footer', {

+ 1 - 0
src/e2e/topMenu.e2e.js

@@ -4,6 +4,7 @@ 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}`);

+ 0 - 9
src/pages/Result/Success.test.js

@@ -1,9 +0,0 @@
-import React from 'react';
-import { shallow } from 'enzyme';
-import Success from './Success';
-
-it('renders with Result', () => {
-  const wrapper = shallow(<Success />);
-  expect(wrapper.find('Result').length).toBe(1);
-  expect(wrapper.find('Result').prop('type')).toBe('success');
-});

+ 5 - 0
src/utils/authority.js

@@ -1,4 +1,6 @@
 // use localStorage to store the authority info, which might be sent from server in actual project.
+const { NODE_ENV } = process.env;
+
 export function getAuthority(str) {
   // return localStorage.getItem('antd-pro-authority') || ['admin', 'user'];
   const authorityString =
@@ -13,6 +15,9 @@ export function getAuthority(str) {
   if (typeof authority === 'string') {
     return [authority];
   }
+  if (!authority && NODE_ENV !== 'production') {
+    return ['admin'];
+  }
   return authority;
 }