html-snapshots 0.18.3 → 1.0.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 (84) hide show
  1. package/.eslintrc.json +4 -5
  2. package/.github/workflows/verify.yml +2 -2
  3. package/HISTORY.md +42 -0
  4. package/README.md +109 -256
  5. package/examples/README.md +149 -0
  6. package/examples/custom/myFilter.js +2 -2
  7. package/examples/custom/package-lock.json +2021 -5
  8. package/examples/custom/package.json +1 -1
  9. package/examples/custom/snapshot.js +8 -10
  10. package/examples/debug-phantomjs/package-lock.json +6 -6
  11. package/examples/debug-phantomjs/package.json +1 -1
  12. package/examples/debug-phantomjs/snapshot.js +13 -14
  13. package/examples/debug-puppeteer/README.md +18 -0
  14. package/examples/debug-puppeteer/package-lock.json +2804 -0
  15. package/examples/debug-puppeteer/package.json +12 -0
  16. package/examples/debug-puppeteer/snapshot.js +30 -0
  17. package/examples/html5rocks/package-lock.json +1306 -5
  18. package/examples/html5rocks/package.json +1 -1
  19. package/examples/html5rocks/snapshot.js +14 -23
  20. package/examples/process-limit/package-lock.json +1306 -5
  21. package/examples/process-limit/package.json +1 -1
  22. package/examples/process-limit/snapshot.js +8 -10
  23. package/examples/simple-promise/package-lock.json +1306 -5
  24. package/examples/simple-promise/package.json +1 -1
  25. package/examples/simple-promise/snapshot.js +6 -8
  26. package/examples/sitemap-index/package-lock.json +1306 -5
  27. package/examples/sitemap-index/package.json +1 -1
  28. package/examples/sitemap-index/snapshot.js +6 -6
  29. package/examples/utils/index.js +2 -4
  30. package/examples/verbose/package-lock.json +1306 -5
  31. package/examples/verbose/package.json +1 -1
  32. package/examples/verbose/snapshot.js +12 -14
  33. package/lib/async/index.js +0 -1
  34. package/lib/common/index.js +1 -1
  35. package/lib/common/sitemap/index.js +16 -0
  36. package/lib/common/sitemap/sitemap-collection.js +94 -0
  37. package/lib/common/sitemap/sitemap-index.js +68 -0
  38. package/lib/common/{sitemap.js → sitemap/sitemap.js} +68 -57
  39. package/lib/html-snapshots.js +87 -5
  40. package/lib/input-generators/_base.js +7 -1
  41. package/lib/input-generators/array.js +0 -1
  42. package/lib/input-generators/robots.js +98 -58
  43. package/lib/input-generators/sitemap-index.js +3 -124
  44. package/lib/input-generators/sitemap.js +3 -7
  45. package/lib/input-generators/textfile.js +2 -6
  46. package/lib/puppeteer/index.js +98 -0
  47. package/lib/puppeteer/removeScripts.js +8 -0
  48. package/package.json +9 -4
  49. package/test/helpers/options.js +4 -2
  50. package/test/mocha/browsers/puppeteer.js +106 -0
  51. package/test/mocha/browsers/server/index.html +9 -0
  52. package/test/mocha/browsers/test.js +11 -0
  53. package/test/mocha/html-snapshots/basics.js +60 -47
  54. package/test/mocha/html-snapshots/phantomjs-options.js +54 -60
  55. package/test/mocha/html-snapshots/process-limit.js +126 -120
  56. package/test/mocha/html-snapshots/puppeteer.js +47 -0
  57. package/test/mocha/html-snapshots/robots.js +156 -121
  58. package/test/mocha/html-snapshots/server/public/page-sitemap.xml +16 -0
  59. package/test/mocha/html-snapshots/server/test_robots.txt +13 -0
  60. package/test/mocha/html-snapshots/server/test_robots_sitemap.txt +15 -0
  61. package/test/mocha/html-snapshots/server/test_robots_sitemap.xml +22 -0
  62. package/test/mocha/html-snapshots/sitemap-index.js +100 -90
  63. package/test/mocha/html-snapshots/sitemap.js +75 -31
  64. package/test/mocha/html-snapshots/snapshot-scripts.js +150 -145
  65. package/test/mocha/html-snapshots/test.js +23 -14
  66. package/test/mocha/html-snapshots/test_robots.txt +0 -2
  67. package/test/mocha/html-snapshots/use-jquery.js +65 -64
  68. package/test/mocha/html-snapshots/utils.js +29 -30
  69. package/test/mocha/input-generators/server/test_robots.txt +0 -2
  70. package/test/mocha/input-generators/server/test_robots_bad.txt +0 -2
  71. package/test/mocha/input-generators/server/test_robots_sitemap.txt +17 -0
  72. package/test/mocha/input-generators/server/test_robots_sitemap_bad.txt +17 -0
  73. package/test/mocha/input-generators/server/test_robots_sitemap_multi.txt +18 -0
  74. package/test/mocha/input-generators/server/test_sitemap_index_empty.xml +3 -0
  75. package/test/mocha/input-generators/server/test_sitemap_index_malformed.xml +2 -0
  76. package/test/mocha/input-generators/sitemap-index.js +65 -9
  77. package/test/mocha/input-generators/test.js +276 -280
  78. package/test/mocha/input-generators/test_robots.txt +0 -2
  79. package/test/mocha/input-generators/test_robots_bad.txt +0 -2
  80. package/test/mocha/input-generators/test_robots_sitemap.txt +17 -0
  81. package/test/mocha/input-generators/test_robots_sitemap_bad.txt +17 -0
  82. package/test/mocha/input-generators/test_robots_sitemap_multi.txt +18 -0
  83. package/lib/common/node.js +0 -26
  84. package/test/mocha/common/node.js +0 -100
