@@ -46,6 +46,66 @@ describe('component-styles', () => {
4646 expect ( content ) . toContain ( '\\\\2014 \\\\00A0' ) ;
4747 } ) ;
4848
49+ it ( 'should build one component w/ out inline style, and re-compile when adding inline styles' , async ( ) => {
50+ compiler . config . watch = true ;
51+ await compiler . fs . writeFiles ( {
52+ [ path . join ( root , 'src' , 'cmp-a.tsx' ) ] : `@Component({ tag: 'cmp-a' }) export class CmpA {}` ,
53+ } ) ;
54+ await compiler . fs . commit ( ) ;
55+
56+ let r = await compiler . build ( ) ;
57+ expect ( r . diagnostics ) . toHaveLength ( 0 ) ;
58+ expect ( r . styleBuildCount ) . toBe ( 0 ) ;
59+
60+ const rebuildListener = compiler . once ( 'buildFinish' ) ;
61+
62+ await compiler . fs . writeFiles ( {
63+ [ path . join ( root , 'src' , 'cmp-a.tsx' ) ] : `@Component({ tag: 'cmp-a', styles: 'body { color: green; }' }) export class CmpA {}` ,
64+ } , { clearFileCache : true } ) ;
65+ await compiler . fs . commit ( ) ;
66+
67+ compiler . trigger ( 'fileUpdate' , path . join ( root , 'src' , 'cmp-a.tsx' ) ) ;
68+
69+ r = await rebuildListener ;
70+ expect ( r . diagnostics ) . toHaveLength ( 0 ) ;
71+ expect ( r . hmr . inlineStylesUpdated ) . toHaveLength ( 1 ) ;
72+ expect ( r . hmr . inlineStylesUpdated [ 0 ] . styleText ) . toBe ( `body { color: green; }` ) ;
73+
74+ const content = await compiler . fs . readFile ( path . join ( root , 'www' , 'build' , 'cmp-a.entry.js' ) ) ;
75+ expect ( content ) . toContain ( `color: green` ) ;
76+ expect ( r . styleBuildCount ) . toBe ( 1 ) ;
77+ } ) ;
78+
79+ it ( 'should build one component w/ inline style, and re-compile when removing inline styles' , async ( ) => {
80+ compiler . config . watch = true ;
81+ await compiler . fs . writeFiles ( {
82+ [ path . join ( root , 'src' , 'cmp-a.tsx' ) ] : `@Component({ tag: 'cmp-a', styles: 'body { color: green; }' }) export class CmpA {}` ,
83+ } ) ;
84+ await compiler . fs . commit ( ) ;
85+
86+ let r = await compiler . build ( ) ;
87+ expect ( r . diagnostics ) . toHaveLength ( 0 ) ;
88+ expect ( r . styleBuildCount ) . toBe ( 1 ) ;
89+
90+ const rebuildListener = compiler . once ( 'buildFinish' ) ;
91+
92+ await compiler . fs . writeFiles ( {
93+ [ path . join ( root , 'src' , 'cmp-a.tsx' ) ] : `@Component({ tag: 'cmp-a' }) export class CmpA {}` ,
94+ } , { clearFileCache : true } ) ;
95+ await compiler . fs . commit ( ) ;
96+
97+ compiler . trigger ( 'fileUpdate' , path . join ( root , 'src' , 'cmp-a.tsx' ) ) ;
98+
99+ r = await rebuildListener ;
100+ expect ( r . diagnostics ) . toHaveLength ( 0 ) ;
101+ expect ( r . hmr . inlineStylesUpdated ) . toHaveLength ( 1 ) ;
102+ expect ( r . hmr . inlineStylesUpdated [ 0 ] . styleText ) . toBe ( `` ) ;
103+
104+ const content = await compiler . fs . readFile ( path . join ( root , 'www' , 'build' , 'cmp-a.entry.js' ) ) ;
105+ expect ( content ) . not . toContain ( `color: green` ) ;
106+ expect ( r . styleBuildCount ) . toBe ( 0 ) ;
107+ } ) ;
108+
49109 it ( 'should build one component w/ inline style, and re-compile on module file changes' , async ( ) => {
50110 compiler . config . watch = true ;
51111 await compiler . fs . writeFiles ( {
@@ -71,6 +131,9 @@ describe('component-styles', () => {
71131
72132 r = await rebuildListener ;
73133 expect ( r . diagnostics ) . toHaveLength ( 0 ) ;
134+ expect ( r . diagnostics ) . toHaveLength ( 0 ) ;
135+ expect ( r . hmr . inlineStylesUpdated ) . toHaveLength ( 1 ) ;
136+ expect ( r . hmr . inlineStylesUpdated [ 0 ] . styleText ) . toContain ( `color: green` ) ;
74137
75138 content = await compiler . fs . readFile ( path . join ( root , 'www' , 'build' , 'cmp-a.entry.js' ) ) ;
76139 expect ( content ) . toContain ( `color: green` ) ;
0 commit comments