html-snapshots 1.3.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/lib/common/index.js +57 -3
  2. package/lib/common/sitemap/sitemap-collection.js +3 -2
  3. package/lib/common/sitemap/sitemap-index.js +1 -4
  4. package/lib/common/sitemap/sitemap.js +15 -13
  5. package/lib/html-snapshots.js +5 -6
  6. package/lib/input-generators/_base.js +5 -5
  7. package/package.json +5 -6
  8. package/.c8rc.json +0 -5
  9. package/.eslintignore +0 -5
  10. package/.eslintrc.json +0 -16
  11. package/.github/issue_template.md +0 -16
  12. package/.github/workflows/verify.yml +0 -32
  13. package/docs/example-heroku-redis.md +0 -43
  14. package/docs/notes.md +0 -42
  15. package/examples/README.md +0 -149
  16. package/examples/custom/README.md +0 -22
  17. package/examples/custom/myFilter.js +0 -22
  18. package/examples/custom/package-lock.json +0 -2804
  19. package/examples/custom/package.json +0 -12
  20. package/examples/custom/snapshot.js +0 -28
  21. package/examples/debug-phantomjs/README.md +0 -38
  22. package/examples/debug-phantomjs/package-lock.json +0 -2922
  23. package/examples/debug-phantomjs/package.json +0 -12
  24. package/examples/debug-phantomjs/snapshot.js +0 -60
  25. package/examples/debug-puppeteer/README.md +0 -18
  26. package/examples/debug-puppeteer/package-lock.json +0 -2804
  27. package/examples/debug-puppeteer/package.json +0 -12
  28. package/examples/debug-puppeteer/snapshot.js +0 -30
  29. package/examples/html5rocks/README.md +0 -22
  30. package/examples/html5rocks/package-lock.json +0 -3218
  31. package/examples/html5rocks/package.json +0 -12
  32. package/examples/html5rocks/snapshot.js +0 -59
  33. package/examples/process-limit/README.md +0 -24
  34. package/examples/process-limit/package-lock.json +0 -2830
  35. package/examples/process-limit/package.json +0 -12
  36. package/examples/process-limit/snapshot.js +0 -30
  37. package/examples/simple-promise/README.md +0 -20
  38. package/examples/simple-promise/package-lock.json +0 -2830
  39. package/examples/simple-promise/package.json +0 -12
  40. package/examples/simple-promise/snapshot.js +0 -30
  41. package/examples/sitemap-index/README.md +0 -20
  42. package/examples/sitemap-index/package-lock.json +0 -2830
  43. package/examples/sitemap-index/package.json +0 -12
  44. package/examples/sitemap-index/snapshot.js +0 -34
  45. package/examples/verbose/README.md +0 -22
  46. package/examples/verbose/package-lock.json +0 -2805
  47. package/examples/verbose/package.json +0 -12
  48. package/examples/verbose/snapshot.js +0 -34
  49. package/test/helpers/options.js +0 -55
  50. package/test/helpers/result.js +0 -32
  51. package/test/helpers/sitemap.js +0 -130
  52. package/test/mocha/async/test.js +0 -416
  53. package/test/mocha/browsers/puppeteer.js +0 -129
  54. package/test/mocha/browsers/server/index.html +0 -9
  55. package/test/mocha/browsers/test.js +0 -11
  56. package/test/mocha/common/helpers.js +0 -87
  57. package/test/mocha/common/test.js +0 -188
  58. package/test/mocha/html-snapshots/basics.js +0 -88
  59. package/test/mocha/html-snapshots/myFilter.js +0 -10
  60. package/test/mocha/html-snapshots/phantomjs-options.js +0 -156
  61. package/test/mocha/html-snapshots/process-limit.js +0 -156
  62. package/test/mocha/html-snapshots/puppeteer.js +0 -47
  63. package/test/mocha/html-snapshots/robots.js +0 -194
  64. package/test/mocha/html-snapshots/server/contact/index.html +0 -57
  65. package/test/mocha/html-snapshots/server/favicon.ico +0 -0
  66. package/test/mocha/html-snapshots/server/fonts/facebolf-webfont.eot +0 -0
  67. package/test/mocha/html-snapshots/server/fonts/facebolf-webfont.svg +0 -220
  68. package/test/mocha/html-snapshots/server/fonts/facebolf-webfont.ttf +0 -0
  69. package/test/mocha/html-snapshots/server/fonts/facebolf-webfont.woff +0 -0
  70. package/test/mocha/html-snapshots/server/images/ajax-loader.gif +0 -0
  71. package/test/mocha/html-snapshots/server/images/art1.jpg +0 -0
  72. package/test/mocha/html-snapshots/server/images/carpet.jpg +0 -0
  73. package/test/mocha/html-snapshots/server/images/carpets/carpet1.jpg +0 -0
  74. package/test/mocha/html-snapshots/server/images/carpets/carpet1_th.jpg +0 -0
  75. package/test/mocha/html-snapshots/server/images/carpets/carpet2.jpg +0 -0
  76. package/test/mocha/html-snapshots/server/images/carpets/carpet2_th.jpg +0 -0
  77. package/test/mocha/html-snapshots/server/images/carpets/carpet3.jpg +0 -0
  78. package/test/mocha/html-snapshots/server/images/carpets/carpet3_th.jpg +0 -0
  79. package/test/mocha/html-snapshots/server/images/carpets/carpet4.jpg +0 -0
  80. package/test/mocha/html-snapshots/server/images/carpets/carpet4_th.jpg +0 -0
  81. package/test/mocha/html-snapshots/server/images/floor.jpg +0 -0
  82. package/test/mocha/html-snapshots/server/images/foundation/orbit/bullets.jpg +0 -0
  83. package/test/mocha/html-snapshots/server/images/foundation/orbit/left-arrow-small.png +0 -0
  84. package/test/mocha/html-snapshots/server/images/foundation/orbit/left-arrow.png +0 -0
  85. package/test/mocha/html-snapshots/server/images/foundation/orbit/loading.gif +0 -0
  86. package/test/mocha/html-snapshots/server/images/foundation/orbit/mask-black.png +0 -0
  87. package/test/mocha/html-snapshots/server/images/foundation/orbit/pause-black.png +0 -0
  88. package/test/mocha/html-snapshots/server/images/foundation/orbit/right-arrow-small.png +0 -0
  89. package/test/mocha/html-snapshots/server/images/foundation/orbit/right-arrow.png +0 -0
  90. package/test/mocha/html-snapshots/server/images/foundation/orbit/rotator-black.png +0 -0
  91. package/test/mocha/html-snapshots/server/images/foundation/orbit/timer-black.png +0 -0
  92. package/test/mocha/html-snapshots/server/images/home-sprite/certification.png +0 -0
  93. package/test/mocha/html-snapshots/server/images/home-sprite/cleantrust.png +0 -0
  94. package/test/mocha/html-snapshots/server/images/home-sprite/institute.png +0 -0
  95. package/test/mocha/html-snapshots/server/images/home-sprite-s1a48fdbd81.png +0 -0
  96. package/test/mocha/html-snapshots/server/images/logo-300.png +0 -0
  97. package/test/mocha/html-snapshots/server/images/slider1-lg.jpg +0 -0
  98. package/test/mocha/html-snapshots/server/images/slider1.jpg +0 -0
  99. package/test/mocha/html-snapshots/server/index.css +0 -1
  100. package/test/mocha/html-snapshots/server/index.html +0 -57
  101. package/test/mocha/html-snapshots/server/nojq/index.html +0 -46
  102. package/test/mocha/html-snapshots/server/pjsopts/index.html +0 -55
  103. package/test/mocha/html-snapshots/server/public/page-sitemap.xml +0 -16
  104. package/test/mocha/html-snapshots/server/public/wordpress/category-sitemap.xml +0 -13
  105. package/test/mocha/html-snapshots/server/public/wordpress/page-sitemap.xml +0 -16
  106. package/test/mocha/html-snapshots/server/public/wordpress/post-sitemap.xml +0 -27
  107. package/test/mocha/html-snapshots/server/public/wordpress/post_tag-sitemap.xml +0 -17
  108. package/test/mocha/html-snapshots/server/public/wordpress/product-sitemap.xml +0 -13
  109. package/test/mocha/html-snapshots/server/public/wordpress-2/category-sitemap.xml +0 -13
  110. package/test/mocha/html-snapshots/server/public/wordpress-2/page-sitemap.xml +0 -16
  111. package/test/mocha/html-snapshots/server/public/wordpress-2/post-sitemap.xml +0 -27
  112. package/test/mocha/html-snapshots/server/public/wordpress-2/post_tag-sitemap.xml +0 -17
  113. package/test/mocha/html-snapshots/server/public/wordpress-2/product-sitemap.xml +0 -13
  114. package/test/mocha/html-snapshots/server/require.js +0 -1
  115. package/test/mocha/html-snapshots/server/services/carpets/index.html +0 -57
  116. package/test/mocha/html-snapshots/server/test_robots.txt +0 -13
  117. package/test/mocha/html-snapshots/server/test_robots_sitemap.txt +0 -15
  118. package/test/mocha/html-snapshots/server/test_robots_sitemap.xml +0 -22
  119. package/test/mocha/html-snapshots/server/test_sitemap_index-2.xml +0 -25
  120. package/test/mocha/html-snapshots/server/test_sitemap_index-3.xml +0 -25
  121. package/test/mocha/html-snapshots/server/test_sitemap_index.xml +0 -25
  122. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/extras/custom-validity.js +0 -1
  123. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/extras/modernizr-custom.js +0 -1
  124. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/extras/mousepress.js +0 -1
  125. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/polyfiller.js +0 -1
  126. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/FlashCanvas/canvas2png.js +0 -1
  127. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/FlashCanvas/flashcanvas.js +0 -1
  128. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/FlashCanvas/flashcanvas.swf +0 -0
  129. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/FlashCanvas/proxy.php +0 -73
  130. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/FlashCanvas/save.php +0 -49
  131. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/FlashCanvasPro/canvas2png.js +0 -1
  132. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/FlashCanvasPro/flash10canvas.swf +0 -0
  133. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/FlashCanvasPro/flash9canvas.swf +0 -0
  134. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/FlashCanvasPro/flashcanvas.js +0 -1
  135. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/FlashCanvasPro/proxy.php +0 -73
  136. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/FlashCanvasPro/save.php +0 -49
  137. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/1.js +0 -1
  138. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/10.js +0 -1
  139. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/11.js +0 -1
  140. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/12.js +0 -1
  141. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/13.js +0 -1
  142. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/14.js +0 -1
  143. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/15.js +0 -1
  144. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/16.js +0 -1
  145. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/17.js +0 -1
  146. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/18.js +0 -1
  147. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/19.js +0 -1
  148. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/2.js +0 -1
  149. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/20.js +0 -1
  150. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/21.js +0 -1
  151. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/22.js +0 -1
  152. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/23.js +0 -1
  153. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/24.js +0 -1
  154. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/25.js +0 -1
  155. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/26.js +0 -1
  156. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/27.js +0 -1
  157. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/3.js +0 -1
  158. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/4.js +0 -1
  159. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/5.js +0 -1
  160. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/59.js +0 -1
  161. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/6.js +0 -1
  162. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/7.js +0 -1
  163. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/8.js +0 -1
  164. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/combos/9.js +0 -1
  165. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/details.js +0 -1
  166. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/dom-extend.js +0 -1
  167. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/es5.js +0 -1
  168. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/excanvas.js +0 -1
  169. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/form-core.js +0 -1
  170. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/form-datalist.js +0 -1
  171. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/form-message.js +0 -1
  172. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/form-native-extend.js +0 -1
  173. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/form-number-date-api.js +0 -1
  174. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/form-number-date-ui.js +0 -1
  175. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/form-shim-extend.js +0 -1
  176. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/geolocation.js +0 -1
  177. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-ar.js +0 -1
  178. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-ch-ZN.js +0 -1
  179. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-de.txt +0 -33
  180. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-el.js +0 -1
  181. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-en.txt +0 -34
  182. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-es.js +0 -1
  183. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-fr.js +0 -1
  184. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-he.js +0 -1
  185. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-hi.js +0 -1
  186. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-hu.js +0 -1
  187. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-it.js +0 -1
  188. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-ja.js +0 -1
  189. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-nl.js +0 -1
  190. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-pt-PT.js +0 -1
  191. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-ru.js +0 -1
  192. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/i18n/errormessages-sv.js +0 -1
  193. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/json-storage.js +0 -1
  194. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/jwplayer/license.txt +0 -1
  195. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/jwplayer/player.swf +0 -0
  196. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/jwplayer/readme.html +0 -87
  197. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/mediaelement-core.js +0 -1
  198. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/mediaelement-jaris.js +0 -1
  199. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/mediaelement-native-fix.js +0 -1
  200. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/mediaelement-swf.js +0 -1
  201. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/mediaelement-yt.js +0 -1
  202. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/styles/details-arrows.png +0 -0
  203. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/styles/forms.png +0 -0
  204. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/styles/polyfill-loader.gif +0 -0
  205. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/styles/shim.css +0 -1
  206. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/swf/JarisFLVPlayer.swf +0 -0
  207. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/swf/jwwebshims.swf +0 -0
  208. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/swf/localStorage.swf +0 -0
  209. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/track-ui.js +0 -1
  210. package/test/mocha/html-snapshots/server/vendor/js/libs/webshim/minified/shims/track.js +0 -1
  211. package/test/mocha/html-snapshots/server/vendor/js/plugins/cload.js +0 -49
  212. package/test/mocha/html-snapshots/server/vendor/js/plugins/modernizr.js +0 -4
  213. package/test/mocha/html-snapshots/server/vendor/js/plugins/oldie.js +0 -74
  214. package/test/mocha/html-snapshots/sitemap-index.js +0 -140
  215. package/test/mocha/html-snapshots/sitemap.js +0 -104
  216. package/test/mocha/html-snapshots/snapshot-scripts.js +0 -206
  217. package/test/mocha/html-snapshots/test.js +0 -105
  218. package/test/mocha/html-snapshots/test_robots.txt +0 -13
  219. package/test/mocha/html-snapshots/test_sitemap.xml +0 -22
  220. package/test/mocha/html-snapshots/use-jquery.js +0 -144
  221. package/test/mocha/html-snapshots/utils.js +0 -200
  222. package/test/mocha/input-generators/server/public/wordpress/category-sitemap.xml +0 -13
  223. package/test/mocha/input-generators/server/public/wordpress/page-sitemap.xml +0 -16
  224. package/test/mocha/input-generators/server/public/wordpress/post-sitemap.xml +0 -55
  225. package/test/mocha/input-generators/server/public/wordpress/post_tag-sitemap.xml +0 -25
  226. package/test/mocha/input-generators/server/public/wordpress/product-sitemap.xml +0 -13
  227. package/test/mocha/input-generators/server/test_robots.txt +0 -15
  228. package/test/mocha/input-generators/server/test_robots_bad.txt +0 -11
  229. package/test/mocha/input-generators/server/test_robots_sitemap.txt +0 -17
  230. package/test/mocha/input-generators/server/test_robots_sitemap_bad.txt +0 -17
  231. package/test/mocha/input-generators/server/test_robots_sitemap_multi.txt +0 -18
  232. package/test/mocha/input-generators/server/test_sitemap.xml +0 -34
  233. package/test/mocha/input-generators/server/test_sitemap.xml.gz +0 -0
  234. package/test/mocha/input-generators/server/test_sitemap_bad.xml.gz +0 -0
  235. package/test/mocha/input-generators/server/test_sitemap_index.xml +0 -25
  236. package/test/mocha/input-generators/server/test_sitemap_index.xml.gz +0 -0
  237. package/test/mocha/input-generators/server/test_sitemap_index_empty.xml +0 -3
  238. package/test/mocha/input-generators/server/test_sitemap_index_malformed.xml +0 -2
  239. package/test/mocha/input-generators/sitemap-index.js +0 -87
  240. package/test/mocha/input-generators/sitemap.js +0 -320
  241. package/test/mocha/input-generators/test.js +0 -1447
  242. package/test/mocha/input-generators/test_line.txt +0 -5
  243. package/test/mocha/input-generators/test_robots.txt +0 -15
  244. package/test/mocha/input-generators/test_robots_bad.txt +0 -11
  245. package/test/mocha/input-generators/test_robots_sitemap.txt +0 -17
  246. package/test/mocha/input-generators/test_robots_sitemap_bad.txt +0 -17
  247. package/test/mocha/input-generators/test_robots_sitemap_multi.txt +0 -18
  248. package/test/mocha/input-generators/test_sitemap.xml +0 -34
  249. package/test/mocha/input-generators/test_sitemap.xml.gz +0 -0
  250. package/test/mocha/input-generators/test_sitemap_bad.xml.gz +0 -0
  251. package/test/mocha/input-generators/test_sitemap_index.xml +0 -25
  252. package/test/mocha/input-generators/test_sitemap_index.xml.gz +0 -0
  253. package/test/server/index.js +0 -32
