html-snapshots 0.18.2 → 0.19.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 (65) hide show
  1. package/.eslintrc.json +4 -5
  2. package/README.md +73 -68
  3. package/examples/custom/myFilter.js +2 -2
  4. package/examples/custom/package-lock.json +1012 -77
  5. package/examples/custom/package.json +1 -1
  6. package/examples/custom/snapshot.js +8 -10
  7. package/examples/debug-phantomjs/package-lock.json +76 -76
  8. package/examples/debug-phantomjs/package.json +1 -1
  9. package/examples/debug-phantomjs/snapshot.js +12 -14
  10. package/examples/html5rocks/package-lock.json +1379 -78
  11. package/examples/html5rocks/package.json +1 -1
  12. package/examples/html5rocks/snapshot.js +15 -18
  13. package/examples/process-limit/package-lock.json +1379 -78
  14. package/examples/process-limit/package.json +1 -1
  15. package/examples/process-limit/snapshot.js +8 -10
  16. package/examples/simple-promise/package-lock.json +1379 -78
  17. package/examples/simple-promise/package.json +1 -1
  18. package/examples/simple-promise/snapshot.js +6 -8
  19. package/examples/sitemap-index/package-lock.json +1378 -77
  20. package/examples/sitemap-index/package.json +1 -1
  21. package/examples/sitemap-index/snapshot.js +6 -6
  22. package/examples/utils/index.js +2 -4
  23. package/examples/verbose/package-lock.json +1380 -78
  24. package/examples/verbose/package.json +1 -1
  25. package/examples/verbose/snapshot.js +11 -14
  26. package/lib/async/index.js +0 -1
  27. package/lib/common/index.js +1 -1
  28. package/lib/common/sitemap/index.js +16 -0
  29. package/lib/common/sitemap/sitemap-collection.js +94 -0
  30. package/lib/common/sitemap/sitemap-index.js +68 -0
  31. package/lib/common/{sitemap.js → sitemap/sitemap.js} +68 -57
  32. package/lib/html-snapshots.js +0 -1
  33. package/lib/input-generators/array.js +0 -1
  34. package/lib/input-generators/robots.js +98 -58
  35. package/lib/input-generators/sitemap-index.js +3 -124
  36. package/lib/input-generators/sitemap.js +3 -7
  37. package/lib/input-generators/textfile.js +2 -6
  38. package/package.json +6 -6
  39. package/test/helpers/options.js +4 -2
  40. package/test/mocha/html-snapshots/process-limit.js +46 -48
  41. package/test/mocha/html-snapshots/robots.js +156 -138
  42. package/test/mocha/html-snapshots/server/test_robots.txt +13 -0
  43. package/test/mocha/html-snapshots/server/test_robots_sitemap.txt +15 -0
  44. package/test/mocha/html-snapshots/server/test_robots_sitemap.xml +22 -0
  45. package/test/mocha/html-snapshots/sitemap-index.js +58 -57
  46. package/test/mocha/html-snapshots/snapshot-scripts.js +55 -54
  47. package/test/mocha/html-snapshots/test.js +16 -16
  48. package/test/mocha/html-snapshots/test_robots.txt +0 -2
  49. package/test/mocha/html-snapshots/utils.js +0 -1
  50. package/test/mocha/input-generators/server/test_robots.txt +0 -2
  51. package/test/mocha/input-generators/server/test_robots_bad.txt +0 -2
  52. package/test/mocha/input-generators/server/test_robots_sitemap.txt +17 -0
  53. package/test/mocha/input-generators/server/test_robots_sitemap_bad.txt +17 -0
  54. package/test/mocha/input-generators/server/test_robots_sitemap_multi.txt +18 -0
  55. package/test/mocha/input-generators/server/test_sitemap_index_empty.xml +3 -0
  56. package/test/mocha/input-generators/server/test_sitemap_index_malformed.xml +2 -0
  57. package/test/mocha/input-generators/sitemap-index.js +65 -9
  58. package/test/mocha/input-generators/test.js +276 -280
  59. package/test/mocha/input-generators/test_robots.txt +0 -2
  60. package/test/mocha/input-generators/test_robots_bad.txt +0 -2
  61. package/test/mocha/input-generators/test_robots_sitemap.txt +17 -0
  62. package/test/mocha/input-generators/test_robots_sitemap_bad.txt +17 -0
  63. package/test/mocha/input-generators/test_robots_sitemap_multi.txt +18 -0
  64. package/lib/common/node.js +0 -26
  65. package/test/mocha/common/node.js +0 -100
