Skip to content

Commit d37aaae

Browse files
committed
feat: add static-style extract test
1 parent 981f713 commit d37aaae

File tree

4 files changed

+91
-2
lines changed

4 files changed

+91
-2
lines changed

components/_util/cssinjs/StyleContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const useStyleProvider = (props: UseStyleProviderProps) => {
8888
const parentContext = useStyleInject();
8989
const context = shallowRef<Partial<StyleContextProps>>({ ...defaultStyleContext });
9090
watch(
91-
[props, parentContext],
91+
[() => props, () => parentContext],
9292
() => {
9393
const mergedContext: Partial<StyleContextProps> = {
9494
...parentContext.value,

components/_util/static-style-extract/index.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,28 @@ const blackList: string[] = [
1111
'Popover',
1212
'Tooltip',
1313
'Tour',
14+
'SelectOptGroup',
15+
'SelectOption',
16+
'Dropdown',
17+
'Anchor',
18+
'QuarterPicker',
19+
'MenuDivider',
20+
'MenuItem',
21+
'MenuItemGroup',
22+
'SubMenu',
23+
'MentionsOption',
24+
'TableColumn',
25+
'TableColumnGroup',
26+
'TableSummary',
27+
'TableSummaryRow',
28+
'TableSummaryCell',
29+
'TreeNode',
30+
'TreeSelectNode',
31+
'TabPane',
32+
'CheckableTag',
33+
'TimelineItem',
34+
'LocaleProvider',
35+
'QRCode',
1436
];
1537

1638
const defaultNode = () => (
@@ -19,7 +41,7 @@ const defaultNode = () => (
1941
.filter(name => !blackList.includes(name) && name[0] === name[0].toUpperCase())
2042
.map(compName => {
2143
const Comp = antd[compName];
22-
if (compName === 'Dropdown' || compName === 'Anchor') {
44+
if (compName === 'Dropdown') {
2345
return (
2446
<Comp key={compName} menu={{ items: [] }}>
2547
<div />

components/_util/static-style-extract/tests/__snapshots__/index.test.js.snap

Lines changed: 5 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// import { StyleProvider } from '../../cssinjs';
2+
import { extractStyle } from '../index';
3+
// import { ConfigProvider } from '../../../components';
4+
5+
const testGreenColor = '#008000';
6+
describe('Static-Style-Extract', () => {
7+
it('should extract static styles', () => {
8+
const cssText = extractStyle();
9+
expect(cssText).not.toContain(testGreenColor);
10+
expect(cssText).toMatchSnapshot();
11+
});
12+
// it('should extract static styles with customTheme', () => {
13+
// const cssText = extractStyle((node) => {
14+
// return(
15+
// <ConfigProvider
16+
// theme={{
17+
// token: {
18+
// colorPrimary: testGreenColor,
19+
// },
20+
// }}
21+
// >
22+
// {node}
23+
// </ConfigProvider>
24+
// );
25+
// });
26+
// expect(cssText).toContain(testGreenColor);
27+
// expect(cssText).toMatchSnapshot();
28+
// });
29+
// it('with custom hashPriority', () => {
30+
// const cssText = extractStyle(
31+
// (node) => (
32+
// <StyleProvider hashPriority='high'>
33+
// <ConfigProvider
34+
// theme={{
35+
// token: {
36+
// colorPrimary: testGreenColor,
37+
// },
38+
// }}
39+
// >
40+
// {node}
41+
// </ConfigProvider>
42+
// </StyleProvider>
43+
// ),
44+
// );
45+
// expect(cssText).toContain(testGreenColor);
46+
// expect(cssText).not.toContain(':where');
47+
// expect(cssText).toMatchSnapshot();
48+
//
49+
// const cssText2 = extractStyle((node) => (
50+
// <ConfigProvider
51+
// theme={{
52+
// token: {
53+
// colorPrimary: testGreenColor,
54+
// },
55+
// }}
56+
// >
57+
// {node}
58+
// </ConfigProvider>
59+
// ));
60+
// expect(cssText2).toContain(':where');
61+
// });
62+
});

0 commit comments

Comments
 (0)