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.
- package/.eslintrc.json +4 -5
- package/README.md +73 -68
- package/examples/custom/myFilter.js +2 -2
- package/examples/custom/package-lock.json +1012 -77
- package/examples/custom/package.json +1 -1
- package/examples/custom/snapshot.js +8 -10
- package/examples/debug-phantomjs/package-lock.json +76 -76
- package/examples/debug-phantomjs/package.json +1 -1
- package/examples/debug-phantomjs/snapshot.js +12 -14
- package/examples/html5rocks/package-lock.json +1379 -78
- package/examples/html5rocks/package.json +1 -1
- package/examples/html5rocks/snapshot.js +15 -18
- package/examples/process-limit/package-lock.json +1379 -78
- package/examples/process-limit/package.json +1 -1
- package/examples/process-limit/snapshot.js +8 -10
- package/examples/simple-promise/package-lock.json +1379 -78
- package/examples/simple-promise/package.json +1 -1
- package/examples/simple-promise/snapshot.js +6 -8
- package/examples/sitemap-index/package-lock.json +1378 -77
- package/examples/sitemap-index/package.json +1 -1
- package/examples/sitemap-index/snapshot.js +6 -6
- package/examples/utils/index.js +2 -4
- package/examples/verbose/package-lock.json +1380 -78
- package/examples/verbose/package.json +1 -1
- package/examples/verbose/snapshot.js +11 -14
- package/lib/async/index.js +0 -1
- package/lib/common/index.js +1 -1
- package/lib/common/sitemap/index.js +16 -0
- package/lib/common/sitemap/sitemap-collection.js +94 -0
- package/lib/common/sitemap/sitemap-index.js +68 -0
- package/lib/common/{sitemap.js → sitemap/sitemap.js} +68 -57
- package/lib/html-snapshots.js +0 -1
- package/lib/input-generators/array.js +0 -1
- package/lib/input-generators/robots.js +98 -58
- package/lib/input-generators/sitemap-index.js +3 -124
- package/lib/input-generators/sitemap.js +3 -7
- package/lib/input-generators/textfile.js +2 -6
- package/package.json +6 -6
- package/test/helpers/options.js +4 -2
- package/test/mocha/html-snapshots/process-limit.js +46 -48
- package/test/mocha/html-snapshots/robots.js +156 -138
- package/test/mocha/html-snapshots/server/test_robots.txt +13 -0
- package/test/mocha/html-snapshots/server/test_robots_sitemap.txt +15 -0
- package/test/mocha/html-snapshots/server/test_robots_sitemap.xml +22 -0
- package/test/mocha/html-snapshots/sitemap-index.js +58 -57
- package/test/mocha/html-snapshots/snapshot-scripts.js +55 -54
- package/test/mocha/html-snapshots/test.js +16 -16
- package/test/mocha/html-snapshots/test_robots.txt +0 -2
- package/test/mocha/html-snapshots/utils.js +0 -1
- package/test/mocha/input-generators/server/test_robots.txt +0 -2
- package/test/mocha/input-generators/server/test_robots_bad.txt +0 -2
- package/test/mocha/input-generators/server/test_robots_sitemap.txt +17 -0
- package/test/mocha/input-generators/server/test_robots_sitemap_bad.txt +17 -0
- package/test/mocha/input-generators/server/test_robots_sitemap_multi.txt +18 -0
- package/test/mocha/input-generators/server/test_sitemap_index_empty.xml +3 -0
- package/test/mocha/input-generators/server/test_sitemap_index_malformed.xml +2 -0
- package/test/mocha/input-generators/sitemap-index.js +65 -9
- package/test/mocha/input-generators/test.js +276 -280
- package/test/mocha/input-generators/test_robots.txt +0 -2
- package/test/mocha/input-generators/test_robots_bad.txt +0 -2
- package/test/mocha/input-generators/test_robots_sitemap.txt +17 -0
- package/test/mocha/input-generators/test_robots_sitemap_bad.txt +17 -0
- package/test/mocha/input-generators/test_robots_sitemap_multi.txt +18 -0
- package/lib/common/node.js +0 -26
- 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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
27
|
+
const { localRobotsFile: inputFile, port } = options;
|
|
28
28
|
|
|
29
29
|
return function () {
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
for (
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
99
|
-
snapshotScriptTest.prove(completed,
|
|
99
|
+
.then(completed => {
|
|
100
|
+
snapshotScriptTest.prove(completed, e => {
|
|
100
101
|
cleanup(done, e);
|
|
101
102
|
});
|
|
102
103
|
})
|
|
103
|
-
.catch(
|
|
104
|
+
.catch(err => {
|
|
104
105
|
checkActualFiles(err.notCompleted)
|
|
105
|
-
.then(
|
|
106
|
+
.then(() => {
|
|
106
107
|
cleanup(done, err);
|
|
107
108
|
});
|
|
108
109
|
});
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
scriptNames.forEach(
|
|
112
|
-
it(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
8
|
-
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const enableDestroy = require("server-destroy");
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const timeout = require("./utils").timeout;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
33
|
+
const server = require("../../server");
|
|
32
34
|
|
|
33
35
|
return function () {
|
|
34
|
-
|
|
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
|
|
|
@@ -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: /
|
|
@@ -4,14 +4,13 @@
|
|
|
4
4
|
* Copyright (c) 2013 - 2022, Alex Grant, LocalNerve, contributors
|
|
5
5
|
*/
|
|
6
6
|
/* global describe, it, before */
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
});
|