ant-design/components/__tests__/node.test.tsx
黑雨 01ca7c7821
test: convert demo to testing-lib (#37381)
* test: replace testing-lib

* test: replace testing-lib

* test: replace testing-lib

* test: update snap

* test: replace testing-lib

* test: replace testing-lib

* test: update for lint

* merge: merge

* test: testing-lib

* test: replace testing-lib

* test: testing-lib

* test: testing-lib

* test: replace testing-lib

* test: replace testing-lib

* test: Replace test aria replacment logic

* test: Update snapshot

* chore: hack for id

* test: clean up

* test: clean demo

* chore: update

* test: snapshot update

* test: fix snapshot rep logic

* test: fix snapshot rep logic

* test: fix snapshot rep logic

* chore: update demo

* test: fix snapshot rep logic

* test: Update snapshot

* test: rest snapshot

* test: update snapshot

* test: Update test case

* test: config env

* chore: clean up

* chore: Use renderServer instead

* test: adjust testing logic

* test: modify test logic

* test: split ssr test

* test: skip if need skip

* chore: ignore test file covv

Co-authored-by: 二货机器人 <smith3816@gmail.com>
2022-09-09 15:51:35 +08:00

49 lines
1.5 KiB
TypeScript

import glob from 'glob';
import * as React from 'react';
import { renderToString } from 'react-dom/server';
import type { Options } from '../../tests/shared/demoTest';
(global as any).testConfig = {};
jest.mock('../../tests/shared/demoTest', () => {
function fakeDemoTest(name: string, option: Options = {}) {
(global as any).testConfig[name] = option;
}
return fakeDemoTest;
});
describe('node', () => {
beforeAll(() => {
jest.useFakeTimers().setSystemTime(new Date('2016-11-22'));
});
// Find the component exist demo test file
const files = glob.sync(`./components/*/__tests__/demo.test.@(j|t)s?(x)`);
files.forEach(componentTestFile => {
const componentName = componentTestFile.match(/components\/([^/]*)\//)![1];
// Test for ssr
describe(componentName, () => {
const demoList = glob.sync(`./components/${componentName}/demo/*.md`);
// Use mock to get config
require(`../../${componentTestFile}`); // eslint-disable-line global-require, import/no-dynamic-require
const option = (global as any).testConfig?.[componentName];
demoList.forEach(demoFile => {
const skip: string[] = option?.skip || [];
const test = skip.some(skipMarkdown => demoFile.includes(skipMarkdown)) ? it.skip : it;
test(demoFile, () => {
const Demo = require(`../../${demoFile}`).default; // eslint-disable-line global-require, import/no-dynamic-require
expect(() => {
renderToString(<Demo />);
}).not.toThrow();
});
});
});
});
});