puppeteer-browser-ready 1.2.3 → 1.3.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/README.md CHANGED
@@ -130,14 +130,28 @@ describe('The web page', () => {
130
130
  before(loadWebPage);
131
131
  after(closeWebPage);
132
132
 
133
- it('has the correct URL -> ' + url, () => {
133
+ it('has the correct URL', () => {
134
134
  const actual = { status: web.status, url: web.location.href };
135
135
  const expected = { status: 200, url: url };
136
136
  assertDeepStrictEqual(actual, expected);
137
137
  });
138
138
 
139
- it('has exactly one header, main, and footer', () => {
140
- const actual = getTags('body >*');
139
+ it('title starts with "Pretty-Print JSON"', () => {
140
+ const actual = { title: web.title.substring(0, 17) };
141
+ const expected = { title: 'Pretty-Print JSON' };
142
+ assertDeepStrictEqual(actual, expected);
143
+ });
144
+
145
+ it('body has exactly one header, main, and footer -- node-html-parsed', () => {
146
+ const getTags = (elems) => [...elems].map(elem => elem.tagName.toLowerCase());
147
+ const actual = getTags(web.root.querySelectorAll('body >*'));
148
+ const expected = ['header', 'main', 'footer'];
149
+ assertDeepStrictEqual(actual, expected);
150
+ });
151
+
152
+ it('body has exactly one header, main, and footer -- page.$$eval()', async () => {
153
+ const getTags = (elems) => elems.map(elem => elem.nodeName.toLowerCase());
154
+ const actual = await web.page.$$eval('body >*', getTags);
141
155
  const expected = ['header', 'main', 'footer'];
142
156
  assertDeepStrictEqual(actual, expected);
143
157
  });
@@ -160,8 +174,10 @@ describe('The document content', () => {
160
174
  **Output:**
161
175
  ```
162
176
  The web page
163
- ✓ has the correct URL -> https://pretty-print-json.js.org/
164
- has exactly one header, main, and footer
177
+ ✓ has the correct URL
178
+ title starts with "Pretty-Print JSON"
179
+ ✓ body has exactly one header, main, and footer -- node-html-parsed
180
+ ✓ body has exactly one header, main, and footer -- page.$$eval()
165
181
 
166
182
  The document content
167
183
  ✓ has a 🚀 traveling to 🪐!
@@ -218,7 +234,7 @@ Example configuration in **package.json** to allow 5,000 ms:
218
234
  <br>
219
235
 
220
236
  ---
221
- **CLI Build Tools**
237
+ **CLI Build Tools for package.json**
222
238
  - 🎋 [add-dist-header](https://github.com/center-key/add-dist-header):&nbsp; _Prepend a one-line banner comment (with license notice) to distribution files_
223
239
  - 📄 [copy-file-util](https://github.com/center-key/copy-file-util):&nbsp; _Copy or rename a file with optional package version number_
224
240
  - 📂 [copy-folder-util](https://github.com/center-key/copy-folder-util):&nbsp; _Recursively copy files from one folder to another folder_
@@ -1,6 +1,5 @@
1
- //! puppeteer-browser-ready v1.2.3 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
1
+ //! puppeteer-browser-ready v1.3.1 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
2
2
 
3
- /// <reference types="cheerio" />
4
3
  import { Browser, HTTPResponse, Page } from 'puppeteer';
5
4
  import { HTMLElement } from 'node-html-parser';
6
5
  import { Server } from 'http';
@@ -29,11 +28,9 @@ export type Web = {
29
28
  location: Location;
30
29
  title: string | null;
31
30
  html: string | null;
32
- $: cheerio.Root | null;
33
31
  root: HTMLElement | null;
34
32
  };
35
33
  export type BrowserReadySettings = {
36
- addCheerio: boolean;
37
34
  parseHtml: boolean;
38
35
  verbose: boolean;
39
36
  };
@@ -1,7 +1,6 @@
1
- //! puppeteer-browser-ready v1.2.3 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
1
+ //! puppeteer-browser-ready v1.3.1 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
2
2
 
3
3
  import { parse } from 'node-html-parser';
4
- import cheerio from 'cheerio';
5
4
  import express from 'express';
6
5
  import httpTerminator from 'http-terminator';
7
6
  // Package
@@ -43,13 +42,11 @@ const browserReady = {
43
42
  return http.terminator.terminate();
44
43
  },
45
44
  goto(url, options) {
46
- const defaults = { addCheerio: false, parseHtml: true, verbose: false };
45
+ const defaults = { parseHtml: true, verbose: false };
47
46
  const settings = { ...defaults, ...options };
48
- if (settings.addCheerio)
49
- console.log('puppeteer-browser-ready: Option "addCheerio" is deprecated, use "parseHtml" instead.');
50
47
  const log = (label, msg) => settings.verbose &&
51
48
  console.log(' ', Date.now() % 100000, label + ':', msg);
52
- const rootInfo = (root) => root.constructor.name + '/' + root.firstChild.toString();
49
+ const rootInfo = (root) => root.constructor.name + '/' + root.firstChild?.toString();
53
50
  const web = async (browser) => {
54
51
  log('Connected', browser.isConnected());
55
52
  try {
@@ -65,10 +62,9 @@ const browserReady = {
65
62
  log('Title', title);
66
63
  const html = response && await response.text();
67
64
  log('Bytes', html?.length);
68
- const $ = html && settings.addCheerio ? cheerio.load(html) : null; //deprecated
69
65
  const root = html && settings.parseHtml ? parse(html) : null;
70
66
  log('DOM root', root ? rootInfo(root) : null);
71
- return { browser, page, response, status, location, title, html, $, root };
67
+ return { browser, page, response, status, location, title, html, root };
72
68
  }
73
69
  catch (error) {
74
70
  const status = browser.isConnected() ? 'connected' : 'not connected';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puppeteer-browser-ready",
3
- "version": "1.2.3",
3
+ "version": "1.3.1",
4
4
  "description": "Simple utility to go to a URL and wait for the HTTP response",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,7 +16,10 @@
16
16
  },
17
17
  "./": "./dist/"
18
18
  },
19
- "repository": "github:center-key/puppeteer-browser-ready",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/center-key/puppeteer-browser-ready.git"
22
+ },
20
23
  "homepage": "https://github.com/center-key/puppeteer-browser-ready",
21
24
  "bugs": "https://github.com/center-key/puppeteer-browser-ready/issues",
22
25
  "docs": "https://github.com/center-key/puppeteer-browser-ready#readme",
@@ -74,7 +77,7 @@
74
77
  "build": [
75
78
  "tsc",
76
79
  "add-dist-header build dist",
77
- "html-validator"
80
+ "html-validator spec"
78
81
  ]
79
82
  },
80
83
  "scripts": {
@@ -85,31 +88,29 @@
85
88
  "puppeteer": "^15 || ^16 || ^17 || ^18 || ^19.7 || ^20 || ^21"
86
89
  },
87
90
  "dependencies": {
88
- "cheerio": "~1.0.0-rc.12",
89
91
  "express": "~4.18",
90
92
  "http-terminator": "~3.2",
91
93
  "node-html-parser": "~6.1"
92
94
  },
93
95
  "devDependencies": {
94
- "@types/cheerio": "~0.22",
95
96
  "@types/express": "~4.17",
96
97
  "@types/mocha": "~10.0",
97
- "@types/node": "~20.6",
98
+ "@types/node": "~20.10",
98
99
  "@types/ws": "~8.5",
99
- "@typescript-eslint/eslint-plugin": "~6.7",
100
- "@typescript-eslint/parser": "~6.7",
100
+ "@typescript-eslint/eslint-plugin": "~6.15",
101
+ "@typescript-eslint/parser": "~6.15",
101
102
  "add-dist-header": "~1.3",
102
103
  "assert-deep-strict-equal": "~1.1",
103
104
  "copy-file-util": "~1.1",
104
105
  "copy-folder-util": "~1.1",
105
- "eslint": "~8.49",
106
+ "eslint": "~8.56",
106
107
  "jshint": "~2.13",
107
108
  "mocha": "~10.2",
108
- "open": "~9.1",
109
- "puppeteer": "~21.2",
109
+ "open": "~10.0",
110
+ "puppeteer": "~21.6",
110
111
  "rimraf": "~5.0",
111
112
  "run-scripts-util": "~1.2",
112
- "typescript": "~5.2",
113
- "w3c-html-validator": "~1.4"
113
+ "typescript": "~5.3",
114
+ "w3c-html-validator": "~1.6"
114
115
  }
115
116
  }