html-snapshots 0.19.0 → 1.0.1
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/.github/workflows/verify.yml +2 -2
- package/HISTORY.md +42 -0
- package/README.md +92 -244
- package/examples/README.md +149 -0
- package/examples/custom/package-lock.json +1090 -9
- package/examples/custom/package.json +1 -1
- package/examples/debug-phantomjs/package-lock.json +1977 -292
- package/examples/debug-phantomjs/package.json +1 -1
- package/examples/debug-phantomjs/snapshot.js +1 -0
- package/examples/debug-puppeteer/README.md +18 -0
- package/examples/debug-puppeteer/package-lock.json +2804 -0
- package/examples/debug-puppeteer/package.json +12 -0
- package/examples/debug-puppeteer/snapshot.js +30 -0
- package/examples/html5rocks/package-lock.json +734 -18
- package/examples/html5rocks/package.json +1 -1
- package/examples/html5rocks/snapshot.js +0 -6
- package/examples/process-limit/package-lock.json +734 -18
- package/examples/process-limit/package.json +1 -1
- package/examples/simple-promise/package-lock.json +734 -18
- package/examples/simple-promise/package.json +1 -1
- package/examples/sitemap-index/package-lock.json +734 -18
- package/examples/sitemap-index/package.json +1 -1
- package/examples/sitemap-index/snapshot.js +0 -1
- package/examples/verbose/package-lock.json +734 -19
- package/examples/verbose/package.json +1 -1
- package/examples/verbose/snapshot.js +1 -0
- package/lib/html-snapshots.js +87 -4
- package/lib/input-generators/_base.js +7 -1
- package/lib/puppeteer/index.js +98 -0
- package/lib/puppeteer/removeScripts.js +8 -0
- package/package.json +6 -2
- package/test/mocha/browsers/puppeteer.js +106 -0
- package/test/mocha/browsers/server/index.html +9 -0
- package/test/mocha/browsers/test.js +11 -0
- package/test/mocha/html-snapshots/basics.js +60 -47
- package/test/mocha/html-snapshots/phantomjs-options.js +54 -60
- package/test/mocha/html-snapshots/process-limit.js +100 -92
- package/test/mocha/html-snapshots/puppeteer.js +47 -0
- package/test/mocha/html-snapshots/robots.js +137 -120
- package/test/mocha/html-snapshots/server/public/page-sitemap.xml +16 -0
- package/test/mocha/html-snapshots/sitemap-index.js +89 -80
- package/test/mocha/html-snapshots/sitemap.js +75 -31
- package/test/mocha/html-snapshots/snapshot-scripts.js +124 -120
- package/test/mocha/html-snapshots/test.js +11 -2
- package/test/mocha/html-snapshots/use-jquery.js +65 -64
- package/test/mocha/html-snapshots/utils.js +29 -29
- package/examples/utils/index.js +0 -25
|
@@ -4,39 +4,51 @@
|
|
|
4
4
|
* Copyright (c) 2013 - 2022, Alex Grant, LocalNerve, contributors
|
|
5
5
|
*/
|
|
6
6
|
/* global it */
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const rimraf = require("rimraf").sync;
|
|
10
|
+
const utils = require("./utils");
|
|
11
|
+
const optHelp = require("../../helpers/options");
|
|
12
|
+
const resHelp = require("../../helpers/result");
|
|
13
|
+
const ss = require("../../../lib/html-snapshots");
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
timeout,
|
|
17
|
+
outputDir,
|
|
18
|
+
cleanup,
|
|
19
|
+
unexpectedError,
|
|
20
|
+
unexpectedSuccess,
|
|
21
|
+
checkActualFiles
|
|
22
|
+
} = utils;
|
|
23
|
+
|
|
24
|
+
const outputBase = path.resolve(outputDir, "..");
|
|
25
|
+
const cookiesFile = path.join(outputBase, "cookies.txt");
|
|
25
26
|
|
|
26
27
|
function phantomjsOptionsTests (options) {
|
|
27
|
-
|
|
28
|
+
const {
|
|
29
|
+
port
|
|
30
|
+
} = options;
|
|
31
|
+
|
|
32
|
+
function createOptions (newOptions) {
|
|
33
|
+
const defaultOptions = {
|
|
34
|
+
input: "array",
|
|
35
|
+
source: [ `http://localhost:${port}/pjsopts` ],
|
|
36
|
+
outputDir,
|
|
37
|
+
outputDirClean: false,
|
|
38
|
+
selector: ".content-complete",
|
|
39
|
+
timeout,
|
|
40
|
+
browser: "phantomjs",
|
|
41
|
+
phantomjsOptions: `--cookies-file=${cookiesFile}`
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
...defaultOptions,
|
|
45
|
+
...newOptions
|
|
46
|
+
};
|
|
47
|
+
}
|
|
28
48
|
|
|
29
49
|
return function () {
|
|
30
50
|
it ("should work on first vanilla full invocation, no checks", function (done) {
|
|
31
|
-
|
|
32
|
-
input: "array",
|
|
33
|
-
source: [ "http://localhost:"+port+"/pjsopts" ],
|
|
34
|
-
outputDir: outputDir,
|
|
35
|
-
outputDirClean: false,
|
|
36
|
-
selector: ".content-complete",
|
|
37
|
-
timeout: timeout,
|
|
38
|
-
phantomjsOptions: "--cookies-file="+cookiesFile
|
|
39
|
-
};
|
|
51
|
+
const options = createOptions({});
|
|
40
52
|
|
|
41
53
|
rimraf(outputBase);
|
|
42
54
|
|
|
@@ -52,25 +64,17 @@ function phantomjsOptionsTests (options) {
|
|
|
52
64
|
});
|
|
53
65
|
|
|
54
66
|
it("should work with one string option", function (done) {
|
|
55
|
-
|
|
56
|
-
input: "array",
|
|
57
|
-
source: [ "http://localhost:"+port+"/pjsopts" ],
|
|
58
|
-
outputDir: outputDir,
|
|
59
|
-
outputDirClean: false,
|
|
60
|
-
selector: ".content-complete",
|
|
61
|
-
timeout: timeout,
|
|
62
|
-
phantomjsOptions: "--cookies-file="+cookiesFile
|
|
63
|
-
};
|
|
67
|
+
const options = createOptions({});
|
|
64
68
|
|
|
65
69
|
rimraf(outputBase);
|
|
66
70
|
|
|
67
|
-
ss.run(optHelp.decorate(options),
|
|
71
|
+
ss.run(optHelp.decorate(options), (err, completed) => {
|
|
68
72
|
if (err) {
|
|
69
|
-
console.log(
|
|
73
|
+
console.log(`@@@ error = ${err}, completed=${completed.join(',')}`);
|
|
70
74
|
}
|
|
71
75
|
})
|
|
72
76
|
.then(() => {
|
|
73
|
-
|
|
77
|
+
let assertionError;
|
|
74
78
|
try {
|
|
75
79
|
fs.accessSync(cookiesFile);
|
|
76
80
|
} catch (e) {
|
|
@@ -87,28 +91,23 @@ function phantomjsOptionsTests (options) {
|
|
|
87
91
|
});
|
|
88
92
|
|
|
89
93
|
it("should work with multiple options, test one", function (done) {
|
|
90
|
-
|
|
91
|
-
input: "array",
|
|
92
|
-
source: [ "http://localhost:"+port+"/pjsopts" ],
|
|
93
|
-
outputDir: outputDir,
|
|
94
|
-
outputDirClean: false,
|
|
94
|
+
const options = createOptions({
|
|
95
95
|
selector: "#inline-image",
|
|
96
|
-
timeout: timeout,
|
|
97
96
|
phantomjsOptions: [
|
|
98
|
-
|
|
97
|
+
`--cookies-file=${cookiesFile}`,
|
|
99
98
|
"--load-images=true"
|
|
100
99
|
]
|
|
101
|
-
};
|
|
100
|
+
});
|
|
102
101
|
|
|
103
102
|
rimraf(outputBase);
|
|
104
103
|
|
|
105
|
-
ss.run(optHelp.decorate(options),
|
|
104
|
+
ss.run(optHelp.decorate(options), (err, completed) => {
|
|
106
105
|
if (err) {
|
|
107
|
-
console.log(
|
|
106
|
+
console.log(`@@@ error = ${err}, completed=${completed.join(',')}`);
|
|
108
107
|
}
|
|
109
108
|
})
|
|
110
109
|
.then(() => {
|
|
111
|
-
|
|
110
|
+
let assertionError;
|
|
112
111
|
try {
|
|
113
112
|
fs.accessSync(cookiesFile);
|
|
114
113
|
} catch (e) {
|
|
@@ -125,25 +124,21 @@ function phantomjsOptionsTests (options) {
|
|
|
125
124
|
});
|
|
126
125
|
|
|
127
126
|
it("should work with multiple options, test two", function (done) {
|
|
128
|
-
|
|
129
|
-
input: "array",
|
|
130
|
-
source: [ "http://localhost:"+port+"/pjsopts" ],
|
|
131
|
-
outputDir: outputDir,
|
|
132
|
-
outputDirClean: false,
|
|
127
|
+
const options = createOptions({
|
|
133
128
|
selector: "#inline-image",
|
|
134
129
|
timeout: 5000, // this should fail, so don't wait too long.
|
|
135
130
|
phantomjsOptions: [
|
|
136
|
-
|
|
131
|
+
`--cookies-file=${cookiesFile}`,
|
|
137
132
|
"--load-images=false"
|
|
138
133
|
]
|
|
139
|
-
};
|
|
134
|
+
});
|
|
140
135
|
|
|
141
136
|
rimraf(outputBase);
|
|
142
137
|
|
|
143
138
|
ss.run(optHelp.decorate(options))
|
|
144
139
|
.then(unexpectedSuccess.bind(null, done))
|
|
145
140
|
.catch(err => {
|
|
146
|
-
|
|
141
|
+
let assertionError;
|
|
147
142
|
try {
|
|
148
143
|
resHelp.mustBeError(err);
|
|
149
144
|
} catch (e) {
|
|
@@ -152,7 +147,6 @@ function phantomjsOptionsTests (options) {
|
|
|
152
147
|
cleanup(done, assertionError);
|
|
153
148
|
});
|
|
154
149
|
});
|
|
155
|
-
|
|
156
150
|
// most of these tests use no options, so not testing that again here
|
|
157
151
|
};
|
|
158
152
|
}
|
|
@@ -25,7 +25,11 @@ const {
|
|
|
25
25
|
const urls = robotsTests.urlCount;
|
|
26
26
|
|
|
27
27
|
function processLimitTests (options) {
|
|
28
|
-
const {
|
|
28
|
+
const {
|
|
29
|
+
port,
|
|
30
|
+
localRobotsFile: inputFile,
|
|
31
|
+
browsers
|
|
32
|
+
} = options;
|
|
29
33
|
const pollInterval = 50;
|
|
30
34
|
let phantomCount = 0;
|
|
31
35
|
let timer;
|
|
@@ -47,98 +51,102 @@ function processLimitTests (options) {
|
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
return function () {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
54
|
+
browsers.forEach(browser => {
|
|
55
|
+
it(`should limit as expected - ${browser}`, function (done) {
|
|
56
|
+
const processLimit = urls - 1;
|
|
57
|
+
const complete = completeTest.bind(null, done, processLimit);
|
|
58
|
+
|
|
59
|
+
if (process.platform === "win32") {
|
|
60
|
+
assert.ok(true, "Skipping posix compliant tests for processLimit");
|
|
61
|
+
done();
|
|
62
|
+
} else {
|
|
63
|
+
rimraf(outputDir);
|
|
64
|
+
|
|
65
|
+
killSpawnedProcesses(function (err) {
|
|
66
|
+
const options = {
|
|
67
|
+
source: inputFile,
|
|
68
|
+
hostname: "localhost",
|
|
69
|
+
selector: "#dynamic-content",
|
|
70
|
+
outputDirClean: true,
|
|
71
|
+
outputDir,
|
|
72
|
+
timeout,
|
|
73
|
+
processLimit,
|
|
74
|
+
port,
|
|
75
|
+
browser
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (err) {
|
|
79
|
+
return done(err);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
ss.run(optHelp.decorate(options))
|
|
83
|
+
.then(() => {
|
|
84
|
+
complete();
|
|
85
|
+
})
|
|
86
|
+
.catch(e => {
|
|
87
|
+
complete(e || unexpectedError, e.notCompleted);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
timer = setInterval(() => {
|
|
91
|
+
countSpawnedProcesses(function (count) {
|
|
92
|
+
// console.log("@@@ DEBUG @@@ phantom count: "+count);
|
|
93
|
+
if (count > processLimit) {
|
|
94
|
+
phantomCount = count;
|
|
95
|
+
clearInterval(timer);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}, pollInterval);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
96
102
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
103
|
+
it(`should limit to just one process - ${browser}`, function (done) {
|
|
104
|
+
const processLimit = 1;
|
|
105
|
+
const complete = completeTest.bind(null, done, processLimit);
|
|
106
|
+
|
|
107
|
+
if (process.platform === "win32") {
|
|
108
|
+
assert.ok(true, "Skipping posix compliant tests for processLimit");
|
|
109
|
+
done();
|
|
110
|
+
} else {
|
|
111
|
+
rimraf(outputDir);
|
|
112
|
+
|
|
113
|
+
killSpawnedProcesses(function (err) {
|
|
114
|
+
const options = {
|
|
115
|
+
source: inputFile,
|
|
116
|
+
hostname: "localhost",
|
|
117
|
+
selector: "#dynamic-content",
|
|
118
|
+
outputDirClean: true,
|
|
119
|
+
outputDir,
|
|
120
|
+
timeout,
|
|
121
|
+
processLimit,
|
|
122
|
+
port,
|
|
123
|
+
browser
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
if (err) {
|
|
127
|
+
return done(err);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
ss.run(optHelp.decorate(options))
|
|
131
|
+
.then(() => {
|
|
132
|
+
complete();
|
|
133
|
+
})
|
|
134
|
+
.catch(e => {
|
|
135
|
+
complete(e || unexpectedError, e.notCompleted);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
timer = setInterval(function () {
|
|
139
|
+
countSpawnedProcesses(function (count) {
|
|
140
|
+
// console.log("@@@ DEBUG @@@ phantom count: "+count);
|
|
141
|
+
if (count > processLimit) {
|
|
142
|
+
phantomCount = count;
|
|
143
|
+
clearInterval(timer);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}, pollInterval);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
});
|
|
142
150
|
});
|
|
143
151
|
};
|
|
144
152
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests unique to the puppeteer browser.
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2013 - 2022, Alex Grant, LocalNerve, contributors
|
|
5
|
+
*/
|
|
6
|
+
/* global it */
|
|
7
|
+
const optHelp = require("../../helpers/options");
|
|
8
|
+
const ss = require("../../../lib/html-snapshots");
|
|
9
|
+
const {
|
|
10
|
+
outputDir,
|
|
11
|
+
cleanupSuccess,
|
|
12
|
+
testSuccess
|
|
13
|
+
} = require("./utils");
|
|
14
|
+
|
|
15
|
+
function puppeteerTests (options) {
|
|
16
|
+
const {
|
|
17
|
+
port
|
|
18
|
+
} = options;
|
|
19
|
+
|
|
20
|
+
return function () {
|
|
21
|
+
|
|
22
|
+
it("should launch debugger when requested", function (done) {
|
|
23
|
+
const options = {
|
|
24
|
+
source: [
|
|
25
|
+
`http://localhost:${port}/contact`
|
|
26
|
+
],
|
|
27
|
+
outputDir,
|
|
28
|
+
timeout: 5000,
|
|
29
|
+
debug: {
|
|
30
|
+
flag: true,
|
|
31
|
+
slowMo: 50
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const success = testSuccess.bind(null, cleanupSuccess.bind(null, done));
|
|
36
|
+
|
|
37
|
+
// TODO: check for headless: false chrome invocation
|
|
38
|
+
ss.run(optHelp.decorate(options))
|
|
39
|
+
.then(success)
|
|
40
|
+
.catch(done);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
testSuite: puppeteerTests
|
|
47
|
+
};
|