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
|
@@ -24,58 +24,75 @@ const {
|
|
|
24
24
|
} = utils;
|
|
25
25
|
|
|
26
26
|
function snapshotScriptTests (options) {
|
|
27
|
-
const {
|
|
27
|
+
const {
|
|
28
|
+
localRobotsFile: inputFile,
|
|
29
|
+
port,
|
|
30
|
+
browsers
|
|
31
|
+
} = options;
|
|
28
32
|
|
|
29
33
|
return function () {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
34
|
+
const removeScriptsConfig = {
|
|
35
|
+
name: "removeScripts",
|
|
36
|
+
option: {
|
|
37
|
+
script: "removeScripts"
|
|
38
|
+
},
|
|
39
|
+
browser: "phantomjs",
|
|
40
|
+
prove: (completed, done) => {
|
|
41
|
+
// console.log("@@@ removeScripts prove @@@");
|
|
42
|
+
let content, err;
|
|
43
|
+
for (var i = 0; i < completed.length; i++) {
|
|
44
|
+
content = fs.readFileSync(completed[i], { encoding: "utf8" });
|
|
45
|
+
if (/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi.test(content)) {
|
|
46
|
+
err = new Error("removeScripts failed. Script tag found in "+completed[i]);
|
|
47
|
+
break;
|
|
45
48
|
}
|
|
46
|
-
done(err);
|
|
47
49
|
}
|
|
50
|
+
done(err);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const customFilterConfig = {
|
|
54
|
+
name: "customFilter",
|
|
55
|
+
option: {
|
|
56
|
+
script: "customFilter",
|
|
57
|
+
module: path.join(__dirname, "myFilter.js")
|
|
48
58
|
},
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
content = fs.readFileSync(completed[i], { encoding: "utf8" });
|
|
61
|
-
// this is dependent on myFilter.js adding someattrZZQy anywhere
|
|
62
|
-
if (content.indexOf("someattrZZQy") < 0) {
|
|
63
|
-
err = new Error("customFilter snapshotScript failed. Special sequence not found in "+completed[i]);
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
59
|
+
browser: "phantomjs",
|
|
60
|
+
prove: (completed, done) => {
|
|
61
|
+
// console.log("@@@ customFilter prove @@@");
|
|
62
|
+
let content, err;
|
|
63
|
+
for (let i = 0; i < completed.length; i++) {
|
|
64
|
+
// console.log("@@@ readFile "+completed[i]);
|
|
65
|
+
content = fs.readFileSync(completed[i], { encoding: "utf8" });
|
|
66
|
+
// this is dependent on myFilter.js adding someattrZZQy anywhere
|
|
67
|
+
if (content.indexOf("someattrZZQy") < 0) {
|
|
68
|
+
err = new Error("customFilter snapshotScript failed. Special sequence not found in "+completed[i]);
|
|
69
|
+
break;
|
|
66
70
|
}
|
|
67
|
-
done(err);
|
|
68
71
|
}
|
|
72
|
+
done(err);
|
|
69
73
|
}
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
};
|
|
75
|
+
const snapshotScriptTests = [];
|
|
76
|
+
browsers.forEach(browser => {
|
|
77
|
+
snapshotScriptTests.push({
|
|
78
|
+
...removeScriptsConfig,
|
|
79
|
+
...{
|
|
80
|
+
name: `${removeScriptsConfig.name}-${browser}`,
|
|
81
|
+
browser
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
snapshotScriptTests.push({
|
|
85
|
+
...customFilterConfig,
|
|
86
|
+
...{
|
|
87
|
+
name: `${customFilterConfig.name}-${browser}`,
|
|
88
|
+
browser
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
72
93
|
describe("should succeed for scripts", function () {
|
|
73
94
|
let testNumber = 0, snapshotScriptTest;
|
|
74
|
-
const scriptNames =
|
|
75
|
-
snapshotScriptTests[testNumber].name,
|
|
76
|
-
snapshotScriptTests[testNumber + 1].name
|
|
77
|
-
//, testNumber + 2, etc
|
|
78
|
-
];
|
|
95
|
+
const scriptNames = snapshotScriptTests.map(test => test.name);
|
|
79
96
|
|
|
80
97
|
beforeEach(function () {
|
|
81
98
|
snapshotScriptTest = snapshotScriptTests[testNumber++];
|
|
@@ -89,6 +106,7 @@ function snapshotScriptTests (options) {
|
|
|
89
106
|
outputDirClean: true,
|
|
90
107
|
timeout: timeout,
|
|
91
108
|
snapshotScript: snapshotScriptTest.option,
|
|
109
|
+
browser: snapshotScriptTest.browser,
|
|
92
110
|
outputDir,
|
|
93
111
|
port
|
|
94
112
|
};
|
|
@@ -109,90 +127,76 @@ function snapshotScriptTests (options) {
|
|
|
109
127
|
});
|
|
110
128
|
}
|
|
111
129
|
|
|
112
|
-
scriptNames.forEach(scriptName => {
|
|
113
|
-
it(`snapshot script ${scriptName}`, function (done) {
|
|
130
|
+
scriptNames.forEach((scriptName, i) => {
|
|
131
|
+
it(`snapshot script ${scriptName}, ${snapshotScriptTests[i].browser}`, function (done) {
|
|
114
132
|
setTimeout(snapshotScriptTestDefinition, 3000, done);
|
|
115
133
|
});
|
|
116
134
|
});
|
|
117
135
|
});
|
|
118
136
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
it("should fail if a bogus script object is supplied", function(done) {
|
|
138
|
-
const options = {
|
|
139
|
-
source: inputFile,
|
|
140
|
-
hostname: "localhost",
|
|
141
|
-
selector: "#dynamic-content",
|
|
142
|
-
outputDirClean: true,
|
|
143
|
-
snapshotScript: {
|
|
144
|
-
script: bogusFile
|
|
145
|
-
},
|
|
146
|
-
timeout: 2000,
|
|
147
|
-
outputDir,
|
|
148
|
-
port
|
|
149
|
-
};
|
|
150
|
-
const twice = _.after(2, cleanupError.bind(null, done, 0));
|
|
151
|
-
|
|
152
|
-
ss.run(optHelp.decorate(options), twice)
|
|
153
|
-
.then(unexpectedSuccess.bind(null, done))
|
|
154
|
-
.catch(twice);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it("should fail if a customFilter is defined but no module", function(done) {
|
|
158
|
-
const options = {
|
|
159
|
-
source: inputFile,
|
|
160
|
-
hostname: "localhost",
|
|
161
|
-
selector: "#dynamic-content",
|
|
162
|
-
outputDirClean: true,
|
|
163
|
-
snapshotScript: {
|
|
164
|
-
script: "customFilter"
|
|
165
|
-
},
|
|
166
|
-
timeout: 2000,
|
|
167
|
-
outputDir,
|
|
168
|
-
port
|
|
169
|
-
};
|
|
170
|
-
const twice = _.after(2, cleanupError.bind(null, done, 0));
|
|
171
|
-
|
|
172
|
-
ss.run(optHelp.decorate(options), twice)
|
|
173
|
-
.then(unexpectedSuccess.bind(null, done))
|
|
174
|
-
.catch(twice);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("should fail if a customFilter is defined and bogus module", function(done) {
|
|
178
|
-
const options = {
|
|
179
|
-
source: inputFile,
|
|
180
|
-
hostname: "localhost",
|
|
181
|
-
selector: "#dynamic-content",
|
|
182
|
-
outputDirClean: true,
|
|
183
|
-
snapshotScript: {
|
|
184
|
-
script: "customFilter",
|
|
185
|
-
module: bogusFile
|
|
186
|
-
},
|
|
187
|
-
timeout: 2000,
|
|
188
|
-
outputDir,
|
|
189
|
-
port
|
|
190
|
-
};
|
|
191
|
-
const twice = _.after(2, cleanupError.bind(null, done, 0));
|
|
137
|
+
describe("should fail for scripts", function () {
|
|
138
|
+
function createOptions (newOptions) {
|
|
139
|
+
const defaultOptions = {
|
|
140
|
+
source: inputFile,
|
|
141
|
+
hostname: "localhost",
|
|
142
|
+
selector: "#dynamic-content",
|
|
143
|
+
outputDirClean: true,
|
|
144
|
+
snapshotScript: bogusFile,
|
|
145
|
+
timeout: 2000,
|
|
146
|
+
outputDir,
|
|
147
|
+
port
|
|
148
|
+
};
|
|
149
|
+
return {
|
|
150
|
+
...defaultOptions,
|
|
151
|
+
...newOptions
|
|
152
|
+
};
|
|
153
|
+
}
|
|
192
154
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
155
|
+
const testOptions = [{
|
|
156
|
+
name: "should fail if a bogus script string is supplied",
|
|
157
|
+
options: {
|
|
158
|
+
snapshotScript: bogusFile
|
|
159
|
+
}
|
|
160
|
+
}, {
|
|
161
|
+
name: "should fail if a bogus script object is supplied",
|
|
162
|
+
options: {
|
|
163
|
+
snapshotScript: {
|
|
164
|
+
script: bogusFile
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}, {
|
|
168
|
+
name: "should fail if a customFilter is defined but no module",
|
|
169
|
+
options: {
|
|
170
|
+
snapshotScript: {
|
|
171
|
+
script: "customFilter"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}, {
|
|
175
|
+
name: "should fail if a customFilter is defined and bogus module",
|
|
176
|
+
options: {
|
|
177
|
+
browser: "phantomjs",
|
|
178
|
+
snapshotScript: {
|
|
179
|
+
script: "customFilter",
|
|
180
|
+
module: bogusFile
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}];
|
|
184
|
+
const driverOptions = browsers.map(browser => {
|
|
185
|
+
return testOptions.map(test => {
|
|
186
|
+
test.options.browser = browser;
|
|
187
|
+
return JSON.parse(JSON.stringify(test));
|
|
188
|
+
});
|
|
189
|
+
}).flat();
|
|
190
|
+
|
|
191
|
+
driverOptions.forEach(driver => {
|
|
192
|
+
it(driver.name, function (done) {
|
|
193
|
+
const options = createOptions(driver.options);
|
|
194
|
+
const twice = _.after(2, cleanupError.bind(null, done, 0));
|
|
195
|
+
ss.run(optHelp.decorate(options), twice)
|
|
196
|
+
.then(unexpectedSuccess.bind(null, done))
|
|
197
|
+
.catch(twice);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
196
200
|
});
|
|
197
201
|
};
|
|
198
202
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
const path = require("path");
|
|
8
8
|
const enableDestroy = require("server-destroy");
|
|
9
9
|
|
|
10
|
-
const timeout = require("./utils")
|
|
10
|
+
const { timeout } = require("./utils");
|
|
11
11
|
|
|
12
12
|
const basics = require("./basics");
|
|
13
13
|
const robots = require("./robots");
|
|
@@ -17,6 +17,7 @@ const processLimit = require("./process-limit");
|
|
|
17
17
|
const useJQuery = require("./use-jquery");
|
|
18
18
|
const snapshotScripts = require("./snapshot-scripts");
|
|
19
19
|
const phantomJSOptions = require("./phantomjs-options");
|
|
20
|
+
const puppeteer = require("./puppeteer");
|
|
20
21
|
|
|
21
22
|
const localRobotsFile = path.join(__dirname, "./test_robots.txt");
|
|
22
23
|
|
|
@@ -54,7 +55,11 @@ function serverContext (testSuiteFactory, port) {
|
|
|
54
55
|
});
|
|
55
56
|
});
|
|
56
57
|
|
|
57
|
-
describe("tests", testSuiteFactory({
|
|
58
|
+
describe("tests", testSuiteFactory({
|
|
59
|
+
port,
|
|
60
|
+
localRobotsFile,
|
|
61
|
+
browsers: ["phantomjs", "puppeteer"]
|
|
62
|
+
}));
|
|
58
63
|
};
|
|
59
64
|
}
|
|
60
65
|
|
|
@@ -68,6 +73,10 @@ describe("html-snapshots", function () {
|
|
|
68
73
|
"phantomjsOptions option", serverContext(phantomJSOptions.testSuite, 8035)
|
|
69
74
|
);
|
|
70
75
|
|
|
76
|
+
describe(
|
|
77
|
+
"puppeteer specific tests", serverContext(puppeteer.testSuite, 8042)
|
|
78
|
+
);
|
|
79
|
+
|
|
71
80
|
describe(
|
|
72
81
|
"additional snapshot scripts", serverContext(snapshotScripts.testSuite, 8036)
|
|
73
82
|
);
|
|
@@ -4,48 +4,61 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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),
|
|
55
|
+
ss.run(optHelp.decorate(options), (err, completed) => {
|
|
43
56
|
if (err) {
|
|
44
|
-
console.log(
|
|
57
|
+
console.log(`@@@ error = ${err}, completed=${completed.join(',')}`);
|
|
45
58
|
}
|
|
46
59
|
})
|
|
47
|
-
.then(
|
|
48
|
-
|
|
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(
|
|
70
|
+
.catch(e => {
|
|
58
71
|
checkActualFiles(e.notCompleted)
|
|
59
|
-
.then(
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
source: [ "http://localhost:"+port+"/" ],
|
|
79
|
+
const options = createOptions({
|
|
80
|
+
source: [ `http://localhost:${port}/` ],
|
|
69
81
|
selector: "#dynamic-content",
|
|
70
|
-
outputDir
|
|
71
|
-
|
|
72
|
-
timeout: timeout,
|
|
73
|
-
useJQuery: true
|
|
74
|
-
};
|
|
82
|
+
outputDir
|
|
83
|
+
});
|
|
75
84
|
|
|
76
|
-
ss.run(optHelp.decorate(options),
|
|
85
|
+
ss.run(optHelp.decorate(options), (err, completed) => {
|
|
77
86
|
if (err) {
|
|
78
|
-
console.log(
|
|
87
|
+
console.log(`@@@ error = ${err}, completed=${completed.join(',')}`);
|
|
79
88
|
}
|
|
80
89
|
})
|
|
81
|
-
.then(
|
|
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(
|
|
100
|
+
.catch(e => {
|
|
92
101
|
checkActualFiles(e.notCompleted)
|
|
93
|
-
.then(
|
|
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
|
-
|
|
102
|
-
input: "array",
|
|
103
|
-
source: [ "http://localhost:"+port+"/nojq" ],
|
|
110
|
+
const options = createOptions({
|
|
104
111
|
selector: "#pocs1",
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
120
|
-
input: "array",
|
|
121
|
-
source: [ "http://localhost:"+port+"/nojq" ],
|
|
124
|
+
const options = createOptions({
|
|
122
125
|
selector: ".nojq-notvisible",
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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,28 +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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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");
|
|
14
14
|
|
|
15
15
|
// Constants
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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;
|
|
21
21
|
|
|
22
22
|
function dumpTree (p) {
|
|
23
|
-
fs.readdirSync(p).forEach(
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
fs.readdirSync(p).forEach(file => {
|
|
24
|
+
const curPath = path.join(p, path.sep, file);
|
|
25
|
+
const stats = fs.statSync(curPath);
|
|
26
26
|
|
|
27
27
|
if (stats.isDirectory()) {
|
|
28
28
|
dumpTree(curPath);
|
|
@@ -33,7 +33,7 @@ function dumpTree (p) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
function checkActualFiles (files) {
|
|
36
|
-
|
|
36
|
+
let shortFile, outputRoot;
|
|
37
37
|
|
|
38
38
|
if (files.length > 0) {
|
|
39
39
|
shortFile = outputDir;
|
|
@@ -45,7 +45,7 @@ function checkActualFiles (files) {
|
|
|
45
45
|
return prev;
|
|
46
46
|
}, files[0]);
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
let exists = false; // toggle to dumpTree
|
|
49
49
|
outputRoot = path.dirname(shortFile);
|
|
50
50
|
try {
|
|
51
51
|
fs.statSync(outputRoot).isDirectory();
|
|
@@ -58,9 +58,9 @@ function checkActualFiles (files) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
return Promise.all(files.map(
|
|
61
|
+
return Promise.all(files.map(file => {
|
|
62
62
|
return pathExists(file)
|
|
63
|
-
.then(
|
|
63
|
+
.then(result => {
|
|
64
64
|
if (result) {
|
|
65
65
|
console.log("@@@ actually exists:" + file);
|
|
66
66
|
}
|
|
@@ -92,10 +92,10 @@ function countSpawnedProcesses (cb) {
|
|
|
92
92
|
if (process.platform === "darwin") {
|
|
93
93
|
wc = spawn("wc", ["-l"]);
|
|
94
94
|
pgrep = spawn("pgrep", [spawnedProcessPattern]);
|
|
95
|
-
pgrep.stdout.on("data",
|
|
95
|
+
pgrep.stdout.on("data", data => {
|
|
96
96
|
wc.stdin.write(data);
|
|
97
97
|
});
|
|
98
|
-
pgrep.stdout.on("end",
|
|
98
|
+
pgrep.stdout.on("end", () => {
|
|
99
99
|
wc.stdin.end();
|
|
100
100
|
});
|
|
101
101
|
wc.stdout.on("data", cb);
|
|
@@ -105,16 +105,16 @@ function countSpawnedProcesses (cb) {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
// Clear any lingering
|
|
108
|
+
// Clear any lingering browser processes in play
|
|
109
109
|
function killSpawnedProcesses (cb) {
|
|
110
110
|
var pkill = spawn("pkill", [spawnedProcessPattern]);
|
|
111
111
|
var guardedCb = _.once(cb);
|
|
112
112
|
|
|
113
|
-
pkill.on("exit",
|
|
113
|
+
pkill.on("exit", () => {
|
|
114
114
|
setTimeout(guardedCb, 2000);
|
|
115
115
|
});
|
|
116
|
-
pkill.on("error",
|
|
117
|
-
guardedCb(new Error("failed to kill
|
|
116
|
+
pkill.on("error", () => {
|
|
117
|
+
guardedCb(new Error("failed to kill browser processes"));
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
120
|
|
|
@@ -123,8 +123,8 @@ function cleanup (done, arg) {
|
|
|
123
123
|
if (process.platform === "win32") {
|
|
124
124
|
setTimeout(done, 1000, arg);
|
|
125
125
|
} else {
|
|
126
|
-
setImmediate(
|
|
127
|
-
killSpawnedProcesses(
|
|
126
|
+
setImmediate(() => {
|
|
127
|
+
killSpawnedProcesses(err => {
|
|
128
128
|
done(multiError(err, arg));
|
|
129
129
|
});
|
|
130
130
|
});
|
package/examples/utils/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utilities for the examples.
|
|
3
|
-
* Copyright (c) 2013 - 2022, Alex Grant, LocalNerve, contributors
|
|
4
|
-
*/
|
|
5
|
-
const spawn = require('child_process').spawn;
|
|
6
|
-
|
|
7
|
-
function cleanupAndExit (failure) {
|
|
8
|
-
var pkill;
|
|
9
|
-
|
|
10
|
-
if (failure) {
|
|
11
|
-
if (process.platform === 'win32') {
|
|
12
|
-
process.exit(0);
|
|
13
|
-
} else {
|
|
14
|
-
// kill any lingering phantomjs processes
|
|
15
|
-
pkill = spawn('pkill', ['^phantomjs$']);
|
|
16
|
-
pkill.on('exit', function () {
|
|
17
|
-
process.exit(0);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = {
|
|
24
|
-
cleanupAndExit
|
|
25
|
-
};
|