@@ -513,6 +513,81 @@ describe('beasties', () => {
513513 fs . rmSync ( tmpDir , { recursive : true } )
514514 } )
515515
516+ it ( 'handles stylesheets with query strings' , async ( ) => {
517+ const beasties = new Beasties ( {
518+ reduceInlineStyles : false ,
519+ path : '/' ,
520+ } )
521+ const assets : Record < string , string > = {
522+ '/style.css' : 'h1 { color: blue; } h2.unused { color: red; }' ,
523+ }
524+ beasties . readFile = filename => assets [ filename . replace ( / ^ \w : / , '' ) . replace ( / \\ / g, '/' ) ] !
525+
526+ const result = await beasties . process ( trim `
527+ <html>
528+ <head>
529+ <link rel="stylesheet" href="/style.css?v=123">
530+ </head>
531+ <body>
532+ <h1>Hello World!</h1>
533+ </body>
534+ </html>
535+ ` )
536+
537+ expect ( result ) . toContain ( '<style>h1{color:blue}</style>' )
538+ expect ( result ) . toContain ( '/style.css?v=123' )
539+ } )
540+
541+ it ( 'handles stylesheets with hash fragments' , async ( ) => {
542+ const beasties = new Beasties ( {
543+ reduceInlineStyles : false ,
544+ path : '/' ,
545+ } )
546+ const assets : Record < string , string > = {
547+ '/style.css' : 'h1 { color: green; } h2.unused { color: red; }' ,
548+ }
549+ beasties . readFile = filename => assets [ filename . replace ( / ^ \w : / , '' ) . replace ( / \\ / g, '/' ) ] !
550+
551+ const result = await beasties . process ( trim `
552+ <html>
553+ <head>
554+ <link rel="stylesheet" href="/style.css#section">
555+ </head>
556+ <body>
557+ <h1>Hello World!</h1>
558+ </body>
559+ </html>
560+ ` )
561+
562+ expect ( result ) . toContain ( '<style>h1{color:green}</style>' )
563+ expect ( result ) . toContain ( '/style.css#section' )
564+ } )
565+
566+ it ( 'handles stylesheets with both query strings and hash fragments' , async ( ) => {
567+ const beasties = new Beasties ( {
568+ reduceInlineStyles : false ,
569+ path : '/' ,
570+ } )
571+ const assets : Record < string , string > = {
572+ '/style.css' : 'h1 { color: purple; } h2.unused { color: red; }' ,
573+ }
574+ beasties . readFile = filename => assets [ filename . replace ( / ^ \w : / , '' ) . replace ( / \\ / g, '/' ) ] !
575+
576+ const result = await beasties . process ( trim `
577+ <html>
578+ <head>
579+ <link rel="stylesheet" href="/style.css?v=456#section">
580+ </head>
581+ <body>
582+ <h1>Hello World!</h1>
583+ </body>
584+ </html>
585+ ` )
586+
587+ expect ( result ) . toContain ( '<style>h1{color:purple}</style>' )
588+ expect ( result ) . toContain ( '/style.css?v=456#section' )
589+ } )
590+
516591 it ( 'ignores remote stylesheets by default' , async ( ) => {
517592 const beasties = new Beasties ( {
518593 reduceInlineStyles : false ,
0 commit comments