Browse Source
* test: New Image Snapshots * circleci apt-get some lib * fix command * set CircleCI NODE_ENV * new test:image * upgrade jest-image-snapshot * needs dist * use jest html report * use now deploy * fix deploy skip * set token * upgrade version * change if * improve imageTest * print node version * revert puppeteer version * fix now fail * test * fix now fail * add if * fix if * add judgement * fix action * rebase * fix test image script * lint ignore * fix lint failpull/24320/head
骗你是小猫咪
5 years ago
committed by
GitHub
10 changed files with 155 additions and 4 deletions
@ -0,0 +1,31 @@ |
|||
name: UI-TEST |
|||
|
|||
on: |
|||
issue_comment: |
|||
types: [created] |
|||
|
|||
jobs: |
|||
ui: |
|||
runs-on: ubuntu-latest |
|||
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/ui') |
|||
steps: |
|||
- name: checkout |
|||
uses: actions/checkout@master |
|||
|
|||
- name: install |
|||
run: npm ci |
|||
|
|||
- name: dist |
|||
run: npm run dist |
|||
|
|||
- name: test |
|||
run: npm run test:image |
|||
|
|||
- name: VERCEL Now Deployment |
|||
uses: amondnet/now-deployment@v2.0.3 |
|||
with: |
|||
zeit-token: ${{ secrets.VERCEL_TOKEN }} |
|||
now-project-id: ${{ secrets.VERCEL_PROJECT_ID}} |
|||
now-org-id: ${{ secrets.VERCEL_ORG_ID}} |
|||
working-directory: ./jest-stare |
|||
if: failure() |
@ -0,0 +1,24 @@ |
|||
const { moduleNameMapper, transformIgnorePatterns } = require('./.jest'); |
|||
|
|||
// jest config for image snapshots
|
|||
module.exports = { |
|||
setupFiles: ['./tests/setup.js'], |
|||
moduleFileExtensions: ['ts', 'tsx', 'js', 'md'], |
|||
moduleNameMapper, |
|||
transform: { |
|||
'\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor', |
|||
'\\.js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor', |
|||
'\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor', |
|||
'\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor', |
|||
}, |
|||
testRegex: 'image\\.test\\.js$', |
|||
testEnvironment: 'node', |
|||
transformIgnorePatterns, |
|||
snapshotSerializers: ['enzyme-to-json/serializer'], |
|||
globals: { |
|||
'ts-jest': { |
|||
tsConfigFile: './tsconfig.test.json', |
|||
}, |
|||
}, |
|||
reporters: ['default', 'jest-stare'], |
|||
}; |
After Width: | Height: | Size: 10 KiB |
@ -0,0 +1,37 @@ |
|||
import React from 'react'; |
|||
import { Col, Row } from '..'; |
|||
import imageTest from '../../../tests/shared/imageTest'; |
|||
|
|||
describe('Grid image', () => { |
|||
imageTest( |
|||
<> |
|||
<Row> |
|||
<Col>col</Col> |
|||
</Row> |
|||
<Row> |
|||
<Col>col</Col> |
|||
<Col>col</Col> |
|||
<Col>col</Col> |
|||
<Col>col</Col> |
|||
</Row> |
|||
<Row> |
|||
<Col span={24}>col</Col> |
|||
</Row> |
|||
<Row> |
|||
<Col span={12}>col-12</Col> |
|||
<Col span={12}>col-12</Col> |
|||
</Row> |
|||
<Row> |
|||
<Col span={8}>col-8</Col> |
|||
<Col span={8}>col-8</Col> |
|||
<Col span={8}>col-8</Col> |
|||
</Row> |
|||
<Row> |
|||
<Col span={6}>col-6</Col> |
|||
<Col span={6}>col-6</Col> |
|||
<Col span={6}>col-6</Col> |
|||
<Col span={6}>col-6</Col> |
|||
</Row> |
|||
</>, |
|||
); |
|||
}); |
@ -0,0 +1,12 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<meta charset="UTF-8" /> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
|||
<title>Amazing Antd</title> |
|||
<link rel="stylesheet" href="antd.css" /> |
|||
</head> |
|||
<body> |
|||
<div id="root"></div> |
|||
</body> |
|||
</html> |
@ -0,0 +1,38 @@ |
|||
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 { toMatchImageSnapshot } from 'jest-image-snapshot'; |
|||
import ReactDOMServer from 'react-dom/server'; |
|||
|
|||
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 () => { |
|||
browser = await puppeteer.launch(); |
|||
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(); |
|||
}); |
|||
|
|||
it('component image screenshot should correct', async () => { |
|||
const html = ReactDOMServer.renderToString(component); |
|||
await page.evaluate(innerHTML => { |
|||
document.querySelector('#root')!.innerHTML = innerHTML; |
|||
}, html); |
|||
|
|||
const image = await page.screenshot(); |
|||
|
|||
expect(image).toMatchImageSnapshot(); |
|||
}); |
|||
}); |
|||
} |
Loading…
Reference in new issue