@@ -4,156 +4,174 @@
4
4
  * Copyright (c) 2013 - 2022, Alex Grant, LocalNerve, contributors
5
5
  */
6
6
  /* global it */
7
- var path = require("path");
8
- var rimraf = require("rimraf").sync;
9
- var _ = require("lodash");
10
- var optHelp = require("../../helpers/options");
11
- var ss = require("../../../lib/html-snapshots");
12
- var utils = require("./utils");
13
-
14
- // missing destructuring, will write postcard...
15
- var timeout = utils.timeout;
16
- var outputDir = utils.outputDir;
17
- var cleanup = utils.cleanup;
18
- var cleanupSuccess = utils.cleanupSuccess;
19
- var cleanupError = utils.cleanupError;
20
- var testSuccess = utils.testSuccess;
21
- var bogusFile = utils.bogusFile;
22
- var unexpectedSuccess = utils.unexpectedSuccess;
23
- var checkActualFiles = utils.checkActualFiles;
24
-
25
- // Robots constants
26
- var inputFile = path.join(__dirname, "./test_robots.txt");
27
- var urls = 3; // must match test_robots.txt
7
+ const rimraf = require("rimraf").sync;
8
+ const _ = require("lodash");
9
+ const common = require("../../../lib/common");
10
+ const optHelp = require("../../helpers/options");
11
+ const ss = require("../../../lib/html-snapshots");
12
+ const utils = require("./utils");
13
+
14
+ const {
15
+ timeout,
16
+ outputDir,
17
+ cleanup,
18
+ cleanupSuccess,
19
+ cleanupError,
20
+ testSuccess,
21
+ bogusFile,
22
+ unexpectedSuccess,
23
+ checkActualFiles
24
+ } = utils;
25
+
26
+ const urls = 3; // must match url # in robots files test fixtures.
28
27
 
29
28
  /**
30
29
  * The robots test suite.
31
30
  */
