@@ -352,7 +352,7 @@ describe('Browser Builder styles', () => {
352
352
} ) ;
353
353
354
354
// TODO: consider making this a unit test in the url processing plugins.
355
- it ( `supports baseHref and deployUrl in resource urls` , ( done ) => {
355
+ it ( `supports baseHref/ deployUrl in resource urls without rebaseRootRelativeCssUrls ` , ( done ) => {
356
356
// Use a large image for the relative ref so it cannot be inlined.
357
357
host . copyFile ( 'src/spectrum.png' , './src/assets/global-img-relative.png' ) ;
358
358
host . copyFile ( 'src/spectrum.png' , './src/assets/component-img-relative.png' ) ;
@@ -396,6 +396,132 @@ describe('Browser Builder styles', () => {
396
396
concatMap ( ( ) => runTargetSpec ( host , browserTargetSpec ,
397
397
{ extractCss : true , baseHref : '/base/' , deployUrl : 'http://deploy.url/' } ,
398
398
) ) ,
399
+ tap ( ( ) => {
400
+ const styles = virtualFs . fileBufferToString (
401
+ host . scopedSync ( ) . read ( normalize ( stylesBundle ) ) ,
402
+ ) ;
403
+ const main = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( mainBundle ) ) ) ;
404
+ expect ( styles )
405
+ . toContain ( `url('/assets/global-img-absolute.svg')` ) ;
406
+ expect ( main )
407
+ . toContain ( `url('/assets/component-img-absolute.svg')` ) ;
408
+ } ) ,
409
+ // Check urls with base-href scheme are used as is (with deploy-url).
410
+ concatMap ( ( ) => runTargetSpec ( host , browserTargetSpec ,
411
+ { extractCss : true , baseHref : 'http://base.url/' , deployUrl : 'deploy/' } ,
412
+ ) ) ,
413
+ tap ( ( ) => {
414
+ const styles = virtualFs . fileBufferToString (
415
+ host . scopedSync ( ) . read ( normalize ( stylesBundle ) ) ,
416
+ ) ;
417
+ const main = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( mainBundle ) ) ) ;
418
+ expect ( styles )
419
+ . toContain ( `url('/assets/global-img-absolute.svg')` ) ;
420
+ expect ( main )
421
+ . toContain ( `url('/assets/component-img-absolute.svg')` ) ;
422
+ } ) ,
423
+ // Check urls with deploy-url and base-href scheme only use deploy-url.
424
+ concatMap ( ( ) => runTargetSpec ( host , browserTargetSpec , {
425
+ extractCss : true ,
426
+ baseHref : 'http://base.url/' ,
427
+ deployUrl : 'http://deploy.url/' ,
428
+ } ,
429
+ ) ) ,
430
+ tap ( ( ) => {
431
+ const styles = virtualFs . fileBufferToString (
432
+ host . scopedSync ( ) . read ( normalize ( stylesBundle ) ) ,
433
+ ) ;
434
+ const main = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( mainBundle ) ) ) ;
435
+ expect ( styles ) . toContain ( `url('/assets/global-img-absolute.svg')` ) ;
436
+ expect ( main ) . toContain ( `url('/assets/component-img-absolute.svg')` ) ;
437
+ } ) ,
438
+ // Check with schemeless base-href and deploy-url flags.
439
+ concatMap ( ( ) => runTargetSpec ( host , browserTargetSpec ,
440
+ { extractCss : true , baseHref : '/base/' , deployUrl : 'deploy/' } ,
441
+ ) ) ,
442
+ tap ( ( ) => {
443
+ const styles = virtualFs . fileBufferToString (
444
+ host . scopedSync ( ) . read ( normalize ( stylesBundle ) ) ,
445
+ ) ;
446
+ const main = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( mainBundle ) ) ) ;
447
+ expect ( styles ) . toContain ( `url('/assets/global-img-absolute.svg')` ) ;
448
+ expect ( main ) . toContain ( `url('/assets/component-img-absolute.svg')` ) ;
449
+ } ) ,
450
+ // Check with identical base-href and deploy-url flags.
451
+ concatMap ( ( ) => runTargetSpec ( host , browserTargetSpec ,
452
+ { extractCss : true , baseHref : '/base/' , deployUrl : '/base/' } ,
453
+ ) ) ,
454
+ tap ( ( ) => {
455
+ const styles = virtualFs . fileBufferToString (
456
+ host . scopedSync ( ) . read ( normalize ( stylesBundle ) ) ,
457
+ ) ;
458
+ const main = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( mainBundle ) ) ) ;
459
+ expect ( styles ) . toContain ( `url('/assets/global-img-absolute.svg')` ) ;
460
+ expect ( main ) . toContain ( `url('/assets/component-img-absolute.svg')` ) ;
461
+ } ) ,
462
+ // Check with only base-href flag.
463
+ concatMap ( ( ) => runTargetSpec ( host , browserTargetSpec ,
464
+ { extractCss : true , baseHref : '/base/' } ,
465
+ ) ) ,
466
+ tap ( ( ) => {
467
+ const styles = virtualFs . fileBufferToString (
468
+ host . scopedSync ( ) . read ( normalize ( stylesBundle ) ) ,
469
+ ) ;
470
+ const main = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( mainBundle ) ) ) ;
471
+ expect ( styles ) . toContain ( `url('/assets/global-img-absolute.svg')` ) ;
472
+ expect ( main ) . toContain ( `url('/assets/component-img-absolute.svg')` ) ;
473
+ } ) ,
474
+ ) . toPromise ( ) . then ( done , done . fail ) ;
475
+ } , 90000 ) ;
476
+
477
+ it ( `supports baseHref/deployUrl in resource urls with rebaseRootRelativeCssUrls` , ( done ) => {
478
+ // Use a large image for the relative ref so it cannot be inlined.
479
+ host . copyFile ( 'src/spectrum.png' , './src/assets/global-img-relative.png' ) ;
480
+ host . copyFile ( 'src/spectrum.png' , './src/assets/component-img-relative.png' ) ;
481
+ host . writeMultipleFiles ( {
482
+ 'src/styles.css' : `
483
+ h1 { background: url('/assets/global-img-absolute.svg'); }
484
+ h2 { background: url('./assets/global-img-relative.png'); }
485
+ ` ,
486
+ 'src/app/app.component.css' : `
487
+ h3 { background: url('/assets/component-img-absolute.svg'); }
488
+ h4 { background: url('../assets/component-img-relative.png'); }
489
+ ` ,
490
+ 'src/assets/global-img-absolute.svg' : imgSvg ,
491
+ 'src/assets/component-img-absolute.svg' : imgSvg ,
492
+ } ) ;
493
+
494
+ const stylesBundle = 'dist/styles.css' ;
495
+ const mainBundle = 'dist/main.js' ;
496
+
497
+ // Check base paths are correctly generated.
498
+ const overrides = {
499
+ extractCss : true ,
500
+ rebaseRootRelativeCssUrls : true ,
501
+ } ;
502
+ runTargetSpec ( host , browserTargetSpec , { ...overrides , aot : true } ) . pipe (
503
+ tap ( ( ) => {
504
+ const styles = virtualFs . fileBufferToString (
505
+ host . scopedSync ( ) . read ( normalize ( stylesBundle ) ) ,
506
+ ) ;
507
+ const main = virtualFs . fileBufferToString ( host . scopedSync ( ) . read ( normalize ( mainBundle ) ) ) ;
508
+ expect ( styles ) . toContain ( `url('/assets/global-img-absolute.svg')` ) ;
509
+ expect ( styles ) . toContain ( `url('global-img-relative.png')` ) ;
510
+ expect ( main ) . toContain ( `url('/assets/component-img-absolute.svg')` ) ;
511
+ expect ( main ) . toContain ( `url('component-img-relative.png')` ) ;
512
+ expect ( host . scopedSync ( ) . exists ( normalize ( 'dist/assets/global-img-absolute.svg' ) ) )
513
+ . toBe ( true ) ;
514
+ expect ( host . scopedSync ( ) . exists ( normalize ( 'dist/global-img-relative.png' ) ) )
515
+ . toBe ( true ) ;
516
+ expect ( host . scopedSync ( ) . exists ( normalize ( 'dist/assets/component-img-absolute.svg' ) ) )
517
+ . toBe ( true ) ;
518
+ expect ( host . scopedSync ( ) . exists ( normalize ( 'dist/component-img-relative.png' ) ) )
519
+ . toBe ( true ) ;
520
+ } ) ,
521
+ // Check urls with deploy-url scheme are used as is.
522
+ concatMap ( ( ) => runTargetSpec ( host , browserTargetSpec ,
523
+ { ...overrides , baseHref : '/base/' , deployUrl : 'http://deploy.url/' } ,
524
+ ) ) ,
399
525
tap ( ( ) => {
400
526
const styles = virtualFs . fileBufferToString (
401
527
host . scopedSync ( ) . read ( normalize ( stylesBundle ) ) ,
@@ -408,7 +534,7 @@ describe('Browser Builder styles', () => {
408
534
} ) ,
409
535
// Check urls with base-href scheme are used as is (with deploy-url).
410
536
concatMap ( ( ) => runTargetSpec ( host , browserTargetSpec ,
411
- { extractCss : true , baseHref : 'http://base.url/' , deployUrl : 'deploy/' } ,
537
+ { ... overrides , baseHref : 'http://base.url/' , deployUrl : 'deploy/' } ,
412
538
) ) ,
413
539
tap ( ( ) => {
414
540
const styles = virtualFs . fileBufferToString (
@@ -422,7 +548,7 @@ describe('Browser Builder styles', () => {
422
548
} ) ,
423
549
// Check urls with deploy-url and base-href scheme only use deploy-url.
424
550
concatMap ( ( ) => runTargetSpec ( host , browserTargetSpec , {
425
- extractCss : true ,
551
+ ... overrides ,
426
552
baseHref : 'http://base.url/' ,
427
553
deployUrl : 'http://deploy.url/' ,
428
554
} ,
@@ -437,7 +563,7 @@ describe('Browser Builder styles', () => {
437
563
} ) ,
438
564
// Check with schemeless base-href and deploy-url flags.
439
565
concatMap ( ( ) => runTargetSpec ( host , browserTargetSpec ,
440
- { extractCss : true , baseHref : '/base/' , deployUrl : 'deploy/' } ,
566
+ { ... overrides , baseHref : '/base/' , deployUrl : 'deploy/' } ,
441
567
) ) ,
442
568
tap ( ( ) => {
443
569
const styles = virtualFs . fileBufferToString (
@@ -449,7 +575,7 @@ describe('Browser Builder styles', () => {
449
575
} ) ,
450
576
// Check with identical base-href and deploy-url flags.
451
577
concatMap ( ( ) => runTargetSpec ( host , browserTargetSpec ,
452
- { extractCss : true , baseHref : '/base/' , deployUrl : '/base/' } ,
578
+ { ... overrides , baseHref : '/base/' , deployUrl : '/base/' } ,
453
579
) ) ,
454
580
tap ( ( ) => {
455
581
const styles = virtualFs . fileBufferToString (
@@ -461,7 +587,7 @@ describe('Browser Builder styles', () => {
461
587
} ) ,
462
588
// Check with only base-href flag.
463
589
concatMap ( ( ) => runTargetSpec ( host , browserTargetSpec ,
464
- { extractCss : true , baseHref : '/base/' } ,
590
+ { ... overrides , baseHref : '/base/' } ,
465
591
) ) ,
466
592
tap ( ( ) => {
467
593
const styles = virtualFs . fileBufferToString (
0 commit comments