File tree Expand file tree Collapse file tree
packages/postcss/test/plugins Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+ exports [` plugins > enforce 1` ] = ` ".red { color : red ; .blue { color: blue } } "` ;
Original file line number Diff line number Diff line change 1+ import postcss from 'postcss'
2+
3+ // 不动态添加
4+ // 1 Once
5+ // 2 Once
6+ // 1 Root
7+ // 2 Root
8+ // 1 Rule
9+ // 2 Rule
10+ // 1 RuleExit
11+ // 2 RuleExit
12+ // 1 RootExit
13+ // 2 RootExit
14+ // 1 OnceExit
15+ // 2 OnceExit
16+
17+ // 动态添加
18+
19+ // 1 Once
20+ // 2 Once
21+ // 1 Root
22+ // 2 Root
23+ // 1 Rule
24+ // 2 Rule
25+ // 在这里因为添加了所以重新执行了 Rule
26+ // 1 Rule
27+ // 2 Rule
28+ // 1 RuleExit
29+ // 2 RuleExit
30+ // 同样重新执行了 RuleExit
31+ // 1 RuleExit
32+ // 2 RuleExit
33+ // 1 RootExit
34+ // 2 RootExit
35+ // 重新执行 Root
36+ // 1 Root
37+ // 2 Root
38+ // 1 RootExit
39+ // 2 RootExit
40+ // end
41+ // 1 OnceExit
42+ // 2 OnceExit
43+ describe ( 'plugins' , ( ) => {
44+ const weakMap = new WeakMap ( )
45+ it ( 'enforce' , async ( ) => {
46+ const { css } = await postcss (
47+ [
48+ {
49+ postcssPlugin : '1' ,
50+ Once ( ) {
51+ console . log ( '1 Once' )
52+ } ,
53+ OnceExit ( ) {
54+ console . log ( '1 OnceExit' )
55+ } ,
56+ Root ( ) {
57+ console . log ( '1 Root' )
58+ } ,
59+ RootExit ( ) {
60+ console . log ( '1 RootExit' )
61+ } ,
62+ Rule ( ) {
63+ console . log ( '1 Rule' )
64+ } ,
65+ RuleExit ( ) {
66+ console . log ( '1 RuleExit' )
67+ } ,
68+ } ,
69+ {
70+ postcssPlugin : '2' ,
71+ Rule ( node , { rule, decl } ) {
72+ console . log ( '2 Rule' )
73+ if ( ! weakMap . get ( rule ) ) {
74+ node . append ( rule ( { selector : '.blue' , nodes : [ decl ( { prop : 'color' , value : 'blue' } ) ] } ) )
75+ weakMap . set ( rule , true )
76+ }
77+ } ,
78+ RuleExit ( ) {
79+ console . log ( '2 RuleExit' )
80+ } ,
81+ Root ( ) {
82+ console . log ( '2 Root' )
83+ } ,
84+ RootExit ( ) {
85+ console . log ( '2 RootExit' )
86+ } ,
87+ Once ( ) {
88+ console . log ( '2 Once' )
89+ } ,
90+ OnceExit ( _root ) {
91+ console . log ( '2 OnceExit' )
92+ // root.append(rule({ selector: '.blue', nodes: [decl({ prop: 'color', value: 'blue' })] }))
93+ } ,
94+ } ,
95+ ] ,
96+ ) . process ( '.red { color: red; }' , {
97+ from : undefined ,
98+ } )
99+ expect ( css ) . toMatchSnapshot ( )
100+ } )
101+ } )
You can’t perform that action at this time.
0 commit comments