From 70b90c076f4d160b3e1278c48c1c421e3d35c2f1 Mon Sep 17 00:00:00 2001 From: shaodahong Date: Thu, 12 Nov 2020 20:22:21 +0800 Subject: [PATCH 1/4] test: and pull_request_target branches-ignore --- .github/workflows/ui.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ui.yml b/.github/workflows/ui.yml index 32b90fc89f..75f8f93d6c 100644 --- a/.github/workflows/ui.yml +++ b/.github/workflows/ui.yml @@ -2,6 +2,9 @@ name: UI on: pull_request_target: + . # fix merge commit trigger + branches-ignore: + - master push: branches: - master From 9cdb037409f424bd1abd9d1f3a8220bd03b66489 Mon Sep 17 00:00:00 2001 From: shaodahong Date: Thu, 12 Nov 2020 20:25:07 +0800 Subject: [PATCH 2/4] remove symbolsymbol --- .github/workflows/ui.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ui.yml b/.github/workflows/ui.yml index 75f8f93d6c..6784fa4fa1 100644 --- a/.github/workflows/ui.yml +++ b/.github/workflows/ui.yml @@ -2,7 +2,7 @@ name: UI on: pull_request_target: - . # fix merge commit trigger + # fix merge commit trigger branches-ignore: - master push: From 427817fb1b456998236fb52cdac6e1135c98f5d2 Mon Sep 17 00:00:00 2001 From: shaodahong Date: Fri, 13 Nov 2020 19:35:46 +0800 Subject: [PATCH 3/4] use jest-puppeteer fix more launch --- .jest.image.js | 2 +- jest-puppeteer.config.js | 15 +++++++++++++++ package.json | 2 ++ tests/shared/imageTest.ts | 27 +++------------------------ 4 files changed, 21 insertions(+), 25 deletions(-) create mode 100644 jest-puppeteer.config.js diff --git a/.jest.image.js b/.jest.image.js index b04f37496e..263dcec864 100644 --- a/.jest.image.js +++ b/.jest.image.js @@ -12,7 +12,6 @@ module.exports = { '\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor', }, testRegex: 'image\\.test\\.(j|t)s$', - testEnvironment: 'node', transformIgnorePatterns, snapshotSerializers: ['enzyme-to-json/serializer'], globals: { @@ -20,4 +19,5 @@ module.exports = { tsConfigFile: './tsconfig.test.json', }, }, + preset: 'jest-puppeteer', }; diff --git a/jest-puppeteer.config.js b/jest-puppeteer.config.js new file mode 100644 index 0000000000..668abfb923 --- /dev/null +++ b/jest-puppeteer.config.js @@ -0,0 +1,15 @@ +// jest-puppeteer.config.js +module.exports = { + launch: { + args: [ + // Required for Docker version of Puppeteer + '--no-sandbox', + '--disable-setuid-sandbox', + // This will write shared memory files into /tmp instead of /dev/shm, + // because Docker’s default for /dev/shm is 64MB + '--disable-dev-shm-usage', + ], + }, + browser: 'chromium', + browserContext: 'default', +}; diff --git a/package.json b/package.json index cb5098567c..03426388bb 100644 --- a/package.json +++ b/package.json @@ -162,6 +162,7 @@ "@types/enzyme": "^3.10.5", "@types/gtag.js": "^0.0.3", "@types/jest": "^26.0.0", + "@types/jest-environment-puppeteer": "^4.4.0", "@types/jest-image-snapshot": "^4.1.0", "@types/lodash": "^4.14.139", "@types/puppeteer": "^5.4.0", @@ -223,6 +224,7 @@ "intersection-observer": "^0.11.0", "jest": "^26.0.0", "jest-image-snapshot": "^4.0.0", + "jest-puppeteer": "^4.4.0", "jquery": "^3.4.1", "jsdom": "^16.0.0", "jsonml.js": "^0.1.0", diff --git a/tests/shared/imageTest.ts b/tests/shared/imageTest.ts index 4336d0fa46..55c423ff3c 100644 --- a/tests/shared/imageTest.ts +++ b/tests/shared/imageTest.ts @@ -1,7 +1,6 @@ import React from 'react'; // Reference: https://github.com/ant-design/ant-design/pull/24003#discussion_r427267386 // eslint-disable-next-line import/no-unresolved -import puppeteer, { Browser, Page } from 'puppeteer'; import { configureToMatchImageSnapshot } from 'jest-image-snapshot'; import ReactDOMServer from 'react-dom/server'; import glob from 'glob'; @@ -18,32 +17,10 @@ expect.extend({ toMatchImageSnapshot }); // eslint-disable-next-line jest/no-export export default function imageTest(component: React.ReactElement) { describe(`Image test`, () => { - let browser: Browser; - let page: Page; - - beforeAll(async () => { + it('component image screenshot should correct', async () => { MockDate.set(moment('2016-11-22').valueOf()); - browser = await puppeteer.launch({ - args: [ - // Required for Docker version of Puppeteer - '--no-sandbox', - '--disable-setuid-sandbox', - // This will write shared memory files into /tmp instead of /dev/shm, - // because Docker’s default for /dev/shm is 64MB - '--disable-dev-shm-usage', - ], - }); - page = await browser.newPage(); await page.goto(`file://${process.cwd()}/tests/index.html`); await page.addStyleTag({ path: `${process.cwd()}/dist/antd.css` }); - }); - - afterAll(() => { - browser.close(); - MockDate.reset(); - }); - - it('component image screenshot should correct', async () => { const html = ReactDOMServer.renderToString(component); await page.evaluate(innerHTML => { document.querySelector('#root')!.innerHTML = innerHTML; @@ -52,6 +29,8 @@ export default function imageTest(component: React.ReactElement) { const image = await page.screenshot(); expect(image).toMatchImageSnapshot(); + + MockDate.reset(); }); }); } From 4ce36d2680cf5d688cb0c3a2b9c492b82327c1a5 Mon Sep 17 00:00:00 2001 From: shaodahong Date: Sat, 14 Nov 2020 12:34:45 +0800 Subject: [PATCH 4/4] increase timeout --- .jest.image.js | 1 + docker-compose.yml | 1 + jest-puppeteer.config.js | 2 -- tests/shared/imageTest.ts | 24 +++++++++++------------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.jest.image.js b/.jest.image.js index 263dcec864..6e3c1f2b46 100644 --- a/.jest.image.js +++ b/.jest.image.js @@ -20,4 +20,5 @@ module.exports = { }, }, preset: 'jest-puppeteer', + testTimeout: 10000, }; diff --git a/docker-compose.yml b/docker-compose.yml index 85e2b7d878..782dbaf70e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: - './jest-stare:/app/jest-stare' - './dist:/app/dist' - '.jest.image.js:/app/.jest.image.js' + - './jest-puppeteer.config.js:/app/jest-puppeteer.config.js' - './imageSnapshots:/app/imageSnapshots' - './imageDiffSnapshots:/app/imageDiffSnapshots' entrypoint: "jest --config .jest.image.js --no-cache -i" diff --git a/jest-puppeteer.config.js b/jest-puppeteer.config.js index 668abfb923..fb644512ed 100644 --- a/jest-puppeteer.config.js +++ b/jest-puppeteer.config.js @@ -10,6 +10,4 @@ module.exports = { '--disable-dev-shm-usage', ], }, - browser: 'chromium', - browserContext: 'default', }; diff --git a/tests/shared/imageTest.ts b/tests/shared/imageTest.ts index 55c423ff3c..dd7c36016e 100644 --- a/tests/shared/imageTest.ts +++ b/tests/shared/imageTest.ts @@ -16,22 +16,20 @@ expect.extend({ toMatchImageSnapshot }); // eslint-disable-next-line jest/no-export export default function imageTest(component: React.ReactElement) { - describe(`Image test`, () => { - it('component image screenshot should correct', async () => { - MockDate.set(moment('2016-11-22').valueOf()); - await page.goto(`file://${process.cwd()}/tests/index.html`); - await page.addStyleTag({ path: `${process.cwd()}/dist/antd.css` }); - const html = ReactDOMServer.renderToString(component); - await page.evaluate(innerHTML => { - document.querySelector('#root')!.innerHTML = innerHTML; - }, html); + it('component image screenshot should correct', async () => { + MockDate.set(moment('2016-11-22').valueOf()); + await page.goto(`file://${process.cwd()}/tests/index.html`); + await page.addStyleTag({ path: `${process.cwd()}/dist/antd.css` }); + const html = ReactDOMServer.renderToString(component); + await page.evaluate(innerHTML => { + document.querySelector('#root')!.innerHTML = innerHTML; + }, html); - const image = await page.screenshot(); + const image = await page.screenshot(); - expect(image).toMatchImageSnapshot(); + expect(image).toMatchImageSnapshot(); - MockDate.reset(); - }); + MockDate.reset(); }); }