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,30 +4,30 @@
4
4
  * Copyright (c) 2013 - 2022, Alex Grant, LocalNerve, contributors
5
5
  */
6
6
  /* global beforeEach, describe, it */
7
- // var assert = require("assert");
8
- var path = require("path");
9
- var fs = require("fs");
10
- var _ = require("lodash");
11
- var rimraf = require("rimraf").sync;
12
- var utils = require("./utils");
13
- var optHelp = require("../../helpers/options");
14
- var ss = require("../../../lib/html-snapshots");
15
- var inputFile = require("./robots").inputFile;
16
-
17
- // missing destructuring, will write postcard...
18
- var timeout = utils.timeout;
19
- var outputDir = utils.outputDir;
20
- var cleanup = utils.cleanup;
21
- var bogusFile = utils.bogusFile;
22
- var cleanupError = utils.cleanupError;
23
- var unexpectedSuccess = utils.unexpectedSuccess;
24
- var checkActualFiles = utils.checkActualFiles;
7
+
8
+ const path = require("path");
9
+ const fs = require("fs");
10
+ const _ = require("lodash");
11
+ const rimraf = require("rimraf").sync;
12
+ const utils = require("./utils");
13
+ const optHelp = require("../../helpers/options");
14
+ const ss = require("../../../lib/html-snapshots");
15
+
16
+ const {
17
+ timeout,
18
+ outputDir,
19
+ cleanup,
20
+ bogusFile,
21
+ cleanupError,
22
+ unexpectedSuccess,
23
+ checkActualFiles
24
+ } = utils;
25
25
 
