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.
Files changed (47) hide show
  1. package/.github/workflows/verify.yml +2 -2
  2. package/HISTORY.md +42 -0
  3. package/README.md +92 -244
  4. package/examples/README.md +149 -0
  5. package/examples/custom/package-lock.json +1090 -9
  6. package/examples/custom/package.json +1 -1
  7. package/examples/debug-phantomjs/package-lock.json +1977 -292
  8. package/examples/debug-phantomjs/package.json +1 -1
  9. package/examples/debug-phantomjs/snapshot.js +1 -0
  10. package/examples/debug-puppeteer/README.md +18 -0
  11. package/examples/debug-puppeteer/package-lock.json +2804 -0
  12. package/examples/debug-puppeteer/package.json +12 -0
  13. package/examples/debug-puppeteer/snapshot.js +30 -0
  14. package/examples/html5rocks/package-lock.json +734 -18
  15. package/examples/html5rocks/package.json +1 -1
  16. package/examples/html5rocks/snapshot.js +0 -6
  17. package/examples/process-limit/package-lock.json +734 -18
  18. package/examples/process-limit/package.json +1 -1
  19. package/examples/simple-promise/package-lock.json +734 -18
  20. package/examples/simple-promise/package.json +1 -1
  21. package/examples/sitemap-index/package-lock.json +734 -18
  22. package/examples/sitemap-index/package.json +1 -1
  23. package/examples/sitemap-index/snapshot.js +0 -1
  24. package/examples/verbose/package-lock.json +734 -19
  25. package/examples/verbose/package.json +1 -1
  26. package/examples/verbose/snapshot.js +1 -0
  27. package/lib/html-snapshots.js +87 -4
  28. package/lib/input-generators/_base.js +7 -1
  29. package/lib/puppeteer/index.js +98 -0
  30. package/lib/puppeteer/removeScripts.js +8 -0
  31. package/package.json +6 -2
  32. package/test/mocha/browsers/puppeteer.js +106 -0
  33. package/test/mocha/browsers/server/index.html +9 -0
  34. package/test/mocha/browsers/test.js +11 -0
  35. package/test/mocha/html-snapshots/basics.js +60 -47
  36. package/test/mocha/html-snapshots/phantomjs-options.js +54 -60
  37. package/test/mocha/html-snapshots/process-limit.js +100 -92
  38. package/test/mocha/html-snapshots/puppeteer.js +47 -0
  39. package/test/mocha/html-snapshots/robots.js +137 -120
  40. package/test/mocha/html-snapshots/server/public/page-sitemap.xml +16 -0
  41. package/test/mocha/html-snapshots/sitemap-index.js +89 -80
  42. package/test/mocha/html-snapshots/sitemap.js +75 -31
  43. package/test/mocha/html-snapshots/snapshot-scripts.js +124 -120
  44. package/test/mocha/html-snapshots/test.js +11 -2
  45. package/test/mocha/html-snapshots/use-jquery.js +65 -64
  46. package/test/mocha/html-snapshots/utils.js +29 -29
  47. 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
- var path = require("path");
8
- var fs = require("fs");
9
- var rimraf = require("rimraf").sync;
10
- var utils = require("./utils");
11
- var optHelp = require("../../helpers/options");
12
- var resHelp = require("../../helpers/result");
13
- var ss = require("../../../lib/html-snapshots");
14
-
15
- // missing destructuring, will write postcard...
16
- var timeout = utils.timeout;
17
- var outputDir = utils.outputDir;
18
- var cleanup = utils.cleanup;
19
- var unexpectedError = utils.unexpectedError;
20
- var unexpectedSuccess = utils.unexpectedSuccess;
21
- var checkActualFiles = utils.checkActualFiles;
22
-
23
- var outputBase = path.resolve(outputDir, "..");
24
- var cookiesFile = path.join(outputBase, "cookies.txt");
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
- var port = options.port;
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
- var options = {
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
- var options = {
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), function (err, completed) {
71
+ ss.run(optHelp.decorate(options), (err, completed) => {
68
72
  if (err) {
69
- console.log('@@@ error = '+err+", completed="+completed.join(','));
73
+ console.log(`@@@ error = ${err}, completed=${completed.join(',')}`);
70
74
  }
71
75
  })
72
76
  .then(() => {
73
- var assertionError;
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
- var options = {
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
- "--cookies-file="+cookiesFile,
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), function (err, completed) {
104
+ ss.run(optHelp.decorate(options), (err, completed) => {
106
105
  if (err) {
107
- console.log('@@@ error = '+err+", completed="+completed.join(','));
106
+ console.log(`@@@ error = ${err}, completed=${completed.join(',')}`);
108
107
  }
109
108
  })
110
109
  .then(() => {
111
- var assertionError;
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
- var options = {
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
- "--cookies-file="+cookiesFile,
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
- var assertionError;
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 { port, localRobotsFile: inputFile } = options;
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
- it("should limit as expected", function (done) {
51
- const processLimit = urls - 1;
52
- const complete = completeTest.bind(null, done, processLimit);
53
-
54
- if (process.platform === "win32") {
55
- assert.ok(true, "Skipping posix compliant tests for processLimit");
56
- done();
57
- } else {
58
- rimraf(outputDir);
59
-
60
- killSpawnedProcesses(function (err) {
61
- const options = {
62
- source: inputFile,
63
- hostname: "localhost",
64
- selector: "#dynamic-content",
65
- outputDirClean: true,
66
- outputDir,
67
- timeout,
68
- processLimit,
69
- port
70
- };
71
-
72
- if (err) {
73
- return done(err);
74
- }
75
-
76
- ss.run(optHelp.decorate(options))
77
- .then(() => {
78
- complete();
79
- })
80
- .catch(e => {
81
- complete(e || unexpectedError, e.notCompleted);
82
- });
83
-
84
- timer = setInterval(() => {
85
- countSpawnedProcesses(function (count) {
86
- // console.log("@@@ DEBUG @@@ phantom count: "+count);
87
- if (count > processLimit) {
88
- phantomCount = count;
89
- clearInterval(timer);
90
- }
91
- });
92
- }, pollInterval);
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
- it("should limit to just one process", function (done) {
98
- const processLimit = 1;
99
- const complete = completeTest.bind(null, done, processLimit);
100
-
101
- if (process.platform === "win32") {
102
- assert.ok(true, "Skipping posix compliant tests for processLimit");
103
- done();
104
- } else {
105
- rimraf(outputDir);
106
-
107
- killSpawnedProcesses(function (err) {
108
- const options = {
109
- source: inputFile,
110
- hostname: "localhost",
111
- selector: "#dynamic-content",
112
- outputDirClean: true,
113
- outputDir,
114
- timeout,
115
- processLimit,
116
- port
117
- };
118
-
119
- if (err) {
120
- return done(err);
121
- }
122
-
123
- ss.run(optHelp.decorate(options))
124
- .then(() => {
125
- complete();
126
- })
127
- .catch(e => {
128
- complete(e || unexpectedError, e.notCompleted);
129
- });
130
-
131
- timer = setInterval(function () {
132
- countSpawnedProcesses(function (count) {
133
- // console.log("@@@ DEBUG @@@ phantom count: "+count);
134
- if (count > processLimit) {
135
- phantomCount = count;
136
- clearInterval(timer);
137
- }
138
- });
139
- }, pollInterval);
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
+ };