-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
/
node.test.tsx
57 lines (47 loc) · 1.63 KB
/
node.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { globSync } from 'glob';
import * as React from 'react';
import { renderToString } from 'react-dom/server';
import type { Options } from '../../tests/shared/demoTest';
globalThis.testConfig = {};
vi.mock('../../tests/shared/demoTest', () => {
function fakeDemoTest(name: string, option: Options = {}) {
globalThis.testConfig[name] = option;
}
fakeDemoTest.rootPropsTest = () => {};
return {
default: fakeDemoTest,
rootPropsTest: () => {},
};
});
describe('node', () => {
beforeAll(() => {
vi.useFakeTimers().setSystemTime(new Date('2016-11-22'));
});
// Find the component exist demo test file
const files = globSync(`./components/*/__tests__/demo.test.@(j|t)s?(x)`);
files.forEach((componentTestFile) => {
const componentName = componentTestFile.match(/components\/([^/]*)\//)![1];
// Test for ssr
// eslint-disable-next-line vitest/valid-describe-callback
describe(componentName, async () => {
const demoList = globSync(`./components/${componentName}/demo/*.tsx`);
// Use mock to get config
await import(`../../${componentTestFile}`);
demoList.forEach((demoFile) => {
const option = globalThis.testConfig?.[componentName];
const skip: string[] = option?.skip || [];
const test = skip.some((skipMarkdown) => demoFile.includes(skipMarkdown)) ? it.skip : it;
test(
demoFile,
async () => {
const Demo = (await import(`../../${demoFile}`)).default;
expect(() => {
renderToString(<Demo />);
}).not.toThrow();
},
15000,
);
});
});
});
});