mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 01:19:45 +08:00
8d0bba4dea
* 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 fail
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
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();
|
|
});
|
|
});
|
|
}
|