32
31
  function robotsTests (options) {
33
- var port = options.port;
32
+ const { port, localRobotsFile } = options;
34
33
 
35
- return function () {
36
- it("should all succeed, no output dir pre-exists", function (done) {
37
- var options = {
38
- source: inputFile,
39
- hostname: "localhost",
40
- port: port,
41
- selector: "#dynamic-content",
42
- outputDir: outputDir,
43
- outputDirClean: true,
44
- timeout: timeout
45
- };
46
- var twice = _.after(2, cleanupSuccess.bind(null, done));
47
-
48
- rimraf(outputDir);
49
-
50
- ss.run(optHelp.decorate(options), twice)
51
- .then(testSuccess.bind(null, twice))
52
- .catch(function (e) {
53
- checkActualFiles(e.notCompleted)
54
- .then(function () {
55
- cleanup(done, e);
56
- });
57
- });
58
- });
59
-
60
- it("should all succeed, output dir does pre-exist", function (done) {
61
- var options = {
62
- source: inputFile,
63
- hostname: "localhost",
64
- port: port,
65
- selector: "#dynamic-content",
66
- outputDir: outputDir,
67
- outputDirClean: true,
68
- timeout: timeout
69
- };
70
- var twice = _.after(2, cleanupSuccess.bind(null, done));
71
-
72
- ss.run(optHelp.decorate(options), twice)
73
- .then(testSuccess.bind(null, twice))
74
- .catch(function (e) {
75
- checkActualFiles(e.notCompleted)
76
- .then(function () {
77
- cleanup(done, e);
78
- });
79
- });
80
- });
81
-
82
- it("should all fail with bad phantomjs process to spawn",
83
- function (done) {
84
- var options = {
85
- source: inputFile,
86
- hostname: "localhost",
87
- port: port,
88
- selector: "#dynamic-content",
89
- outputDir: outputDir,
90
- outputDirClean: true,
91
- phantomjs: bogusFile,
92
- timeout: 1000
93
- };
94
- var twice = _.after(2, cleanupError.bind(null, done, 0));
95
-
96
- ss.run(options, twice)
97
- .then(unexpectedSuccess.bind(null, done))
98
- .catch(twice);
99
- });
34
+ // Robots.txt fixtures
35
+ const inputFiles = [
36
+ localRobotsFile,
37
+ `http://localhost:${port}/test_robots.txt`,
38
+ `http://localhost:${port}/test_robots_sitemap.txt`
39
+ ];
100
40
 
101
- it("should all fail, bad remote robots", function (done) {
102
- var options = {
103
- input: "robots",
104
- source: "http://localhost:"+port+"/index.html",
105
- port: port,
106
- selector: "#dynamic-content",
107
- outputDir: outputDir,
108
- outputDirClean: true,
109
- timeout: 6000
110
- };
111
- var twice = _.after(2, cleanupError.bind(null, done, 0));
112
-
113
- ss.run(optHelp.decorate(options), twice)
114
- .then(unexpectedSuccess.bind(null, done))
115
- .catch(twice);
116
- });
117
-
118
- it("should all fail, non-existent selector", function (done) {
119
- var options = {
120
- source: inputFile,
121
- hostname: "localhost",
122
- port: port,
123
- selector: "#dynamic-content-notexist",
124
- outputDir: outputDir,
125
- outputDirClean: true,
126
- timeout: 6000
127
- };
128
- var twice = _.after(2, cleanupError.bind(null, done, 0));
129
-
130
- ss.run(optHelp.decorate(options), twice)
131
- .then(unexpectedSuccess.bind(null, done))
132
- .catch(twice);
133
- });
134
-
135
- it("should fail one snapshot, one non-existent selector",
136
- function (done) {
137
- var options = {
138
- source: inputFile,
139
- hostname: "localhost",
140
- port: port,
141
- selector: { "__default": "#dynamic-content", "/": "#dynamic-content-notexist" },
142
- outputDir: outputDir,
143
- outputDirClean: true,
144
- timeout: 6000
145
- };
146
- var twice = _.after(2, cleanupError.bind(null, done, urls - 1));
147
-
148
- ss.run(optHelp.decorate(options), twice)
149
- .then(unexpectedSuccess.bind(null, done))
150
- .catch(twice);
41
+ return function () {
42
+ inputFiles.forEach(inputFile => {
43
+ it(`should succeed, no output dir pre-exists, ${inputFile}`, function (done) {
44
+ const options = {
45
+ source: inputFile,
46
+ hostname: "localhost",
47
+ selector: "#dynamic-content",
48
+ outputDirClean: true,
49
+ outputDir,
50
+ timeout,
51
+ port
52
+ };
53
+ const twice = _.after(2, cleanupSuccess.bind(null, done));
54
+
55
+ rimraf(outputDir);
56
+
57
+ ss.run(optHelp.decorate(options), twice)
58
+ .then(testSuccess.bind(null, twice))
59
+ .catch(e => {
60
+ checkActualFiles(e.notCompleted)
61
+ .then(() => {
62
+ cleanup(done, e);
63
+ });
64
+ });
65
+ });
66
+
67
+ it(`should succeed, output dir does pre-exist, ${inputFile}`, function (done) {
68
+ const options = {
69
+ source: inputFile,
70
+ hostname: "localhost",
71
+ selector: "#dynamic-content",
72
+ outputDirClean: true,
73
+ outputDir,
74
+ timeout,
75
+ port
76
+ };
77
+ const twice = _.after(2, cleanupSuccess.bind(null, done));
78
+
79
+ ss.run(optHelp.decorate(options), twice)
80
+ .then(testSuccess.bind(null, twice))
81
+ .catch(e => {
82
+ checkActualFiles(e.notCompleted)
83
+ .then(() => {
84
+ cleanup(done, e);
85
+ });
86
+ });
87
+ });
88
+
89
+ it(`should fail with bad phantomjs process to spawn, ${inputFile}`,
90
+ function (done) {
91
+ const options = {
92
+ source: inputFile,
93
+ hostname: "localhost",
94
+ selector: "#dynamic-content",
95
+ outputDirClean: true,
96
+ phantomjs: bogusFile,
97
+ timeout: 1000,
98
+ outputDir,
99
+ port
100
+ };
101
+ const twice = _.after(2, cleanupError.bind(null, done, 0));
102
+
103
+ ss.run(options, twice)
104
+ .then(unexpectedSuccess.bind(null, done))
105
+ .catch(twice);
106
+ });
107
+
108
+ it(`should fail, bad remote robots, ${inputFile}`, function (done) {
109
+ const options = {
110
+ input: "robots",
111
+ source: `http://localhost:${port}/index.html`,
112
+ selector: "#dynamic-content",
113
+ outputDirClean: true,
114
+ timeout: 6000,
115
+ outputDir,
116
+ port
117
+ };
118
+ const twice = _.after(2, cleanupError.bind(null, done, 0));
119
+
120
+ ss.run(optHelp.decorate(options), twice)
121
+ .then(unexpectedSuccess.bind(null, done))
122
+ .catch(twice);
123
+ });
124
+
125
+ it(`should fail, non-existent selector, ${inputFile}`, function (done) {
126
+ const options = {
127
+ source: inputFile,
128
+ hostname: "localhost",
129
+ selector: "#dynamic-content-notexist",
130
+ outputDirClean: true,
131
+ timeout: 6000,
132
+ outputDir,
133
+ port
134
+ };
135
+ const twice = _.after(2, cleanupError.bind(null, done, 0));
136
+
137
+ ss.run(optHelp.decorate(options), twice)
138
+ .then(unexpectedSuccess.bind(null, done))
139
+ .catch(twice);
140
+ });
141
+
142
+ it(`should fail one snapshot, one non-existent selector, ${inputFile}`, function (done) {
143
+ let exceptionUrl = "/";
144
+ if (common.isUrl(inputFile)) {
145
+ // assume the origin of the inputFile is the same as the contents of the remote urls within it.
146
+ const url = new URL(inputFile);
147
+ const isSitemap = url.pathname.includes('sitemap');
148
+ if (isSitemap) {
149
+ exceptionUrl = `${url.origin}${exceptionUrl}`;
150
+ }
151
+ }
152
+ const options = {
153
+ source: inputFile,
154
+ hostname: "localhost",
155
+ selector: {
156
+ "__default": "#dynamic-content",
157
+ [exceptionUrl]: "#dynamic-content-notexist"
158
+ },
159
+ outputDirClean: true,
160
+ timeout: 6000,
161
+ outputDir,
162
+ port
163
+ };
164
+ const twice = _.after(2, cleanupError.bind(null, done, urls - 1));
165
+
166
+ ss.run(optHelp.decorate(options), twice)
167
+ .then(unexpectedSuccess.bind(null, done))
168
+ .catch(twice);
169
+ });
151
170
  });
152
171
  };
153
172
  }
154
173
 
155
174
  module.exports = {
156
175
  testSuite: robotsTests,
157
- inputFile: inputFile,
158
176
  urlCount: urls
159
177
  };
@@ -0,0 +1,13 @@
1
+ User-agent: *
2
+
3
+ Allow: /
4
+ Allow: /contact
5
+ Allow: /services/carpets
6
+
7
+ Disallow: /api/
8
+ Disallow: /vendor/
9
+ Disallow: /fonts/
10
+ Disallow: /images/
11
+
12
+ User-agent: ia_archiver
13
+ Disallow: /
@@ -0,0 +1,15 @@
1
+ User-agent: *
2
+
3
+ Allow: /
4
+ Allow: /contact
5
+ Allow: /services/carpets
6
+
7
+ Disallow: /api/
8
+ Disallow: /vendor/
9
+ Disallow: /fonts/
10
+ Disallow: /images/
11
+
12
+ User-agent: ia_archiver
13
+ Disallow: /
14
+
15
+ Sitemap: http://localhost:8038/test_robots_sitemap.xml
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
4
+ <url>
5
+ <loc>http://localhost:8038/</loc>
6
+ <lastmod>2012-08-11T12:16:09+00:00</lastmod>
7
+ <changefreq>daily</changefreq>
8
+ <priority>1.0</priority>
9
+ </url>
10
+ <url>
11
+ <loc>http://localhost:8038/contact</loc>
12
+ <lastmod>2012-11-02T02:53:40+00:00</lastmod>
13
+ <changefreq>weekly</changefreq>
14
+ <priority>0.6</priority>
15
+ </url>
16
+ <url>
17
+ <loc>http://localhost:8038/services/carpets</loc>
18
+ <lastmod>2012-10-19T10:45:23+00:00</lastmod>
19
+ <changefreq>weekly</changefreq>
20
+ <priority>0.6</priority>
21
+ </url>
22
+ </urlset>
@@ -4,48 +4,49 @@
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 optHelp = require("../../helpers/options");
10
- var ss = require("../../../lib/html-snapshots");
11
- var utils = require("./utils");
7
+ const assert = require("assert");
8
+ const path = require("path");
9
+ const optHelp = require("../../helpers/options");
10
+ const ss = require("../../../lib/html-snapshots");
11
+ const utils = require("./utils");
12
12
 
13
- // missing destructuring, will write postcard...
14
- var outputDir = utils.outputDir;
15
- var timeout = utils.timeout;
16
- var unexpectedError = utils.unexpectedError;
17
- var unexpectedSuccess = utils.unexpectedSuccess;
18
- var cleanup = utils.cleanup;
19
- var checkActualFiles = utils.checkActualFiles;
13
+ const {
14
+ outputDir,
15
+ timeout,
16
+ unexpectedError,
17
+ unexpectedSuccess,
18
+ cleanup,
19
+ checkActualFiles
20
+ } = utils;
20
21
 
21
22
  // Sitemap-index constants
22
- var sitemapIndexFile = "test_sitemap_index.xml";
23
- var inputFile = path.join(__dirname, "./", sitemapIndexFile);
24
- var urls = 3; // must match the unqiue # of urls in all the sitemap files referenced in sitemap-index.
23
+ const sitemapIndexFile = "test_sitemap_index.xml";
24
+ const inputFile = path.join(__dirname, "./", sitemapIndexFile);
25
+ const urls = 3; // must match the unqiue # of urls in all the sitemap files referenced in sitemap-index.
25
26
 
26
27
  function getClass (obj) {
27
- var string = Object.prototype.toString.call(obj);
28
- var m = /\[object ([^\]]+)/.exec(string);
28
+ const string = Object.prototype.toString.call(obj);
29
+ const m = /\[object ([^\]]+)/.exec(string);
29
30
  return m && m[1];
30
31
  }
31
32
 
32
33
  function sitemapIndexTests (options) {
33
- var port = options.port;
34
+ const port = options.port;
34
35
 
35
36
  return function () {
36
37
  it("should succeed for typical sitemap-index usage", function (done) {
37
- var options = {
38
- source: "http://localhost:"+port+"/"+sitemapIndexFile,
38
+ const options = {
39
+ source: `http://localhost:${port}/${sitemapIndexFile}`,
39
40
  input: "sitemap-index",
40
41
  selector: "#dynamic-content",
41
- outputDir: outputDir,
42
42
  outputDirClean: true,
43
- timeout: timeout
43
+ outputDir,
44
+ timeout
44
45
  };
45
46
 
46
47
  ss.run(optHelp.decorate(options))
47
48
  .then(function (completed) {
48
- var assertionError;
49
+ let assertionError;
49
50
  try {
50
51
  assert.equal(getClass(completed), "Array");
51
52
  assert.equal(completed.length, urls);
@@ -54,61 +55,61 @@ function sitemapIndexTests (options) {
54
55
  }
55
56
  cleanup(done, assertionError);
56
57
  })
57
- .catch(function (err) {
58
+ .catch(err => {
58
59
  checkActualFiles(err.notCompleted)
59
- .then(function () {
60
+ .then(() => {
60
61
  cleanup(done, err || unexpectedError);
61
62
  });
62
63
  });
63
64
  });
64
65
 
65
66
  it("should fail fast for bad sitemap url", function (done) {
66
- var sitemapIndexFile3 = path.basename(sitemapIndexFile, ".xml") + "-3" +
67
+ const sitemapIndexFile3 = path.basename(sitemapIndexFile, ".xml") + "-3" +
67
68
  path.extname(sitemapIndexFile);
68
- var options = {
69
- source: "http://localhost:" + port + "/" + sitemapIndexFile3,
70
- input: "sitemap-index",
71
- selector: "#dynamic-content",
72
- outputDir: outputDir,
73
- outputDirClean: true,
74
- timeout: timeout
75
- };
69
+ const options = {
70
+ source: `http://localhost:${port}/${sitemapIndexFile3}`,
71
+ input: "sitemap-index",
72
+ selector: "#dynamic-content",
73
+ outputDirClean: true,
74
+ outputDir,
75
+ timeout
76
+ };
76
77
 
77
- ss.run(optHelp.decorate(options))
78
- .then(unexpectedSuccess)
79
- .catch(function (err) {
80
- var assertionError;
81
- try {
82
- assert.equal(getClass(err.notCompleted), "Array");
83
- // fails fast:
84
- assert.equal(err.notCompleted.length, 0);
85
- } catch (e) {
86
- assertionError = e;
87
- }
88
- cleanup(done, assertionError);
89
- });
78
+ ss.run(optHelp.decorate(options))
79
+ .then(unexpectedSuccess)
80
+ .catch(err => {
81
+ let assertionError;
82
+ try {
83
+ assert.equal(getClass(err.notCompleted), "Array");
84
+ // fails fast:
85
+ assert.equal(err.notCompleted.length, 0);
86
+ } catch (e) {
87
+ assertionError = e;
88
+ }
89
+ cleanup(done, assertionError);
90
+ });
90
91
  });
91
92
 
92
93
  it("should eventually fail for bad page url", function (done) {
93
- var eventually = 1000;
94
- var sitemapIndexFile2 = path.basename(sitemapIndexFile, ".xml") + "-2" +
94
+ const eventually = 1000;
95
+ const sitemapIndexFile2 = path.basename(sitemapIndexFile, ".xml") + "-2" +
95
96
  path.extname(sitemapIndexFile);
96
- var options = {
97
- source: "http://localhost:" + port + "/" + sitemapIndexFile2,
97
+ const options = {
98
+ source: `http://localhost:${port}/${sitemapIndexFile2}`,
98
99
  input: "sitemap-index",
99
100
  selector: "#dynamic-content",
100
- outputDir: outputDir,
101
101
  outputDirClean: true,
102
102
  timeout: {
103
103
  "http://localhost:8040/services/bad": eventually,
104
104
  __default: timeout
105
- }
105
+ },
106
+ outputDir
106
107
  };
107
108
 
108
109
  ss.run(optHelp.decorate(options))
109
110
  .then(unexpectedSuccess)
110
- .catch(function (err) {
111
- var assertionError;
111
+ .catch(err => {
112
+ let assertionError;
112
113
  try {
113
114
  assert.equal(getClass(err.completed), "Array");
114
115
  assert.equal(err.completed.length, urls - 1);
@@ -125,6 +126,6 @@ function sitemapIndexTests (options) {
125
126
 
126
127
  module.exports = {
127
128
  testSuite: sitemapIndexTests,
128
- inputFile: inputFile,
129
- urlCount: urls
129
+ urlCount: urls,
130
+ inputFile
130
131
  };