@@ -4,48 +4,61 @@
4
4
  * Copyright (c) 2013 - 2022, Alex Grant, LocalNerve, contributors
5
5
  */
6
6
  /* global it */
7
- var assert = require("assert");
8
- var path = require("path");
9
- var _ = require("lodash");
10
- var utils = require("./utils");
11
- var optHelp = require("../../helpers/options");
12
- var ss = require("../../../lib/html-snapshots");
13
-
14
- // missing destructuring, will write postcard...
15
- var timeout = utils.timeout;
16
- var outputDir = utils.outputDir;
17
- var cleanup = utils.cleanup;
18
- var cleanupError = utils.cleanupError;
19
- var unexpectedError = utils.unexpectedError;
20
- var unexpectedSuccess = utils.unexpectedSuccess;
21
- var checkActualFiles = utils.checkActualFiles;
22
-
23
- var useJQOutputDir = path.resolve(outputDir, "..", "useJQuery");
7
+ const assert = require("assert");
8
+ const path = require("path");
9
+ const _ = require("lodash");
10
+ const utils = require("./utils");
11
+ const optHelp = require("../../helpers/options");
12
+ const ss = require("../../../lib/html-snapshots");
13
+
14
+ const {
15
+ timeout,
16
+ outputDir,
17
+ cleanup,
18
+ cleanupError,
19
+ unexpectedError,
20
+ unexpectedSuccess,
21
+ checkActualFiles
22
+ } = utils;
23
+
24
+ const useJQOutputDir = path.resolve(outputDir, "..", "useJQuery");
24
25
 