@@ -27,7 +27,8 @@ function ensure (options, must) {
27
27
  }
28
28
 
29
29
  /**
30
- * simple test for url
30
+ * Simple test for url
31
+ *
31
32
  * If you can think of a more approriate test for this use case,
32
33
  * please let me know in the issues...
33
34
  *
@@ -41,6 +42,55 @@ function isUrl (obj) {
41
42
  return false;
42
43
  }
43
44
 
45
+ /**
46
+ * Simple test for a function
47
+ *
48
+ * @param {Any} value - Some object to test.
49
+ * @returns {Boolean} True if is a function, false otherwise.
50
+ */
51
+ function isFunction (value) {
52
+ return typeof value === "function";
53
+ }
54
+
55
+ /**
56
+ * Simple test for an object
57
+ *
58
+ * @param {Any} value - Some object to test.
59
+ * @returns {Boolean} True if is an object, false otherwise.
60
+ */
61
+ function isObject (value) {
62
+ const type = typeof value;
63
+ return value != null && type === "object";
64
+ }
65
+
66
+ /**
67
+ * Wrap a function so it runs one time only.
68
+ *
69
+ * @param {Function} fn - The function to run once only.
70
+ * @param {...any} args - The arguments.
71
+ * @returns {Function} To run the given function once only.
72
+ */
73
+ function once (fn, ...args) {
74
+ function onceWrapper () {
75
+ if (!this.ran) {
76
+ this.ran = true;
77
+ return fn(...args);
78
+ }
79
+ }
80
+ onceWrapper.ran = false;
81
+ return onceWrapper.bind(onceWrapper);
82
+ }
83
+
84
+ /**
85
+ * Get the first element of an array.
86
+ *
87
+ * @param {Array} array
88
+ * @returns {Any} The first value of an array or undefined.
89
+ */
90
+ function head (array) {
91
+ return (array && array.length) ? array[0] : undefined;
92
+ }
93
+
44
94
  /**
45
95
  * Prepend a message to an Error message.
46
96
  *
@@ -103,8 +153,12 @@ function checkResponse (res, mediaTypes) {
103
153
  }
104
154
 
105
155
  module.exports = {
156
+ checkResponse,
106
157
  ensure,
158
+ head,
107
159
  isUrl,
108
- prependMsgToErr,
109
- checkResponse
160
+ isFunction,
161
+ isObject,
162
+ once,
163
+ prependMsgToErr
110
164
  };
@@ -6,7 +6,6 @@
6
6
  */
