77 */
88
99import assert from 'node:assert' ;
10- import { mkdir , mkdtemp , rm , writeFile } from 'node:fs/promises' ;
10+ import { mkdtemp , rm , writeFile } from 'node:fs/promises' ;
1111import { join } from 'node:path' ;
12- import { createComponentStylesheetBundlerForLibrary } from '../../../builders/library/pipeline/stylesheet-bundler' ;
1312import { initializeHash } from '../../../utils/hash' ;
1413import { MemoryLoadResultCache } from '../load-result-cache' ;
1514import { resetSassWorkerPoolCaches , shutdownSassWorkerPool } from '../stylesheets/sass-language' ;
@@ -34,7 +33,6 @@ describe('ComponentStylesheetBundler', () => {
3433 const testDir = await mkdtemp ( join ( tempRoot , 'inline-error-recovery-' ) ) ;
3534 const componentFile = join ( testDir , 'comp.ts' ) ;
3635 const partialFile = join ( testDir , '_missing.scss' ) ;
37- const loadCache = new MemoryLoadResultCache ( ) ;
3836
3937 const bundler = new ComponentStylesheetBundler (
4038 {
@@ -48,7 +46,6 @@ describe('ComponentStylesheetBundler', () => {
4846 } ,
4947 'scss' ,
5048 true ,
51- loadCache ,
5249 ) ;
5350
5451 try {
@@ -77,11 +74,11 @@ describe('ComponentStylesheetBundler', () => {
7774 }
7875 } ) ;
7976
80- it ( 'evicts angular:styles/component loadCache entries when the containing component .ts file is invalidated ' , async ( ) => {
77+ it ( 'should evict # loadCache entries when invalidating inline component stylesheets ' , async ( ) => {
8178 const testDir = await mkdtemp ( join ( tempRoot , 'inline-evict-' ) ) ;
8279 const componentFile = join ( testDir , 'comp.ts' ) ;
83- const loadCache = new MemoryLoadResultCache ( ) ;
84- const putSpy = spyOn ( loadCache , 'put ' ) . and . callThrough ( ) ;
80+ const putSpy = spyOn ( MemoryLoadResultCache . prototype , 'put' ) . and . callThrough ( ) ;
81+ const invalidateSpy = spyOn ( MemoryLoadResultCache . prototype , 'invalidate ' ) . and . callThrough ( ) ;
8582
8683 const bundler = new ComponentStylesheetBundler (
8784 {
@@ -95,7 +92,6 @@ describe('ComponentStylesheetBundler', () => {
9592 } ,
9693 'scss' ,
9794 true ,
98- loadCache ,
9995 ) ;
10096
10197 try {
@@ -105,54 +101,21 @@ describe('ComponentStylesheetBundler', () => {
105101
106102 const cacheKey = putSpy . calls . mostRecent ( ) . args [ 0 ] ;
107103 expect ( cacheKey ) . toMatch ( / ^ a n g u l a r : s t y l e s \/ c o m p o n e n t : s c s s ; / ) ;
108- expect ( loadCache . get ( cacheKey ) ) . toBeDefined ( ) ;
109104
110105 bundler . invalidate ( [ componentFile ] ) ;
111106
112- expect ( loadCache . get ( cacheKey ) ) . toBeUndefined ( ) ;
113- } finally {
114- await bundler . dispose ( ) ;
115- }
116- } ) ;
107+ expect ( invalidateSpy ) . toHaveBeenCalledWith ( cacheKey ) ;
108+ expect ( invalidateSpy ) . toHaveBeenCalledWith ( componentFile ) ;
117109
118- it ( 'persists and reuses stylesheet load results across builds when persistent cache is enabled' , async ( ) => {
119- const testDir = await mkdtemp ( join ( tempRoot , 'persistent-cache-' ) ) ;
120- const cacheDir = join ( testDir , '.angular' , 'cache' ) ;
121- await mkdir ( testDir , { recursive : true } ) ;
122- const styleFile = join ( testDir , 'comp.scss' ) ;
123- await writeFile ( styleFile , '$primary: blue;\n.card { color: $primary; }\n' ) ;
124-
125- const options = {
126- workspaceRoot : testDir ,
127- preserveSymlinks : false ,
128- styleIncludePaths : [ ] ,
129- sass : undefined ,
130- cacheOptions : {
131- enabled : true ,
132- path : cacheDir ,
133- basePath : cacheDir ,
134- } ,
135- inlineStyleLanguage : 'scss' as const ,
136- postcssConfiguration : undefined ,
137- tailwindConfiguration : undefined ,
138- } ;
139-
140- const firstBundler = createComponentStylesheetBundlerForLibrary ( options , false , [ 'es2022' ] ) ;
141- try {
142- const firstResult = await firstBundler . bundleFile ( styleFile ) ;
143- expect ( firstResult . errors ) . toBeUndefined ( ) ;
144- expect ( firstResult . contents ) . toContain ( '.card{color:#00f}' ) ;
145- } finally {
146- await firstBundler . dispose ( ) ;
147- }
148-
149- const secondBundler = createComponentStylesheetBundlerForLibrary ( options , false , [ 'es2022' ] ) ;
150- try {
151- const secondResult = await secondBundler . bundleFile ( styleFile ) ;
110+ const secondResult = await bundler . bundleInline (
111+ '.btn { color: red; }' ,
112+ componentFile ,
113+ 'scss' ,
114+ ) ;
152115 expect ( secondResult . errors ) . toBeUndefined ( ) ;
153- expect ( secondResult . contents ) . toContain ( '.card{color:#00f}' ) ;
116+ expect ( putSpy ) . toHaveBeenCalledTimes ( 2 ) ;
154117 } finally {
155- await secondBundler . dispose ( ) ;
118+ await bundler . dispose ( ) ;
156119 }
157120 } ) ;
158121} ) ;
0 commit comments