25
26
  function useJQueryTests (options) {
26
- var port = options.port;
27
+ const {
28
+ port
29
+ } = options;
30
+
31
+ function createOptions (newOptions) {
32
+ const defaultOptions = {
33
+ input: "array",
34
+ source: [ `http://localhost:${port}/nojq` ],
35
+ selector: ".nojq-dynamic",
36
+ outputDir: useJQOutputDir,
37
+ outputDirClean: true,
38
+ browser: "phantomjs",
39
+ timeout,
40
+ useJQuery: true
41
+ };
42
+ return {
43
+ ...defaultOptions,
44
+ ...newOptions
45
+ };
46
+ }
27
47
 
28
48
  return function () {
29
49
  it("should succeed if useJQuery=false, jQuery NOT loaded, dynamic element",
30
50
  function (done) {
31
- var options = {
32
- input: "array",
33
- source: [ "http://localhost:"+port+"/nojq" ],
34
- selector: ".nojq-dynamic", // nojq-dynamic is created onload
35
- //selector: "#pocs1",
36
- outputDir: useJQOutputDir,
37
- outputDirClean: true,
38
- timeout: timeout,
51
+ const options = createOptions({
39
52
  useJQuery: false
40
- };
53
+ });
41
54
 
42
- ss.run(optHelp.decorate(options), function (err, completed) {
55
+ ss.run(optHelp.decorate(options), (err, completed) => {
43
56
  if (err) {
44
- console.log('@@@ error = '+err+", completed="+completed.join(','));
57
+ console.log(`@@@ error = ${err}, completed=${completed.join(',')}`);
45
58
  }
46
59
  })
47
- .then(function (completed) {
48
- var assertionError;
60
+ .then(completed => {
61
+ let assertionError;
49
62
  try {
50
63
  assert.equal(completed.length, 1);
51
64
  assert.equal(completed[0], path.join(useJQOutputDir, "nojq", "index.html"));
@@ -54,31 +67,27 @@ function useJQueryTests (options) {
54
67
  }
55
68
  cleanup(done, assertionError);
56
69
  })
57
- .catch(function (e) {
70
+ .catch(e => {
58
71
  checkActualFiles(e.notCompleted)
59
- .then(function () {
72
+ .then(() => {
60
73
  cleanup(done, e || unexpectedError);
61
74
  });
62
75
  });
63
76
  });
64
77
 
65
78
  it("should succeed if useJQuery=true, jQuery loaded", function (done) {
66
- var options = {
67
- input: "array",
68
- source: [ "http://localhost:"+port+"/" ],
79
+ const options = createOptions({
80
+ source: [ `http://localhost:${port}/` ],
69
81
  selector: "#dynamic-content",
70
- outputDir: outputDir,
71
- outputDirClean: true,
72
- timeout: timeout,
73
- useJQuery: true
74
- };
82
+ outputDir
83
+ });
75
84
 
76
- ss.run(optHelp.decorate(options), function (err, completed) {
85
+ ss.run(optHelp.decorate(options), (err, completed) => {
77
86
  if (err) {
78
- console.log('@@@ error = '+err+", completed="+completed.join(','));
87
+ console.log(`@@@ error = ${err}, completed=${completed.join(',')}`);
79
88
  }
80
89
  })
81
- .then(function (completed) {
90
+ .then(completed => {
82
91
  var assertionError;
83
92
  try {
84
93
  assert.equal(completed.length, 1);
@@ -88,9 +97,9 @@ function useJQueryTests (options) {
88
97
  }
89
98
  cleanup(done, assertionError);
90
99
  })
91
- .catch(function (e) {
100
+ .catch(e => {
92
101
  checkActualFiles(e.notCompleted)
93
- .then(function () {
102
+ .then(() => {
94
103
  cleanup(done, e || unexpectedError);
95
104
  });
96
105
  });
@@ -98,16 +107,12 @@ function useJQueryTests (options) {
98
107
 
99
108
  it("should fail if useJQuery is true and no jQuery loads in target page",
100
109
  function (done) {
101
- var options = {
102
- input: "array",
103
- source: [ "http://localhost:"+port+"/nojq" ],
110
+ const options = createOptions({
104
111
  selector: "#pocs1",
105
- outputDir: useJQOutputDir,
106
- outputDirClean: true,
107
- timeout: 5000,
108
- useJQuery: true
109
- };
110
- var twice = _.after(2, cleanupError.bind(null, done, 0));
112
+ timeout: 4000
113
+ });
114
+
115
+ const twice = _.after(2, cleanupError.bind(null, done, 0));
111
116
 
112
117
  ss.run(optHelp.decorate(options), twice)
113
118
  .then(unexpectedSuccess.bind(null, done))
@@ -116,16 +121,12 @@ function useJQueryTests (options) {
116
121
 
117
122
  it("should fail if useJQuery is false, no jQuery loads in page, BUT the element is not visible",
118
123
  function (done) {
119
- var options = {
120
- input: "array",
121
- source: [ "http://localhost:"+port+"/nojq" ],
124
+ const options = createOptions({
122
125
  selector: ".nojq-notvisible",
123
- outputDir: useJQOutputDir,
124
- outputDirClean: true,
125
- timeout: 5000,
126
- useJQuery: true
127
- };
128
- var twice = _.after(2, cleanupError.bind(null, done, 0));
126
+ timeout: 4000
127
+ });
128
+
129
+ const twice = _.after(2, cleanupError.bind(null, done, 0));
129
130
 
130
131
  ss.run(optHelp.decorate(options), twice)
131
132
  .then(unexpectedSuccess.bind(null, done))
@@ -1,29 +1,28 @@
1
1
  /**
2
- * html-snapshots test utilities and constants.
2
+ * html-snapshots test debug utilities and constants.
3
3
  *
4
4
  * Copyright (c) 2013 - 2022, Alex Grant, LocalNerve, contributors
5
5
  */
6
- /* global Promise */
7
- var path = require("path");
8
- var fs = require("fs");
9
- var _ = require("lodash");
10
- var spawn = require("child_process").spawn;
11
- var assert = require("assert");
12
- var combineErrors = require("combine-errors");
13
- var resHelp = require("../../helpers/result");
14
- var pathExists = require("../../../lib/async/exists");
6
+ const path = require("path");
7
+ const fs = require("fs");
8
+ const _ = require("lodash");
9
+ const spawn = require("child_process").spawn;
10
+ const assert = require("assert");
11
+ const combineErrors = require("combine-errors");
12
+ const resHelp = require("../../helpers/result");
13
+ const pathExists = require("../../../lib/async/exists");
15
14
 
16
15
  // Constants
17
- var unexpectedError = new Error("unexpected error flow");
18
- var outputDir = path.join(__dirname, "./tmp/snapshots");
19
- var spawnedProcessPattern = "^phantomjs$";
20
- var bogusFile = "./bogus/file.txt";
21
- var timeout = 40000;
16
+ const unexpectedError = new Error("unexpected error flow");
17
+ const outputDir = path.join(__dirname, "./tmp/snapshots");
18
+ const spawnedProcessPattern = "^phantomjs$";
19
+ const bogusFile = "./bogus/file.txt";
20
+ const timeout = 20000;
22
21
 
23
22
  function dumpTree (p) {
24
- fs.readdirSync(p).forEach(function (file) {
25
- var curPath = path.join(p, path.sep, file);
26
- var stats = fs.statSync(curPath);
23
+ fs.readdirSync(p).forEach(file => {
24
+ const curPath = path.join(p, path.sep, file);
25
+ const stats = fs.statSync(curPath);
27
26
 
28
27
  if (stats.isDirectory()) {
29
28
  dumpTree(curPath);
@@ -34,7 +33,7 @@ function dumpTree (p) {
34
33
  }
35
34
 
36
35
  function checkActualFiles (files) {
37
- var shortFile, outputRoot;
36
+ let shortFile, outputRoot;
38
37
 
39
38
  if (files.length > 0) {
40
39
  shortFile = outputDir;
@@ -46,7 +45,7 @@ function checkActualFiles (files) {
46
45
  return prev;
47
46
  }, files[0]);
48
47
  */
49
- var exists = false;
48
+ let exists = false; // toggle to dumpTree
50
49
  outputRoot = path.dirname(shortFile);
51
50
  try {
52
51
  fs.statSync(outputRoot).isDirectory();
@@ -59,9 +58,9 @@ function checkActualFiles (files) {
59
58
  }
60
59
  }
61
60
 
62
- return Promise.all(files.map(function (file) {
61
+ return Promise.all(files.map(file => {
63
62
  return pathExists(file)
64
- .then(function (result) {
63
+ .then(result => {
65
64
  if (result) {
66
65
  console.log("@@@ actually exists:" + file);
67
66
  }
@@ -93,10 +92,10 @@ function countSpawnedProcesses (cb) {
93
92
  if (process.platform === "darwin") {
94
93
  wc = spawn("wc", ["-l"]);
95
94
  pgrep = spawn("pgrep", [spawnedProcessPattern]);
96
- pgrep.stdout.on("data", function (data) {
95
+ pgrep.stdout.on("data", data => {
97
96
  wc.stdin.write(data);
98
97
  });
99
- pgrep.stdout.on("end", function () {
98
+ pgrep.stdout.on("end", () => {
100
99
  wc.stdin.end();
101
100
  });
102
101
  wc.stdout.on("data", cb);
@@ -106,16 +105,16 @@ function countSpawnedProcesses (cb) {
106
105
  }
107
106
  }
108
107
 
109
- // Clear any lingering phantomjs processes in play
108
+ // Clear any lingering browser processes in play
110
109
  function killSpawnedProcesses (cb) {
111
110
  var pkill = spawn("pkill", [spawnedProcessPattern]);
112
111
  var guardedCb = _.once(cb);
113
112
 
114
- pkill.on("exit", function () {
113
+ pkill.on("exit", () => {
115
114
  setTimeout(guardedCb, 2000);
116
115
  });
117
- pkill.on("error", function () {
118
- guardedCb(new Error("failed to kill phantomjs processes"));
116
+ pkill.on("error", () => {
117
+ guardedCb(new Error("failed to kill browser processes"));
119
118
  });
120
119
  }
121
120
 
@@ -124,8 +123,8 @@ function cleanup (done, arg) {
124
123
  if (process.platform === "win32") {
125
124
  setTimeout(done, 1000, arg);
126
125
  } else {
127
- setImmediate(function () {
128
- killSpawnedProcesses(function (err) {
126
+ setImmediate(() => {
127
+ killSpawnedProcesses(err => {
129
128
  done(multiError(err, arg));
130
129
  });
131
130
  });
@@ -11,7 +11,5 @@ Disallow: /vendor/
11
11
  Disallow: /fonts/
12
12
  Disallow: /images/
13
13
 
14
- Sitemap: http://northstarcleaningme.com/sitemap.xml
15
-
16
14
  User-agent: ia_archiver
17
15
  Disallow: /
@@ -7,7 +7,5 @@ Disallow: /vendor/
7
7
  Disallow: /fonts/
8
8
  Disallow: /images/
9
9
 
10
- Sitemap: http://northstarcleaningme.com/sitemap.xml
11
-
12
10
  User-agent: ia_archiver
13
11
  Disallow: /
@@ -0,0 +1,17 @@
1
+ User-agent: *
2
+
3
+ Allow: /
4
+ Allow: /contact
5
+ Allow: /services/carpets
6
+ Allow: /services/test?arg=one
7
+ Allow: /services/#hash
8
+
9
+ Disallow: /api/
10
+ Disallow: /vendor/
11
+ Disallow: /fonts/
12
+ Disallow: /images/
13
+
14
+ Sitemap: http://localhost:8033/test_sitemap.xml
15
+
16
+ User-agent: ia_archiver
17
+ Disallow: /
@@ -0,0 +1,17 @@
1
+ User-agent: *
2
+
3
+ Allow: /
4
+ Allow: /contact
5
+ Allow: /services/carpets
6
+ Allow: /services/test?arg=one
7
+ Allow: /services/#hash
8
+
9
+ Disallow: /api/
10
+ Disallow: /vendor/
11
+ Disallow: /fonts/
12
+ Disallow: /images/
13
+
14
+ Sitemap: http://badhost.nowhere/sitemap.xml
15
+
16
+ User-agent: ia_archiver
17
+ Disallow: /
@@ -0,0 +1,18 @@
1
+ User-agent: *
2
+
3
+ Allow: /
4
+ Allow: /contact
5
+ Allow: /services/carpets
6
+ Allow: /services/test?arg=one
7
+ Allow: /services/#hash
8
+
9
+ Disallow: /api/
10
+ Disallow: /vendor/
11
+ Disallow: /fonts/
12
+ Disallow: /images/
13
+
14
+ Sitemap: http://localhost:8033/test_sitemap.xml
15
+ Sitemap: http://localhost:8033/test_sitemap_index.xml
16
+
17
+ User-agent: ia_archiver
18
+ Disallow: /
@@ -0,0 +1,3 @@
1
+ <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//core.codekraft.it/public/wordpress/main-sitemap.xsl"?>
2
+ <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
+ </sitemapindex>
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//core.codekraft.it/public/wordpress/main-sitemap.xsl"?>
2
+ </sitemapindex>
@@ -4,14 +4,13 @@
4
4
  * Copyright (c) 2013 - 2022, Alex Grant, LocalNerve, contributors
5
5
  */
6
6
  /* global describe, it, before */
7
- var assert = require("assert");
8
- // var path = require("path");
9
- // var rimraf = require("rimraf").sync;
10
- // var factory = require("../../../lib/input-generators");
11
- // var server = require("../../server");
12
- // var options = require("../../helpers/options");
7
+ const assert = require("assert");
8
+ const path = require("path");
9
+ const factory = require("../../../lib/input-generators");
10
+ const server = require("../../server");
11
+ const options = require("../../helpers/options");
13
12
  // var smHelper = require("../../helpers/sitemap");
14
- // var port = 9334;
13
+ const port = 9334;
15
14
 
16
15
  describe("input-generator", function () {
17
16
 
@@ -19,13 +18,70 @@ describe("input-generator", function () {
19
18
  // This is just about specific sitemap index option processing
20
19
 
21
20
  describe("sitemap-index", function () {
21
+ let gen;
22
+ const outputDir = path.join(__dirname, "snapshots");
23
+
24
+ function createOptions (overrideOptions) {
25
+ const basicOptions = {
26
+ input: "sitemap-index",
27
+ outputDirClean: true,
28
+ outputDir,
29
+ port
30
+ };
31
+ return {
32
+ ...basicOptions,
33
+ ...overrideOptions
34
+ };
35
+ }
36
+
37
+ function fail (done, message) {
38
+ const msg = message.toString();
39
+ assert.fail(msg);
40
+ done(new Error(msg));
41
+ }
22
42
 
23
43
  before(function () {
24
- // server.start(path.join(__dirname, "./server"), port);
44
+ server.start(path.join(__dirname, "./server"), port);
45
+ gen = factory.create("sitemap-index");
46
+ });
47
+
48
+ it("should handle empty sitemap-index", function (done) {
49
+ const source = `http://localhost:${port}/test_sitemap_index_empty.xml`;
50
+ const opts = createOptions({
51
+ source,
52
+ _abort: err => {
53
+ const msg = `empty sitemap-index should not abort, ${err}`;
54
+ fail(done, msg);
55
+ }
56
+ });
57
+
58
+ const result = gen.run(options.decorate(opts), () => {
59
+ fail(done, "empty sitemap-index should not produce input");
60
+ });
61
+
62
+ result.then(() => done()).catch(fail.bind(null, done));
63
+ });
64
+
65
+ it("should handle malformed sitemap-index", function (done) {
66
+ const source = `http://localhost:${port}/test_sitemap_index_malformed.xml`;
67
+ const opts = createOptions({
68
+ source,
69
+ _abort: err => {
70
+ assert.equal(true, !!err, `${source} should have aborted with error`);
71
+ done();
72
+ }
73
+ });
74
+
75
+ const result = gen.run(
76
+ options.decorate(opts),
77
+ fail.bind(null, done, `Input handler was called unexpectedly for badSource: ${source}`)
78
+ );
79
+
80
+ result.then(() => assert.ok(true)).catch(fail.bind(null, done));
25
81
  });
26
82
 
27
83
  it("TODO: write specific sitemap-index tests", function () {
28
84
  assert.ok(true);
29
- })
85
+ });
30
86
  });
31
87
  });