jrit / web-resource-inliner

Inlines img, script and link tags into the same file
MIT License
66 stars 29 forks source link

[WIP] Remove node-fetch dep #85

Open iRyusa opened 1 month ago

iRyusa commented 1 month ago

⚠️ Note that 1 test still doesn't work on this PR

➜  web-resource-inliner git:(chore/remove-node-fetch) npm test

> web-resource-inliner@6.0.1 test
> mocha test

  html
    ✓ should inline based on inlineAttribute
    ✓ should exclude based on inlineAttribute
    ✓ should pass HTTP errors up through callbacks when strict (204ms)
    ✓ should pass missing file errors up through callbacks when strict
Not found, skipping: https://raw.githubusercontent.com/not-a-file.css
    ✓ should console.warn HTTP errors when not strict (111ms)
Not found, skipping: not-a-file.css
    ✓ should console.warn missing file errors when not strict
    ✓ should properly escape regex vars before calling replace()
    links
      ✓ should inline local links
      ✓ should inline remote links (163ms)
      ✓ should keep data: uris as-is
      ✓ should inline remote links with no protocol
      ✓ should inline remote links relative to a url
      ✓ should inline local and remote multiline links (38ms)
      ✓ should transform links
      ✓ should rebase inline local links relative to
    scripts
Not found, skipping: /assets/scripts/JsonFeed.js?x=2
Not found, skipping: /assets/scripts/SocialPluginIndex.js
      ✓ should inline scripts
      ✓ should inline multiline scripts
      ✓ should transform scripts
    images
      ✓ should inline local images
      ✓ should inline remote images (213ms)
      ✓ should inline images in one line
      ✓ should include based on size
      ✓ should exclude based on size
    svgs
      ✓ should inline local svgs
      ✓ should include based on size
      ✓ should exclude based on size
    (http mocking)
      ✓ should not try to inline empty links
      ✓ should not try to inline a link that starts with #
1| "<!DOCTYPE html>"
2| "<html>"
3| "<head>"
4| "    <title>test</title>"
5| "</head>"
6| "<body>"
7| "    <img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAHklEQVQoz2NgAIP/YMBAPBjVMNAa/pMISNcwEoMVAH0ls03D44ABAAAAAElFTkSuQmCC\" />" | "    <img src=\"data:image/png;base64,e30=\" />"
8| "    <img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAHklEQVQoz2NgAIP/YMBAPBjVMNAa/pMISNcwEoMVAH0ls03D44ABAAAAAElFTkSuQmCC\" />" | "    <img src=\"data:image/png;base64,e30=\" />"
9| "    <img src=\"cid:whatever\" />"
10| "    <img src=\"\" alt=\"nothing\" />"
11| "</body>"
12| "</html>"
      1) should use the base url (relativeTo) to resolve image URLs
      ✓ should unescape HTML entities when extracting URLs from attributes
      ✓ should understand the spaces to the sides of = when parsing attributes
      ✓ should apply the requestResource option

  css
    ✓ should inline local urls
    ✓ should inline remote urls
    ✓ should rebase local urls

  util
    #escapeSpecialChars
      ✓ should escape special regex characters in a string

  35 passing (833ms)
  1 failing

  1) html
       (http mocking)
         should use the base url (relativeTo) to resolve image URLs:

      Uncaught AssertionError [ERR_ASSERTION]: '<!DOCTYPE html>\n' +
  '<html>\n' +
  '<head>\n' +
  '    <title>test</title>\n' +
  '</head>\n' +
  '<body>\n' +
  '    <img src="data:image/png;base64,e30=" />\n' +
  '    <img src="data:image/png;base64,e30=" />\n' +
  '    <img src="cid:whatever" />\n' +
  '    <img src="" alt="nothing" />\n' +
  '</body>\n' +
  '</html>\n' == '<!DOCTYPE html>\n' +
  '<html>\n' +
  '<head>\n' +
  '    <title>test</title>\n' +
  '</head>\n' +
  '<body>\n' +
  '    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAHklEQVQoz2NgAIP/YMBAPBjVMNAa/pMISNcwEoMVAH0ls03D44ABAAAAAElFTkSuQmCC" />\n' +
  '    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAHklEQVQoz2NgAIP/YMBAPBjVMNAa/pMISNcwEoMVAH0ls03D44ABAAAAAElFTkSuQmCC" />\n' +
  '    <img src="cid:whatever" />\n' +
  '    <img src="" alt="n...
      + expected - actual

       <head>
           <title>test</title>
       </head>
       <body>
      -    <img src="data:image/png;base64,e30=" />
      -    <img src="data:image/png;base64,e30=" />
      +    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAHklEQVQoz2NgAIP/YMBAPBjVMNAa/pMISNcwEoMVAH0ls03D44ABAAAAAElFTkSuQmCC" />
      +    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAHklEQVQoz2NgAIP/YMBAPBjVMNAa/pMISNcwEoMVAH0ls03D44ABAAAAAElFTkSuQmCC" />
           <img src="cid:whatever" />
           <img src="" alt="nothing" />
       </body>
       </html>

      at testEquality (test/spec.js:56:12)
      at /Users/maximebrazeilles/workspaces/web-resource-inliner/test/spec.js:558:17
      at /Users/maximebrazeilles/workspaces/web-resource-inliner/src/html.js:281:13