26
26
  function snapshotScriptTests (options) {
27
- var port = options.port;
27
+ const { localRobotsFile: inputFile, port } = options;
28
28
 
29
29
  return function () {
30
- var snapshotScriptTests = [
30
+ const snapshotScriptTests = [
31
31
  {
32
32
  name: "removeScripts",
33
33
  option: {
@@ -35,7 +35,7 @@ function snapshotScriptTests (options) {
35
35
  },
36
36
  prove: function (completed, done) {
37
37
  // console.log("@@@ removeScripts prove @@@");
38
- var content, err;
38
+ let content, err;
39
39
  for (var i = 0; i < completed.length; i++) {
40
40
  content = fs.readFileSync(completed[i], { encoding: "utf8" });
41
41
  if (/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi.test(content)) {
@@ -54,8 +54,8 @@ function snapshotScriptTests (options) {
54
54
  },
55
55
  prove: function (completed, done) {
56
56
  // console.log("@@@ customFilter prove @@@");
57
- var content, err;
58
- for (var i = 0; i < completed.length; i++) {
57
+ let content, err;
58
+ for (let i = 0; i < completed.length; i++) {
59
59
  // console.log("@@@ readFile "+completed[i]);
60
60
  content = fs.readFileSync(completed[i], { encoding: "utf8" });
61
61
  // this is dependent on myFilter.js adding someattrZZQy anywhere
@@ -70,7 +70,8 @@ function snapshotScriptTests (options) {
70
70
  ];
71
71
 
72
72
  describe("should succeed for scripts", function () {
73
- var testNumber = 0, snapshotScriptTest, scriptNames = [
73
+ let testNumber = 0, snapshotScriptTest;
74
+ const scriptNames = [
74
75
  snapshotScriptTests[testNumber].name,
75
76
  snapshotScriptTests[testNumber + 1].name
76
77
  //, testNumber + 2, etc
@@ -81,52 +82,52 @@ function snapshotScriptTests (options) {
81
82
  });
82
83
 
83
84
  function snapshotScriptTestDefinition (done) {
84
- var options = {
85
+ const options = {
85
86
  source: inputFile,
86
87
  hostname: "localhost",
87
- port: port,
88
88
  selector: "#dynamic-content",
89
- outputDir: outputDir,
90
89
  outputDirClean: true,
91
90
  timeout: timeout,
92
- snapshotScript: snapshotScriptTest.option
91
+ snapshotScript: snapshotScriptTest.option,
92
+ outputDir,
93
+ port
93
94
  };
94
95
 
95
96
  rimraf(outputDir);
96
97
 
97
98
  ss.run(optHelp.decorate(options))
98
- .then(function (completed) {
99
- snapshotScriptTest.prove(completed, function (e) {
99
+ .then(completed => {
100
+ snapshotScriptTest.prove(completed, e => {
100
101
  cleanup(done, e);
101
102
  });
102
103
  })
103
- .catch(function (err) {
104
+ .catch(err => {
104
105
  checkActualFiles(err.notCompleted)
105
- .then(function () {
106
+ .then(() => {
106
107
  cleanup(done, err);
107
108
  });
108
109
  });
109
110
  }
110
111
 
111
- scriptNames.forEach(function (scriptName) {
112
- it("snapshot script "+scriptName, function (done) {
112
+ scriptNames.forEach(scriptName => {
113
+ it(`snapshot script ${scriptName}`, function (done) {
113
114
  setTimeout(snapshotScriptTestDefinition, 3000, done);
114
115
  });
115
116
  });
116
117
  });
117
118
 
118
119
  it("should fail if a bogus script string is supplied", function (done) {
119
- var options = {
120
+ const options = {
120
121
  source: inputFile,
121
122
  hostname: "localhost",
122
- port: port,
123
123
  selector: "#dynamic-content",
124
- outputDir: outputDir,
125
124
  outputDirClean: true,
126
125
  snapshotScript: bogusFile,
127
- timeout: 2000
126
+ timeout: 2000,
127
+ outputDir,
128
+ port
128
129
  };
129
- var twice = _.after(2, cleanupError.bind(null, done, 0));
130
+ const twice = _.after(2, cleanupError.bind(null, done, 0));
130
131
 
131
132
  ss.run(optHelp.decorate(options), twice)
132
133
  .then(unexpectedSuccess.bind(null, done))
@@ -134,19 +135,19 @@ function snapshotScriptTests (options) {
134
135
  });
135
136
 
136
137
  it("should fail if a bogus script object is supplied", function(done) {
137
- var options = {
138
+ const options = {
138
139
  source: inputFile,
139
140
  hostname: "localhost",
140
- port: port,
141
141
  selector: "#dynamic-content",
142
- outputDir: outputDir,
143
142
  outputDirClean: true,
144
143
  snapshotScript: {
145
144
  script: bogusFile
146
145
  },
147
- timeout: 2000
146
+ timeout: 2000,
147
+ outputDir,
148
+ port
148
149
  };
149
- var twice = _.after(2, cleanupError.bind(null, done, 0));
150
+ const twice = _.after(2, cleanupError.bind(null, done, 0));
150
151
 
151
152
  ss.run(optHelp.decorate(options), twice)
152
153
  .then(unexpectedSuccess.bind(null, done))
@@ -154,19 +155,19 @@ function snapshotScriptTests (options) {
154
155
  });
155
156
 
156
157
  it("should fail if a customFilter is defined but no module", function(done) {
157
- var options = {
158
+ const options = {
158
159
  source: inputFile,
159
160
  hostname: "localhost",
160
- port: port,
161
161
  selector: "#dynamic-content",
162
- outputDir: outputDir,
163
162
  outputDirClean: true,
164
163
  snapshotScript: {
165
164
  script: "customFilter"
166
165
  },
167
- timeout: 2000
166
+ timeout: 2000,
167
+ outputDir,
168
+ port
168
169
  };
169
- var twice = _.after(2, cleanupError.bind(null, done, 0));
170
+ const twice = _.after(2, cleanupError.bind(null, done, 0));
170
171
 
171
172
  ss.run(optHelp.decorate(options), twice)
172
173
  .then(unexpectedSuccess.bind(null, done))
@@ -174,20 +175,20 @@ function snapshotScriptTests (options) {
174
175
  });
175
176
 
176
177
  it("should fail if a customFilter is defined and bogus module", function(done) {
177
- var options = {
178
+ const options = {
178
179
  source: inputFile,
179
180
  hostname: "localhost",
180
- port: port,
181
181
  selector: "#dynamic-content",
182
- outputDir: outputDir,
183
182
  outputDirClean: true,
184
183
  snapshotScript: {
185
184
  script: "customFilter",
186
185
  module: bogusFile
187
186
  },
188
- timeout: 2000
187
+ timeout: 2000,
188
+ outputDir,
189
+ port
189
190
  };
190
- var twice = _.after(2, cleanupError.bind(null, done, 0));
191
+ const twice = _.after(2, cleanupError.bind(null, done, 0));
191
192
 
192
193
  ss.run(optHelp.decorate(options), twice)
193
194
  .then(unexpectedSuccess.bind(null, done))
@@ -4,19 +4,21 @@
4
4
  * Copyright (c) 2013 - 2022, Alex Grant, LocalNerve, contributors
5
5
  */
6
6
  /* global describe, before, after */
7
- var path = require("path");
8
- var enableDestroy = require("server-destroy");
7
+ const path = require("path");
8
+ const enableDestroy = require("server-destroy");
9
9
 
10
- var timeout = require("./utils").timeout;
10
+ const timeout = require("./utils").timeout;
11
11
 
12
- var basics = require("./basics");
13
- var robots = require("./robots");
14
- var sitemap = require("./sitemap");
15
- var sitemapIndex = require("./sitemap-index");
16
- var processLimit = require("./process-limit");
17
- var useJQuery = require("./use-jquery");
18
- var snapshotScripts = require("./snapshot-scripts");
19
- var phantomJSOptions = require("./phantomjs-options");
12
+ const basics = require("./basics");
13
+ const robots = require("./robots");
14
+ const sitemap = require("./sitemap");
15
+ const sitemapIndex = require("./sitemap-index");
16
+ const processLimit = require("./process-limit");
17
+ const useJQuery = require("./use-jquery");
18
+ const snapshotScripts = require("./snapshot-scripts");
19
+ const phantomJSOptions = require("./phantomjs-options");
20
+
21
+ const localRobotsFile = path.join(__dirname, "./test_robots.txt");
20
22
 
21
23
  /**
22
24
  * Create a test context with a new server on a port.
@@ -28,10 +30,10 @@ var phantomJSOptions = require("./phantomjs-options");
28
30
  * @returns {Function} A test context with server management.
29
31
  */
30
32
  function serverContext (testSuiteFactory, port) {
31
- var server = require("../../server");
33
+ const server = require("../../server");
32
34
 
33
35
  return function () {
34
- var httpServer;
36
+ let httpServer;
35
37
 
36
38
  before(function (done) {
37
39
  server.start(path.join(__dirname, "./server"), port,
@@ -52,9 +54,7 @@ function serverContext (testSuiteFactory, port) {
52
54
  });
53
55
  });
54
56
 
55
- describe("tests", testSuiteFactory({
56
- port: port
57
- }));
57
+ describe("tests", testSuiteFactory({ port, localRobotsFile }));
58
58
  };
59
59
  }
60
60
 
@@ -9,7 +9,5 @@ Disallow: /vendor/
9
9
  Disallow: /fonts/
10
10
  Disallow: /images/
11
11
 
12
- Sitemap: http://test.local/sitemap.xml
13
-
14
12
  User-agent: ia_archiver
15
13
  Disallow: /
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * Copyright (c) 2013 - 2022, Alex Grant, LocalNerve, contributors
5
5
  */
6
- /* global Promise */
7
6
  var path = require("path");
8
7
  var fs = require("fs");
9
8
  var _ = require("lodash");
@@ -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
  });