diff --git a/.circleci/config.yml b/.circleci/config.yml index ddafc61e35af8f81332c8b70d92cf5cff2ef250d..28ad7a2abf16c05bf6288223a682e30fe3eb703f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,14 +2,14 @@ version: 2 jobs: build: docker: - - image: circleci/node:8.11.4 + - image: circleci/node:latest steps: - checkout - run: npm install - run: npm run build test: docker: - - image: circleci/node:8.11.4 + - image: circleci/node:latest steps: - checkout - run: sh ./tests/fix_puppeteer.sh diff --git a/.eslintrc.js b/.eslintrc.js index d92c54f4de0d79c7596f21b7e3a4354789a0f74f..61b7c58f144009465484e71d59a45d112637afc2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,6 +11,7 @@ module.exports = { }, globals: { APP_TYPE: true, + page: true, }, rules: { 'react/jsx-filename-extension': [1, { extensions: ['.js'] }], diff --git a/Dockerfile b/Dockerfile index 11144bb02fdb54132329c0bcd241e9f5bd92d4c8..af06a83cec7cedbe3fbcfc24cf53414ee376afe5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ -FROM node:latest +FROM circleci/node:latest WORKDIR /usr/src/app/ - +USER root COPY package.json ./ -RUN npm install --silent --no-cache +RUN yarn COPY ./ ./ diff --git a/config/plugin.config.js b/config/plugin.config.js index 57f6deb6fc18564c2fd7db3c052f7f5c39a67a2f..55e8577b7f4c733d83ef34b82ca0028518353cf0 100644 --- a/config/plugin.config.js +++ b/config/plugin.config.js @@ -23,6 +23,8 @@ export default config => { varFile: path.join(__dirname, '../node_modules/antd/lib/style/themes/default.less'), mainLessFile: outFile, // themeVariables: ['@primary-color'], indexFileName: 'index.html', + generateOne: true, + lessUrl: 'https://gw.alipayobjects.com/os/lib/less.js/3.8.1/less.min.js', }, ]); }; diff --git a/jest.config.js b/jest.config.js index ec949f06c920aba9ef41713ff201b8a3ff170186..68a1144bcb17feb585b3725e5d323b0414dd91cc 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,3 +1,4 @@ module.exports = { testURL: 'http://localhost:8000', + preset: 'jest-puppeteer', }; diff --git a/package.json b/package.json index 2be1673046a66bbdd397d2053a00c4c6f7243737..eddfd95cea0b57a54c9d42e396ece88938edc1ef 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "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", diff --git a/src/e2e/baseLayout.e2e.js b/src/e2e/baseLayout.e2e.js new file mode 100644 index 0000000000000000000000000000000000000000..8487a758fe0131cf8439f574ee5e79022b6ca3d5 --- /dev/null +++ b/src/e2e/baseLayout.e2e.js @@ -0,0 +1,46 @@ +import RouterConfig from '../../config/router.config'; + +const BASE_URL = `http://localhost:${process.env.PORT || 8000}`; + +function formatter(data) { + return data + .reduce((pre, item) => { + pre.push(item.path); + return pre; + }, []) + .filter(item => item); +} + +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(); + }); + + 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); + }); +}); diff --git a/src/e2e/home.e2e.js b/src/e2e/home.e2e.js index cadac245b6ff2e7fd721b1de5961f6034ad41ef7..b8d22cb86ec1bda3adda7944666ceb6adb22e255 100644 --- a/src/e2e/home.e2e.js +++ b/src/e2e/home.e2e.js @@ -1,5 +1,3 @@ -import puppeteer from 'puppeteer'; - const BASE_URL = `http://localhost:${process.env.PORT || 8000}`; describe('Homepage', () => { @@ -7,13 +5,11 @@ describe('Homepage', () => { jest.setTimeout(1000000); }); it('it should have logo text', async () => { - const browser = await puppeteer.launch({ args: ['--no-sandbox'] }); - const page = await browser.newPage(); - await page.goto(BASE_URL, { waitUntil: 'networkidle2' }); + await page.goto(BASE_URL); + await page.waitForSelector('h1', { + timeout: 2000, + }); const text = await page.evaluate(() => document.getElementsByTagName('h1')[0].innerText); expect(text).toContain('Ant Design Pro'); - - await page.close(); - browser.close(); }); }); diff --git a/src/e2e/login.e2e.js b/src/e2e/login.e2e.js index 589ad46b39daf3fa951b963ba6a41a7b8f11caec..b991af44ba7a953df0786fd28d8e64a536870aaf 100644 --- a/src/e2e/login.e2e.js +++ b/src/e2e/login.e2e.js @@ -1,24 +1,15 @@ -import puppeteer from 'puppeteer'; - const BASE_URL = `http://localhost:${process.env.PORT || 8000}`; describe('Login', () => { - let browser; - let page; - beforeAll(async () => { jest.setTimeout(1000000); - browser = await puppeteer.launch({ args: ['--no-sandbox'] }); }); beforeEach(async () => { - page = await browser.newPage(); await page.goto(`${BASE_URL}/user/login`, { waitUntil: 'networkidle2' }); await page.evaluate(() => window.localStorage.setItem('antd-pro-authority', 'guest')); }); - afterEach(() => page.close()); - it('should login with failure', async () => { await page.waitForSelector('#userName', { timeout: 2000, @@ -40,6 +31,4 @@ describe('Login', () => { const text = await page.evaluate(() => document.body.innerHTML); expect(text).toContain('