puppeteer-browser-ready 0.4.7 → 0.5.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/README.md CHANGED
@@ -26,22 +26,35 @@ import { browserReady } from 'puppeteer-browser-ready';
26
26
  ```
27
27
 
28
28
  ## B) Usage
29
- Use the `browserReady.goto()` function to tell Puppeteer which page to open. The **Promise** will
30
- resolve with a **Web** object containing a `title` field and a `html` field. Pass the **Web**
31
- object to the `browserReady.close()` function to disconnect the page.
29
+ Use the `browserReady.goto(url, options)` function to tell Puppeteer which page to open.
30
+ The **Promise** will resolve with a **Web** object containing a `title` field and a `html` field.
31
+ Pass the **Web** object to the `browserReady.close(web)` function to disconnect the page.
32
32
  ```javascript
33
33
  const url = 'https://pretty-print-json.js.org/';
34
34
  let web; //fields: browser, page, response, status, location, title, html, $
35
35
  before(async () => web = await puppeteer.launch().then(browserReady.goto(url));
36
36
  after(async () => await browserReady.close(web));
37
37
  ```
38
+ ### `goto()` Options
39
+ | Name (key) | Type | Default | Description |
40
+ | :----------- | :---------- | :------ | :----------------------------------------------- |
41
+ | `addCheerio` | **boolean** | `false` | Return a cheerio reference for querying the DOM. |
42
+ | `verbose` | **boolean** | `false` | Output HTTP connection debug messages. |
43
+
44
+ ### `startWebServer()` Options
45
+ | Name (key) | Type | Default| Description |
46
+ | :------------ | :---------- | :----- | :----------------------------------------------- |
47
+ | `autoCleanup` | **boolean** | `true` | Terminate connection on interruption (`SIGINT`). |
48
+ | `folder` | **string** | `'.'` | Document root for the static web server. |
49
+ | `port` | **number** | `0` | Port number for server (`0` find open port). |
50
+ | `verbose` | **boolean** | `true` | Output informational messages. |
38
51
 
39
52
  ## C) TypeScript Declarations
40
53
  The **TypeScript Declaration File** file is
41
54
  [puppeteer-browser-ready.d.ts](dist/puppeteer-browser-ready.d.ts) in the **dist** folder.
42
55
 
43
- The `browserReady.goto()` function returns a function that takes a Puppeteer **Browser** object and
44
- returns a **Promise** that resolves with a **Web** object:
56
+ The `browserReady.goto(url, options)` function returns a function that takes a Puppeteer **Browser**
57
+ object and returns a **Promise** that resolves with a **Web** object:
45
58
  ```typescript
46
59
  type Web = {
47
60
  browser: Puppeteer.Browser,
@@ -54,8 +67,8 @@ type Web = {
54
67
  };
55
68
  ```
56
69
 
57
- The optional `browserReady.startWebServer()` function starts a static web server and returns a
58
- **Promise** for when the [server](spec/start-web-server.spec.js) is ready:
70
+ The optional `browserReady.startWebServer(options)` function starts a static web server and returns
71
+ a **Promise** for when the [server](spec/start-web-server.spec.js) is ready:
59
72
  ```typescript
60
73
  export type Http = {
61
74
  server: Server,
@@ -69,7 +82,7 @@ export type Http = {
69
82
 
70
83
  ## D) Examples
71
84
 
72
- ### Example: Node.js program
85
+ ### Example 1: Node.js program
73
86
  **Code:**
74
87
  ```javascript
75
88
  import puppeteer from 'puppeteer';
@@ -95,7 +108,7 @@ The HTML from https://pretty-print-json.js.org/ is 8200 characters
95
108
  long and contains 7 <p> tags.
96
109
  ```
97
110
 
98
- ### Example: Mocha specification suite
111
+ ### Example 2: Mocha specification suite
99
112
  **Code:**
100
113
  ```javascript
101
114
  // Mocha Specification Suite
@@ -159,9 +172,9 @@ describe('The document content', () => {
159
172
  ✓ has a 🚀 traveling to 🪐!
160
173
  ```
161
174
 
162
- ### Example: Start and shutdown a static web server
163
- The [startWebServer() and shutdownWebServer()](spec/start-web-server.spec.js) functions can be used
164
- in global fixtures to start and shutdown a static web server.
175
+ ### Example 3: Start and shutdown a static web server
176
+ The [startWebServer(options) and shutdownWebServer(http)](spec/start-web-server.spec.js) functions
177
+ can be used in global fixtures to start and shutdown a static web server.
165
178
 
166
179
  For example, the **spec/fixtures/setup-teardown.js** file below starts a web server on port `7123`
167
180
  with the web root pointed to the project's **docs** folder.
@@ -1,4 +1,4 @@
1
- //! puppeteer-browser-ready v0.4.7 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
1
+ //! puppeteer-browser-ready v0.5.0 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
2
2
 
3
3
  /// <reference types="cheerio" />
4
4
  import httpTerminator from 'http-terminator';
@@ -30,7 +30,7 @@ export declare type Web = {
30
30
  };
31
31
  export declare type BrowserReadyOptions = {
32
32
  addCheerio?: boolean;
33
- debugMode?: boolean;
33
+ verbose?: boolean;
34
34
  };
35
35
  declare const browserReady: {
36
36
  log(...args: unknown[]): void;
@@ -1,4 +1,4 @@
1
- //! puppeteer-browser-ready v0.4.7 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
1
+ //! puppeteer-browser-ready v0.5.0 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
2
2
 
3
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -52,9 +52,9 @@ const browserReady = {
52
52
  return http.terminator.terminate();
53
53
  },
54
54
  goto(url, options) {
55
- const defaults = { addCheerio: true, debugMode: false };
55
+ const defaults = { addCheerio: true, verbose: false };
56
56
  const settings = Object.assign(Object.assign({}, defaults), options);
57
- const log = (label, msg) => settings.debugMode &&
57
+ const log = (label, msg) => settings.verbose &&
58
58
  console.log(' ', Date.now() % 100000, label + ':', msg);
59
59
  const web = (browser) => __awaiter(this, void 0, void 0, function* () {
60
60
  log('Connected', browser.isConnected());
@@ -1,4 +1,4 @@
1
- //! puppeteer-browser-ready v0.4.7 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
1
+ //! puppeteer-browser-ready v0.5.0 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
2
2
 
3
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -67,9 +67,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
67
67
  return http.terminator.terminate();
68
68
  },
69
69
  goto(url, options) {
70
- const defaults = { addCheerio: true, debugMode: false };
70
+ const defaults = { addCheerio: true, verbose: false };
71
71
  const settings = Object.assign(Object.assign({}, defaults), options);
72
- const log = (label, msg) => settings.debugMode &&
72
+ const log = (label, msg) => settings.verbose &&
73
73
  console.log(' ', Date.now() % 100000, label + ':', msg);
74
74
  const web = (browser) => __awaiter(this, void 0, void 0, function* () {
75
75
  log('Connected', browser.isConnected());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puppeteer-browser-ready",
3
- "version": "0.4.7",
3
+ "version": "0.5.0",
4
4
  "description": "Simple utility to go to a URL and wait for the HTTP response (written in TypeScript)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -88,8 +88,8 @@
88
88
  "@types/cheerio": "~0.22",
89
89
  "@types/express": "~4.17",
90
90
  "@types/node": "~17.0",
91
- "@typescript-eslint/eslint-plugin": "~5.15",
92
- "@typescript-eslint/parser": "~5.15",
91
+ "@typescript-eslint/eslint-plugin": "~5.16",
92
+ "@typescript-eslint/parser": "~5.16",
93
93
  "add-dist-header": "~0.1",
94
94
  "assert-deep-strict-equal": "~1.0",
95
95
  "cpy-cli": "~4.1",