7
7
  const fs = require("fs");
8
8
  const pathLib = require("path");
9
- const mkdirp = require("mkdirp");
10
9
  const common = require("../index");
11
10
  const base = require("../../input-generators/_base");
12
11
 
@@ -19,7 +18,9 @@ const base = require("../../input-generators/_base");
19
18
  function prepareWrite (outputPath, callback) {
20
19
  const path = pathLib.parse(outputPath);
21
20
  const dir = pathLib.join(path.root, path.dir);
22
- mkdirp(dir).then(() => callback()).catch(callback);
21
+ fs.mkdir(dir, { recursive: true }, err => {
22
+ callback(err);
23
+ });
23
24
  }
24
25
 
25
26
  /**
@@ -6,7 +6,6 @@
6
6
  * Copyright (c) 2013 - 2022 Alex Grant, LocalNerve, contributors
7
7
  * Licensed under the MIT license.
8
8
  */
9
- const _ = require("lodash");
10
9
  const smc = require("./sitemap-collection");
11
10
 
12
11
  /**
@@ -26,9 +25,7 @@ function sitemapIndexUrls (smLib, options, parseResult) {
26
25
  };
27
26
 
28
27
  // Check if we should process each sitemap in the index.
29
- _.forEach(
30
- // if the sitemap index is malformed, just blow up
31
- parseResult.sitemapindex.sitemap,
28
+ parseResult.sitemapindex?.sitemap?.forEach(
32
29
  sitemapNode => {
33
30
  // optionally ignore current sitemaps by sitemap policy
34
31
  const shouldProcess = !options.sitemapPolicy ||
@@ -13,7 +13,6 @@ const util = require("util");
13
13
  const path = require("path");
14
14
  const urlm = require("url");
15
15
  const zlib = require("zlib");
16
- const _ = require("lodash");
17
16
  const xml2js = require("xml2js");
18
17
  const smi = require("./sitemap-index");
19
18
  const common = require("../index");
@@ -47,8 +46,9 @@ function stillCurrent (urlNode, options) {
47
46
  let lesser, greater, oPath;
48
47
  const statOpts = {throwIfNoEntry: false};
49
48
  const now = Date.now();
50
- const lMod = _.first(urlNode.lastmod);
51
- const cFreq = _.first(urlNode.changefreq) ? _.first(urlNode.changefreq).toLowerCase() : null;
49
+ const lMod = common.head(urlNode.lastmod);
50
+ const cFreq = common.head(urlNode.changefreq) ?
51
+ common.head(urlNode.changefreq).toLowerCase() : null;
52
52
 
53
53
  // only lastmod specified
54
54
  if (lMod && !cFreq) {
@@ -101,12 +101,11 @@ function parse (options, document, callback) {
101
101
  .catch(callback);
102
102
  } else {
103
103
  // Process the url input, but break if base.input returns false.
104
- // In other words, _.find is looking for a non-falsy err.
104
+ // In other words, result.urlset.url.find is looking for a non-falsy err.
105
105
  // For now, this can only happen if no outputDir is defined,
106
106
  // which is a fatal bad option problem and will happen immediately.
107
- _.find(
108
- // if the sitemap is malformed, just blow up
109
- result.urlset.url,
107
+ // if sitemap malformed (result.urlset.url is not array), just blow up...
108
+ result.urlset.url.find(
110
109
  urlNode => {
111
110
  // optionally ignore current urls by sitemap policy
112
111
  let url;
@@ -116,12 +115,15 @@ function parse (options, document, callback) {
116
115
  if (process) {
117
116
  // if sitemap is malformed, just blow up
118
117
  url = urlm.parse(urlNode.loc[0]);
119
- if (!base.input(_.extend({}, options, {
120
- protocol: url.protocol,
121
- auth: url.auth,
122
- hostname: url.hostname,
123
- port: url.port
124
- }),
118
+ if (!base.input(
119
+ { ...options,
120
+ ...{
121
+ protocol: url.protocol,
122
+ auth: url.auth,
123
+ hostname: url.hostname,
124
+ port: url.port
125
+ }
126
+ },
125
127
  urlNode.loc[0])
126
128
  ) {
127
129
  source = urlNode.loc[0];
@@ -15,7 +15,6 @@ const path = require("path");
15
15
  const EventEmitter = require("events").EventEmitter;
16
16
  const rimraf = require("rimraf").sync;
17
17
  const asyncLib = require("async");
18
- const _ = require("lodash");
19
18
 
20
19
  const common = require("./common");
21
20
  const inputFactory = require("./input-generators");
@@ -108,7 +107,7 @@ function phantomjsWorker (input, options, notifier, qcb) {
108
107
  if (!notifier.known(input.outputFile)) {
109
108
 
110
109
  // map snapshotScript object script to a real path
111
- if (_.isObject(options.snapshotScript)) {
110
+ if (common.isObject(options.snapshotScript)) {
112
111
  snapshotScript = `${path.join(__dirname, phantomDir, options.snapshotScript.script)}.js`;
113
112
  customModule = options.snapshotScript.module;
114
113
  }
@@ -176,7 +175,7 @@ function puppeteerWorker (input, options, notifier, qcb) {
176
175
  if (!notifier.known(input.outputFile)) {
177
176
 
178
177
  // map snapshotScript object script
179
- if (_.isObject(options.snapshotScript)) {
178
+ if (common.isObject(options.snapshotScript)) {
180
179
  snapshotScript = options.puppeteer;
181
180
  if (options.snapshotScript.script === "removeScripts") {
182
181
  filter = "./removeScripts";
@@ -280,7 +279,7 @@ module.exports = {
280
279
  const completion = new Promise((resolve, reject) => {
281
280
  function completionResolver (err, completed) {
282
281
  try {
283
- _.isFunction(listener) && listener(err, completed);
282
+ common.isFunction(listener) && listener(err, completed);
284
283
  } catch (e) {
285
284
  console.error("User supplied listener exception", e);
286
285
  }
@@ -297,7 +296,7 @@ module.exports = {
297
296
 
298
297
  // create a worker queue with a parallel process limit.
299
298
  const q = asyncLib.queue(
300
- (task, callback) => { task(_.once(callback)); },
299
+ (task, callback) => { task(common.once(callback)); },
301
300
  options.processLimit
302
301
  );
303
302
 
@@ -313,7 +312,7 @@ module.exports = {
313
312
 
314
313
  // generate input for the snapshots.
315
314
  return inputGenerator.run(options, input => {
316
- q.push(_.partial(worker, input, options, notifier));
315
+ q.push(worker.bind(worker, input, options, notifier));
317
316
  }).then(() => completion)
318
317
  }
319
318
 
@@ -10,7 +10,6 @@
10
10
  const EventEmitter = require("events").EventEmitter;
11
11
  const path = require("path");
12
12
  const urlm = require("url");
13
- const _ = require("lodash");
14
13
  const common = require("../common");
15
14
 
16
15
  // Defaults for this module
@@ -80,10 +79,11 @@ function normalize (obj) {
80
79
  */
