@@ -359,30 +359,6 @@ describe('plugin options', function describe() {
359
359
'the set for which support is mandated by the specification' ) ) ;
360
360
} ) ;
361
361
362
- it ( 'supports legacy constructor with single hash function name' , function it ( ) {
363
- var plugin = new SriPlugin ( 'sha256' ) ;
364
- var dummyCompilation = testCompilation ( ) ;
365
- expect ( plugin . options . hashFuncNames ) . toEqual ( [ 'sha256' ] ) ;
366
- expect ( plugin . options . deprecatedOptions ) . toBeTruthy ( ) ;
367
- plugin . validateOptions ( dummyCompilation ) ;
368
- expect ( dummyCompilation . errors . length ) . toBe ( 0 ) ;
369
- expect ( dummyCompilation . warnings . length ) . toBe ( 1 ) ;
370
- expect ( dummyCompilation . warnings [ 0 ] . message ) . toMatch (
371
- / P a s s i n g a s t r i n g o r a r r a y t o t h e p l u g i n c o n s t r u c t o r i s d e p r e c a t e d / ) ;
372
- } ) ;
373
-
374
- it ( 'supports legacy constructor with array of hash function names' , function it ( ) {
375
- var plugin = new SriPlugin ( [ 'sha256' , 'sha384' ] ) ;
376
- var dummyCompilation = testCompilation ( ) ;
377
- expect ( plugin . options . hashFuncNames ) . toEqual ( [ 'sha256' , 'sha384' ] ) ;
378
- expect ( plugin . options . deprecatedOptions ) . toBeTruthy ( ) ;
379
- plugin . validateOptions ( dummyCompilation ) ;
380
- expect ( dummyCompilation . errors . length ) . toBe ( 0 ) ;
381
- expect ( dummyCompilation . warnings . length ) . toBe ( 1 ) ;
382
- expect ( dummyCompilation . warnings [ 0 ] . message ) . toMatch (
383
- / P a s s i n g a s t r i n g o r a r r a y t o t h e p l u g i n c o n s t r u c t o r i s d e p r e c a t e d / ) ;
384
- } ) ;
385
-
386
362
it ( 'supports new constructor with array of hash function names' , function it ( ) {
387
363
var plugin = new SriPlugin ( {
388
364
hashFuncNames : [ 'sha256' , 'sha384' ]
@@ -434,69 +410,6 @@ describe('plugin options', function describe() {
434
410
expect ( plugin . options . enabled ) . toBeFalsy ( ) ;
435
411
} ) ;
436
412
437
- it ( 'errors if the crossorigin attribute is not a string' , function it ( ) {
438
- var plugin = new SriPlugin ( {
439
- hashFuncNames : [ 'sha256' ] ,
440
- crossorigin : 1234
441
- } ) ;
442
- var dummyCompilation = testCompilation ( ) ;
443
- expect ( plugin . options . hashFuncNames ) . toEqual ( [ 'sha256' ] ) ;
444
- expect ( plugin . options . deprecatedOptions ) . toBeFalsy ( ) ;
445
- plugin . validateOptions ( dummyCompilation ) ;
446
- expect ( dummyCompilation . errors . length ) . toBe ( 1 ) ;
447
- expect ( dummyCompilation . warnings . length ) . toBe ( 1 ) ;
448
- expect ( dummyCompilation . errors [ 0 ] . message ) . toMatch (
449
- / o p t i o n s .c r o s s o r i g i n m u s t b e a s t r i n g ./ ) ;
450
- expect ( dummyCompilation . warnings [ 0 ] . message ) . toMatch (
451
- / s e t w e b p a c k o p t i o n o u t p u t .c r o s s O r i g i n L o a d i n g / ) ;
452
- } ) ;
453
-
454
- it ( 'warns if the crossorigin attribute is not recognized' , function it ( ) {
455
- var plugin = new SriPlugin ( {
456
- hashFuncNames : [ 'sha256' ] ,
457
- crossorigin : 'foo'
458
- } ) ;
459
- var dummyCompilation = testCompilation ( ) ;
460
-
461
- expect ( plugin . options . hashFuncNames ) . toEqual ( [ 'sha256' ] ) ;
462
- expect ( plugin . options . crossorigin ) . toBe ( 'foo' ) ;
463
- expect ( plugin . options . deprecatedOptions ) . toBeFalsy ( ) ;
464
- plugin . validateOptions ( dummyCompilation ) ;
465
- expect ( dummyCompilation . errors . length ) . toBe ( 0 ) ;
466
- expect ( dummyCompilation . warnings . length ) . toBe ( 2 ) ;
467
- expect ( dummyCompilation . warnings [ 0 ] . message ) . toMatch (
468
- / s e t w e b p a c k o p t i o n o u t p u t .c r o s s O r i g i n L o a d i n g / ) ;
469
- expect ( dummyCompilation . warnings [ 1 ] . message ) . toMatch ( new RegExp (
470
- 'specified a value for the crossorigin option that is not part of ' +
471
- 'the set of standard values' ) ) ;
472
- } ) ;
473
-
474
- it ( 'accepts anonymous crossorigin without warning about standard values' , function it ( ) {
475
- var plugin = new SriPlugin ( {
476
- hashFuncNames : [ 'sha256' ] ,
477
- crossorigin : 'anonymous'
478
- } ) ;
479
- var dummyCompilation = testCompilation ( ) ;
480
- plugin . validateOptions ( dummyCompilation ) ;
481
- expect ( dummyCompilation . errors . length ) . toBe ( 0 ) ;
482
- expect ( dummyCompilation . warnings . length ) . toBe ( 1 ) ;
483
- expect ( dummyCompilation . warnings [ 0 ] . message ) . toMatch (
484
- / s e t w e b p a c k o p t i o n o u t p u t .c r o s s O r i g i n L o a d i n g / ) ;
485
- } ) ;
486
-
487
- it ( 'accepts use-credentials crossorigin without warning about standard values' , function it ( ) {
488
- var plugin = new SriPlugin ( {
489
- hashFuncNames : [ 'sha256' ] ,
490
- crossorigin : 'use-credentials'
491
- } ) ;
492
- var dummyCompilation = testCompilation ( ) ;
493
- plugin . validateOptions ( dummyCompilation ) ;
494
- expect ( dummyCompilation . errors . length ) . toBe ( 0 ) ;
495
- expect ( dummyCompilation . warnings . length ) . toBe ( 1 ) ;
496
- expect ( dummyCompilation . warnings [ 0 ] . message ) . toMatch (
497
- / s e t w e b p a c k o p t i o n o u t p u t .c r o s s O r i g i n L o a d i n g / ) ;
498
- } ) ;
499
-
500
413
it ( 'uses default options' , function it ( ) {
501
414
var plugin = new SriPlugin ( {
502
415
hashFuncNames : [ 'sha256' ]
@@ -507,7 +420,6 @@ describe('plugin options', function describe() {
507
420
expect ( plugin . options . deprecatedOptions ) . toBeFalsy ( ) ;
508
421
dummyCompilation = testCompilation ( ) ;
509
422
plugin . validateOptions ( dummyCompilation ) ;
510
- expect ( plugin . options . crossorigin ) . toBe ( 'anonymous' ) ;
511
423
expect ( dummyCompilation . errors . length ) . toBe ( 0 ) ;
512
424
expect ( dummyCompilation . warnings . length ) . toBe ( 0 ) ;
513
425
} ) ;
@@ -633,53 +545,6 @@ describe('html-webpack-plugin', function describe() {
633
545
} ) ;
634
546
} ) ;
635
547
636
- it ( 'should use the crossorigin configuration option' , function it ( callback ) {
637
- var tmpDir = tmp . dirSync ( ) ;
638
- var webpackConfig ;
639
- var handler ;
640
- var scripts ;
641
- var parser ;
642
- function cleanup ( ) {
643
- fs . unlinkSync ( path . join ( tmpDir . name , 'index.html' ) ) ;
644
- fs . unlinkSync ( path . join ( tmpDir . name , 'bundle.js' ) ) ;
645
- tmpDir . removeCallback ( ) ;
646
- }
647
- webpackConfig = {
648
- entry : path . join ( __dirname , './dummy.js' ) ,
649
- output : {
650
- path : tmpDir . name ,
651
- filename : 'bundle.js' ,
652
- crossOriginLoading : 'anonymous'
653
- } ,
654
- plugins : [
655
- new HtmlWebpackPlugin ( ) ,
656
- new SriPlugin ( { hashFuncNames : [ 'sha256' ] , crossorigin : 'foo' } )
657
- ]
658
- } ;
659
- webpack ( webpackConfig , function webpackCallback ( err ) {
660
- if ( err ) {
661
- cleanup ( ) ;
662
- callback ( err ) ;
663
- }
664
-
665
- handler = new htmlparser . DefaultHandler ( function htmlparserCallback ( error , dom ) {
666
- if ( error ) {
667
- cleanup ( ) ;
668
- callback ( error ) ;
669
- } else {
670
- scripts = select ( dom , 'script' ) ;
671
- expect ( scripts . length ) . toEqual ( 1 ) ;
672
- expect ( scripts [ 0 ] . attribs . crossorigin ) . toEqual ( 'foo' ) ;
673
-
674
- cleanup ( ) ;
675
- callback ( ) ;
676
- }
677
- } ) ;
678
- parser = new htmlparser . Parser ( handler ) ;
679
- parser . parseComplete ( fs . readFileSync ( path . join ( tmpDir . name , 'index.html' ) , 'utf-8' ) ) ;
680
- } ) ;
681
- } ) ;
682
-
683
548
it ( 'should work with subdirectories' , function it ( callback ) {
684
549
var tmpDir = tmp . dirSync ( ) ;
685
550
var webpackConfig ;
@@ -737,42 +602,6 @@ describe('html-webpack-plugin', function describe() {
737
602
} ) ;
738
603
} ) ;
739
604
740
- it ( 'should warn when calling htmlWebpackPlugin.options.sriCrossOrigin' , function it ( callback ) {
741
- var tmpDir = tmp . dirSync ( ) ;
742
- var indexEjs = path . join ( tmpDir . name , 'index.ejs' ) ;
743
- var webpackConfig ;
744
- function cleanup ( err ) {
745
- fs . unlinkSync ( indexEjs ) ;
746
- fs . unlinkSync ( path . join ( tmpDir . name , 'bundle.js' ) ) ;
747
- fs . unlinkSync ( path . join ( tmpDir . name , 'index.html' ) ) ;
748
- tmpDir . removeCallback ( ) ;
749
- callback ( err ) ;
750
- }
751
- fs . writeFileSync ( indexEjs , '<% htmlWebpackPlugin.options.sriCrossOrigin %>' ) ;
752
- webpackConfig = {
753
- entry : path . join ( __dirname , './dummy.js' ) ,
754
- output : {
755
- filename : 'bundle.js' ,
756
- path : tmpDir . name ,
757
- crossOriginLoading : 'anonymous'
758
- } ,
759
- plugins : [
760
- new HtmlWebpackPlugin ( {
761
- template : indexEjs
762
- } ) ,
763
- new SriPlugin ( { hashFuncNames : [ 'sha256' , 'sha384' ] } )
764
- ]
765
- } ;
766
- webpack ( webpackConfig , function webpackCallback ( err , result ) {
767
- expect ( result . compilation . warnings . length ) . toEqual ( 1 ) ;
768
- expect ( result . compilation . warnings [ 0 ] ) . toBeAn ( Error ) ;
769
- expect ( result . compilation . warnings [ 0 ] . message ) . toEqual (
770
- 'webpack-subresource-integrity: htmlWebpackPlugin.options.sriCrossOrigin is deprecated, use webpackConfig.output.crossOriginLoading instead.'
771
- ) ;
772
- cleanup ( err ) ;
773
- } ) ;
774
- } ) ;
775
-
776
605
it ( 'should work with subdirectories and a custom template' , function it ( callback ) {
777
606
var tmpDir = tmp . dirSync ( ) ;
778
607
var webpackConfig ;
0 commit comments