2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2024-02-05 11:45:42 +08:00
|
|
|
import { globSync } from 'glob';
|
2022-09-09 15:51:35 +08:00
|
|
|
import { renderToString } from 'react-dom/server';
|
2024-02-05 11:45:42 +08:00
|
|
|
|
2022-09-09 15:51:35 +08:00
|
|
|
import type { Options } from '../../tests/shared/demoTest';
|
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
(global as any).testConfig = {};
|
2022-09-09 15:51:35 +08:00
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.mock('../../tests/shared/demoTest', () => {
|
2022-09-09 15:51:35 +08:00
|
|
|
function fakeDemoTest(name: string, option: Options = {}) {
|
2023-06-07 21:59:21 +08:00
|
|
|
(global as any).testConfig[name] = option;
|
2022-09-09 15:51:35 +08:00
|
|
|
}
|
|
|
|
|
2023-01-20 11:03:50 +08:00
|
|
|
fakeDemoTest.rootPropsTest = () => {};
|
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
return fakeDemoTest;
|
2022-09-09 15:51:35 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('node', () => {
|
|
|
|
beforeAll(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useFakeTimers().setSystemTime(new Date('2016-11-22'));
|
2022-09-09 15:51:35 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Find the component exist demo test file
|
2023-04-12 11:40:09 +08:00
|
|
|
const files = globSync(`./components/*/__tests__/demo.test.@(j|t)s?(x)`);
|
2022-09-09 15:51:35 +08:00
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
files.forEach((componentTestFile) => {
|
2022-09-09 15:51:35 +08:00
|
|
|
const componentName = componentTestFile.match(/components\/([^/]*)\//)![1];
|
|
|
|
|
|
|
|
// Test for ssr
|
2023-06-07 21:59:21 +08:00
|
|
|
describe(componentName, () => {
|
2024-02-05 11:45:42 +08:00
|
|
|
const demoList = globSync(`./components/${componentName}/demo/*.tsx`).filter(
|
|
|
|
(file) => !file.includes('_semantic'),
|
|
|
|
);
|
2022-09-09 15:51:35 +08:00
|
|
|
|
|
|
|
// Use mock to get config
|
2024-09-19 03:30:19 +08:00
|
|
|
require(`../../${componentTestFile}`);
|
2023-06-07 21:59:21 +08:00
|
|
|
const option = (global as any).testConfig?.[componentName];
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
demoList.forEach((demoFile) => {
|
2022-09-09 15:51:35 +08:00
|
|
|
const skip: string[] = option?.skip || [];
|
2022-11-19 13:47:33 +08:00
|
|
|
const test = skip.some((skipMarkdown) => demoFile.includes(skipMarkdown)) ? it.skip : it;
|
2022-09-09 15:51:35 +08:00
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
test(demoFile, () => {
|
2024-09-19 03:30:19 +08:00
|
|
|
const Demo = require(`../../${demoFile}`).default;
|
2023-06-07 21:59:21 +08:00
|
|
|
expect(() => {
|
|
|
|
renderToString(<Demo />);
|
|
|
|
}).not.toThrow();
|
|
|
|
});
|
2022-09-09 15:51:35 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|