81
80
  function supplyMissingDefault (options, name) {
82
81
  if (options[name]() === void 0) {
83
- options[name] = _.wrap(options[name], (func, key) => {
84
- const res = func(key);
82
+ const originalFn = options[name].bind(options[name]);
83
+ options[name] = key => {
84
+ const res = originalFn(key);
85
85
  return res === void 0 ? defaults[name] : res;
86
- });
86
+ };
87
87
  }
88
88
  }
89
89
 
@@ -184,7 +184,7 @@ function getOutputPath (options, page, parse) {
184
184
  * @returns {String|Boolean} The full path to the output file or false on failure.
185
185
  */
186
186
  function mapOutputFile (options, page, parse) {
187
- if (!_.isFunction(options.outputPath)) {
187
+ if (!common.isFunction(options.outputPath)) {
188
188
  options.outputPath = normalize(options.outputPath);
189
189
  }
190
190
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-snapshots",
3
- "version": "1.3.2",
3
+ "version": "1.5.0",
4
4
  "author": {
5
5
  "name": "Alex Grant",
6
6
  "email": "alex@localnerve.com",
@@ -22,6 +22,7 @@
22
22
  "test": "mocha test/mocha/**/*.js --exit --recursive --reporter spec",
23
23
  "test:async": "mocha test/mocha/async/test.js --exit --reporter spec",
24
24
  "test:common": "mocha test/mocha/common/*.js --exit --reporter spec",
25
+ "test:common:debug": "mocha --inspect-brk test/mocha/common/*.js --exit --reporter spec",
25
26
  "test:browsers": "mocha test/mocha/browsers/test.js --exit --reporter spec",
26
27
  "test:browsers:cover": "c8 -- npm run test:browsers",
27
28
  "test:input-generators": "mocha test/mocha/input-generators/*.js --exit --reporter spec",
@@ -55,16 +56,14 @@
55
56
  "async": "3.2.4",
56
57
  "async-lock": "1.4.0",
57
58
  "combine-errors": "3.0.3",
58
- "got": "12.5.2",
59
- "lodash": "4.17.21",
60
- "mkdirp": "1.0.4",
59
+ "got": "12.5.3",
61
60
  "phantomjs-prebuilt": "2.1.16",
62
- "puppeteer": "^19.2.2",
61
+ "puppeteer": "^19.3.0",
63
62
  "rimraf": "3.0.2",
64
63
  "xml2js": "0.4.23"
65
64
  },
66
65
  "devDependencies": {
67
- "eslint": "8.26.0",
66
+ "eslint": "8.28.0",
68
67
  "express": "4.18.2",
69
68
  "mocha": "10.1.0",
70
69
  "c8": "7.12.0",
package/.c8rc.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "reports-dir": "coverage",
3
- "reporter": "lcov",
4
- "exclude": ["tmp", "docs", "node_modules", "test", ".github", "coverage", "examples"]
5
- }
package/.eslintignore DELETED
@@ -1,5 +0,0 @@
1
- examples/*
2
- docs/*
3
- tmp/*
4
- coverage/*
5
- test/mocha/html-snapshots/server
package/.eslintrc.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "parserOptions": {
3
- "ecmaVersion": 2020,
4
- "sourceType": "module"
5
- },
6
- "env": {
7
- "node": true,
8
- "es2020": true
9
- },
10
- "extends": [
11
- "eslint:recommended"
12
- ],
13
- "rules": {
14
- "no-console": 0
15
- }
16
- }
@@ -1,16 +0,0 @@
1
- ### Expected Behavior
2
-
3
-
4
-
5
- ### Actual Behavior
6
-
7
-
8
-
9
- ### Options
10
- ```javascript
11
- {
12
- // Paste the html-snapshots options you used to create the problem here.
13
- }
14
- ```
15
-
16
- ### Node Version
@@ -1,32 +0,0 @@
1
- name: Verify
2
- on:
3
- push:
4
- branches: [ master ]
5
- pull_request:
6
- branches: [ master ]
7
-
8
- jobs:
9
- verify:
10
-
11
- runs-on: ubuntu-latest
12
-
13
- strategy:
14
- matrix:
15
- node-version: [14.x, 16.x, 18.x]
16
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
17
-
18
- steps:
19
- - uses: actions/checkout@v3
20
- - name: Use Node.js ${{ matrix.node-version }}
21
- uses: actions/setup-node@v3
22
- with:
23
- node-version: ${{ matrix.node-version }}
24
- - run: npm ci
25
- - name: Lint, Test, And Coverage
26
- run: npm run lint && xvfb-run -a npm run test:cover
27
- - name: Coverage Upload
28
- if: ${{ success() }}
29
- uses: coverallsapp/github-action@master
30
- with:
31
- github-token: ${{ secrets.GITHUB_TOKEN }}
32
- path-to-lcov: ./coverage/lcov.info
@@ -1,43 +0,0 @@
1
- # A Real html-snapshots Usage Example
2
-
3
- > This article explains an implementation using [html-snapshots](https://github.com/localnerve/html-snapshots) in the wild \(with real, working code\). Please note the code referenced in this article was written by LocalNerve and is subject to the terms of this [license](https://github.com/localnerve/wpspa/blob/master/LICENSE.txt).
4
- **NOTE:** This is an older article and usage style is html-snapshots version 0.13.2.
5
-
6
- ## Summary
7
- The [WPSPA](http://github.com/localnerve/wpspa) project uses [html-snapshots](https://github.com/localnerve/html-snapshots) on [Heroku](https://www.heroku.com/) to populate a Redis store from which the snapshotted html is served on \_escaped\_fragment\_ requests. The [html-snapshots](https://github.com/localnerve/html-snapshots) library is run in a Heroku worker process that periodically keeps the snapshots up-to-date with a CMS.
8
-
9
- The application content and routes in [WPSPA](http://github.com/localnerve/wpspa) are dynamic, so this required me to run [html-snapshots](https://github.com/localnerve/html-snapshots) in a worker on the server to get the dynamic content updates over time.
10
-
11
- > Langauge: Javascript
12
-
13
- > Tools: NodeJS, ExpressJS, PhantomJS, Redis
14
-
15
- ## Serving Html Snapshots in a Scalable Cloud Environment
16
- Since [WPSPA](http://github.com/localnerve/wpspa) runs on Heroku, it is serving the application from [Dynos](https://devcenter.heroku.com/articles/dynos). In essence, Dynos are billable CPU/Memory hours with independent, ephemeral file systems. Dynos can be created and destroyed at will to scale the application. Which one you get when you visit the site is up to the [Heroku routing mesh](https://devcenter.heroku.com/articles/http-routing).
17
-
18
- When a Dyno is started, it gets a copy of the files that it was deployed with in its ephemeral file system. So if your app serves dynamic content from a CMS \(as is the case with [WPSPA](http://github.com/localnerve/wpspa)\), anytime your Dyno starts you get an out-of-date version of the snapshots in the ephemeral file system. In general, managing and serving continually updated content with static html snapshot files will not work on Heroku \(or probably any scalable environment\).
19
-
20
- To see this problem further, the snapshots are being taken from a worker process running on a schedule in a short-lived worker Dyno. The worker does not have access or control of the other Dynos, nor should it. So, to make the snapshots available to web Dynos, they have to be stored in a commonly accessible area \(accessible to worker and web Dynos\), and persist when any or all of them are destroyed. For [WPSPA](http://github.com/localnerve/wpspa), I chose to store them in Redis.
21
-
22
- ### ExpressJS
23
- The snapshots produced by [html-snapshots](https://github.com/localnerve/html-snapshots) are served by custom [ExpressJS](http://expressjs.com/) middleware. The middleware checks to see if it has received an \_escaped\_fragment\_ request. If it has, it retreives the snapshot from Redis and sends it to the client.
24
-
25
- > Middleware code: [wpspa/server/middleware/snapshots.js](https://github.com/localnerve/wpspa/blob/master/server/middleware/snapshots.js)
26
-
27
- The snapshots middleware is loaded higher in the stack, and an example of that placement \(in relation to other things\) can be found in the [WPSPA](http://github.com/localnerve/wpspa) main application file.
28
-
29
- > Application code: [wpspa/app.js](https://github.com/localnerve/wpspa/blob/master/app.js)
30
-
31
- ### NodeJS Worker
32
- A NodeJS worker process runs periodically to update the html snapshots with content updates from the CMS. I call it the [snapshots](https://github.com/localnerve/wpspa/blob/master/server/workers/snapshots/lib/index.js) worker process. To do this, it gets the actual routes used in the application, produces the snapshots for them using [html-snapshots](https://github.com/localnerve/html-snapshots), then stores them in Redis to be served later on request by the ExpressJS middleware. Actually, the snapshots worker doesn't get the application routes itself, because that task alone is a handy, reusable thing. As such, that task was factored out into its own worker process called [routes](https://github.com/localnerve/wpspa/blob/master/server/workers/routes/lib/index.js).
33
- The [routes](https://github.com/localnerve/wpspa/blob/master/server/workers/routes/lib/index.js) worker process runs the [WPSPA](http://github.com/localnerve/wpspa) app on the server, waits for it to load up in PhantomJS, then asks it what it thinks its application routes are. It then stores those routes in Redis for consumption by the [snapshots](https://github.com/localnerve/wpspa/blob/master/server/workers/snapshots/lib/index.js) worker process as described above. \(The dynamic routes are also consumed by other typical web server things, like a dynamic robots.txt and sitemap.xml\).
34
-
35
- > Snapshots worker code: [snapshots](https://github.com/localnerve/wpspa/blob/master/server/workers/snapshots/lib/index.js)
36
-
37
- > Routes worker code: [routes](https://github.com/localnerve/wpspa/blob/master/server/workers/routes/lib/index.js)
38
-
39
- ## Process Limit
40
- I eat my own dogfood. That's how I find out about things sometimes, and this project was no exception. Using [html-snapshots](https://github.com/localnerve/html-snapshots) on Heroku is how I found out that unconditionally spawning processes for each application route is a not-so-good feature to have. So a while back, I added a limiting [process model](https://github.com/localnerve/html-snapshots/tree/rc-7.1#process-model) and an option to control the size of the process pool, [processLimit](https://github.com/localnerve/html-snapshots/blob/master/README.md#process-control-options). For the [WPSPA](http://github.com/localnerve/wpspa) example on Heroku, the [processLimit is set to one](https://github.com/localnerve/wpspa/blob/16c8b5ef2dbea6593572e914f5f3693c0f9f73fc/server/config/config.json#L43) to force only one PhantomJS process to be running at once for the [snapshots](https://github.com/localnerve/wpspa/blob/master/server/workers/snapshots/lib/index.js) worker process, as I run it in a [one-off Dyno](https://devcenter.heroku.com/articles/one-off-dynos), or in the [scheduler](https://addons.heroku.com/scheduler), with a single billable Dyno available to the Heroku account.
41
-
42
- ## Finally
43
- I hope this brief tour of a Heroku/Redis html-snapshots implementation in [WPSPA](http://github.com/localnerve/wpspa) helped you think about your html snapshot implementation needs.
package/docs/notes.md DELETED
@@ -1,42 +0,0 @@
1
- # Background and Other Notes
2
-
3
- ## Why Does This Exist?
4
- The whole reason I created this library was so that I could be certain I snapshotted the page when expected content arrived (not after some arbitrary time expiration). This way, I could be certain the snapshot actually contained the content I expect.
5
-
6
- ## What if I Don't Know About The Rendered Page Content?
7
- If you aren't interested in exact snapshots, or just want to explore because you don't know about the content detail yet, try this:
8
- 1. Use `"body"` as the `selector` option value (every page will probably have a body).
9
- 2. Set the `checkInterval` option high to give the page some time to render before it is written out. `checkInterval` is the time the phantomjs script waits to check for `selector`, so consider this "render time".
10
- 3. Set the `pollInterval` option higher than `checkInterval`.
11
- 4. Set the `timeout` option much higher to give the whole thing time to transpire. Consider `timeout` as a multiple of `pollInterval`.
12
-
13
- ## What Happens If Your Content Does Not Appear
14
- If your content does not show up visibly in a page according to the page's selector you configured in options, you get a timeout error - not a snapshot.
15
-
16
- > That means the element you select **cannot be hidden** by any method.
17
-
18
- ### Why Visible?
19
- The intention of this library is to take a snapshot when dynamic content has been rendered in the browser, and not before. One way to do that is to check for evidence that the element you selected has been rendered, and that's what the default scripts in this library do.
20
-
21
- ## Caveats
22
-
23
- ### Each Snapshot is Created in a Separate Process
24
- html-snapshots creates a new process for each page to snapshot, and they run in parallel.
25
- To control the parallel processing load, you can specify the `processLimit` option to limit the size of the process pool. In other words, you can limit the number of pages being processed in parallel at any one time. The default pool size is set to 4 PhantomJS processes at a time.
26
-
27
- ### The Default Snapshot Scripts
28
- The default snapshot scripts are:
29
- - ["default"](https://github.com/localnerve/html-snapshots/blob/master/lib/phantom/default.js)
30
- - ["removeScripts"](https://github.com/localnerve/html-snapshots/blob/master/lib/phantom/removeScripts.js)
31
- - ["customFilter"](https://github.com/localnerve/html-snapshots/blob/master/lib/phantom/customFilter.js)
32
-
33
- As of v0.6.x, these do not rely on jQuery unless you specify a true `useJQuery` option. If you set `useJQuery` to true \(globally or per-page\), the page being snapshotted **must load jQuery itself**.
34
-
35
- #### When Using jQuery
36
- When using jQuery, the default snapshot scripts use jQuery is(:visible) on your supplied selector to determine document readiness \(and then triggers the snapshot\). Last I checked, this is only available in Zepto by building in a special [selector module](https://github.com/madrobby/zepto/issues/323).
37
-
38
- #### When Not Using jQuery
39
- When not using jQuery \(the new default behavior, from v0.6.x\), [document.querySelector](https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector) is used to select the element using your supplied selector. The element selected must be an HTMLElement, and is considered visible \(triggering a snapshot\) if both offsetWidth and offsetHeight exist.
40
-
41
- ### Override the Default Snapshot Scripts
42
- To override the default snapshot scripts, supply a path to your own phantomjs script using the `snapshotScript` option.
@@ -1,149 +0,0 @@
1
- # Examples
2
-
3
- + [Per-page Selectors](#example---per-page-selectors-and-timeouts)
4
- + [Per-page Output Paths](#example---per-page-special-output-paths)
5
- + [Per-page jQuery](#example---per-page-selectors-and-jquery)
6
- + [Array Input](#example---array)
7
- + [More Array Input](./simple-promise/)
8
- + [Array Input DRY](./html5rocks/)
9
- + [Sitemap Index](./sitemap-index/)
10
- + [Process Limit](./process-limit/)
11
- + [Script Removal](#example---remote-robotstxt-remove-script-tags-from-html-snapshots)
12
- + [Custom Filters](./custom/)
13
- + [Debug PhantomJS w/Verbose Output](./verbose/)
14
- + [Debug PhantomJS w/Attach](./debug-phantomjs/)
15
- + [Debug Puppeteer in devtools](./debug-puppeteer/)
16
-
17
- ### Example - Per page selectors and timeouts
18
- ```javascript
19
- const htmlSnapshots = require('html-snapshots');
20
- htmlSnapshots.run({
21
- input: 'sitemap',
22
- source: 'https://host.domain/sitemap.xml',
23
- outputDir: './snapshots',
24
- outputDirClean: true,
25
- selector: {
26
- 'https://host.domain/': '#home-content',
27
- '__default': '#dynamic-content'
28
- },
29
- timeout: {
30
- 'https://host.domain/superslowpage/': 20000,
31
- '__default': 10000
32
- }
33
- })
34
- .then(completed => {
35
- // completed is an array of full file paths to the completed snapshots.
36
- })
37
- .catch(error => {
38
- // error is an Error instance.
39
- // error.completed is an array of snapshot file paths that were completed.
40
- // error.notCompleted is an array of file paths that did NOT complete.
41
- });
42
- ```
43
- This reads the urls from your sitemap.xml and produces snapshots in the ./snapshots directory. In this example, a selector named "#dynamic-content" appears in all pages across the site except the home page, where "#home-content" appears \(the appearance of a selector in the output triggers the snapshot\). Finally, a default timeout of 10000 ms is set on all pages except http://https://host.domain/superslowpage/, where it waits 20000 ms.
44
-
45
- ### Example - Per page special output paths
46
- ```javascript
47
- const htmlSnapshots = require('html-snapshots');
48
- htmlSnapshots.run({
49
- input: 'sitemap',
50
- source: 'https://host.domain/sitemap.xml',
51
- outputDir: './snapshots',
52
- outputDirClean: true,
53
- outputPath: {
54
- 'https://host.domain/services/?page=1': 'services/page/1',
55
- 'https://host.domain/services/?page=2': 'services/page/2'
56
- },
57
- selector: '#dynamic-content'
58
- })
59
- .then(completed => {
60
- // completed is an array of full file paths to the completed snapshots.
61
- })
62
- .catch(error => {
63
- // error is an Error instance.
64
- // error.completed is an array of snapshot file paths that were completed.
65
- // error.notCompleted is an array of file paths that did NOT complete.
66
- });
67
- ```
68
- This example implies there are a couple of pages with query strings in sitemap.xml, and we don't want html-snapshots to create directories with query string characters in the names. We would also have a rewrite rule that reflects this same mapping when `_escaped_fragment_` shows up in the querystring of a request so we serve the snapshot from the appropriate directory.
69
-
70
- ### Example - Per page selectors and jQuery
71
- ```javascript
72
- const htmlSnapshots = require('html-snapshots');
73
- htmlSnapshots.run({
74
- source: '/path/to/robots.txt',
75
- hostname: 'mysite.com',
76
- outputDir: './snapshots',
77
- outputDirClean: true,
78
- browser: 'phantomjs',
79
- selector: {
80
- '__default': '#dynamic-content',
81
- '/jqpage': 'A-Selector-Not-Supported-By-querySelector'
82
- },
83
- useJQuery: {
84
- '/jqpage': true,
85
- '__default': false
86
- }
87
- })
88
- .then(completed => {
89
- // completed is an array of full file paths to the completed snapshots.
90
- })
91
- .catch(error => {
92
- // error is an Error instance.
93
- // error.completed is an array of snapshot file paths that were completed.
94
- // error.notCompleted is an array of file paths that did NOT complete.
95
- });
96
- ```
97
- This reads the urls from your robots.txt and produces snapshots in the ./snapshots directory. In this example, a selector named "#dynamic-content" appears in all pages across the site except in "/jqpage", where a selector not supported by [querySelector](https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector) is used. Further, "/jqpage" loads jQuery itself \(required\). All the other pages don't need to use special selectors, so the default is set to `false`. Notice that since a robots.txt input is used, full URLs are **not** used to match selectors. Instead, paths \(and QueryStrings and any Hashes\) are used, just as specified in the robots.txt file itself.
98
-
99
- ### Example - Array
100
- ```javascript
101
- const htmlSnapshots = require('html-snapshots');
102
- htmlSnapshots.run({
103
- input: 'array',
104
- source: ['http://mysite.com', 'http://mysite.com/contact', 'http://mysite.com:82/special'],
105
- outputDir: './snapshots',
106
- outputDirClean: true,
107
- selector: '#dynamic-content'
108
- })
109
- .then(completed => {
110
- // completed is an array of full file paths to the completed snapshots.
111
- })
112
- .catch(error => {
113
- // error is an Error instance.
114
- // error.completed is an array of snapshot file paths that were completed.
115
- // error.notCompleted is an array of file paths that did NOT complete.
116
- });
117
- ```
118
- Generates snapshots for "/", "/contact", and "/special" from mysite.com. "/special" uses port 82. All use http protocol. Array input can be powerful, check out a [simple example](/examples/simple-promise), or a more [complex example](/examples/html5rocks).
119
-
120
- ### Example - Remote robots.txt, remove script tags from html snapshots
121
- ```javascript
122
- const assert = require('assert');
123
- const fs = require('fs');
124
- const htmlSnapshots = require('html-snapshots');
125
-
126
- htmlSnapshots.run({
127
- source: 'http://localhost/robots.txt',
128
- outputDir: './snapshots',
129
- outputDirClean: true,
130
- selector: '#dynamic-content',
131
- snapshotScript: {
132
- script: 'removeScripts'
133
- }
134
- })
135
- .then(completed => {
136
- completed.forEach(snapshotFile => {
137
- const content = fs.readFileSync(snapshotFile, { encoding: 'utf8'});
138
- assert.equal(false, /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi.test(content));
139
- });
140
- // It didn't throw b/c there are no script tags in the html snapshots
141
- console.log('stripped all script tags as expected');
142
- })
143
- .catch(error => {
144
- // error is an Error instance.
145
- // error.completed is an array of snapshot file paths that were completed.
146
- // error.notCompleted is an array of file paths that did NOT complete.
147
- });
148
- ```
149
- Removes all script tags from the output of the html snapshot. Custom filters are also supported, see the customFilter Example in the explanation of the `snapshotScript` option. Also, check out the concrete [example](/examples/custom).
@@ -1,22 +0,0 @@
1
- # Example
2
-
3
- > Snapshot a sample website using a sitemap and custom-filter
4
-
5
- > All examples assume you already have NodeJS installed on your local machine
6
-
7
- ## How To Run
8
- 1. Clone this repo
9
- 2. Open a command prompt
10
- 3. Change to the examples/custom directory
11
- 4. Run `npm install`
12
- 5. Run `npm start`
13
-
14
- ## What It Does
15
- This example snapshots the entire website of the WPSPA example application using its sitemap to drive.
16
-
17
- It makes use of a [custom filter](https://github.com/localnerve/html-snapshots/blob/master/examples/custom/myFilter.js) to strip various tags \(and even replace some text\) from the output before the snapshots are stored.
18
-
19
- ## Notes on Interpreting Results
20
- This example creates a local `tmp` directory where the snapshot output is stored.
21
- Inspect the output directory structure and contents.
22
- Compare snapshots with the original website to see what happened.