presidium 3.2.0 → 3.3.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.
@@ -849,24 +849,20 @@ class GoogleChromeDevToolsRuntime {
849
849
  * Supported platforms:
850
850
  * * `mac-arm64`
851
851
  * * `linux64`
852
+ * * `win64`
852
853
  *
853
854
  * ## Further Installation
854
855
  * Some further installation may be required for Linux platforms.
855
856
  *
856
- * ### Install headless dependencies for Amazon Linux 2023
857
+ * ### Install headless dependencies for Amazon Linux 2023 / Red Hat
857
858
  * ```sh
858
859
  * sudo dnf install -y cairo pango nss nspr atk at-spi2-atk cups-libs libdrm libxkbcommon libXcomposite libXdamage libXfixes libXrandr mesa-libgbm alsa-lib
859
860
  * ```
860
861
  *
861
- * ### Install headless dependencies for Ubuntu
862
+ * ### Install headless dependencies for Ubuntu / Debian
862
863
  * ```sh
863
864
  * sudo apt-get update && sudo apt-get install -y libcairo2 libpango-1.0-0 libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libatspi2.0-0 libcups2 libdrm-dev libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm-dev libasound2-dev
864
- *
865
- * # disable AppArmor unprivileged security restriction
866
- * echo "kernel.apparmor_restrict_unprivileged_userns=0" | sudo tee /etc/sysctl.d/60-apparmor-namespace.conf
867
- * sudo sysctl -p /etc/sysctl.d/60-apparmor-namespace.conf
868
865
  * ```
869
- *
870
866
  */
871
867
  class GoogleChromeDevTools extends EventEmitter {
872
868
  constructor(options = {}) {
@@ -921,7 +917,11 @@ class GoogleChromeDevTools extends EventEmitter {
921
917
  offerPerMessageDeflate: false,
922
918
  })
923
919
  this.websocket.on('error', error => {
924
- throw error
920
+ if (this.closed && error.code == 'ECONNRESET') {
921
+ console.error('Reset after close:', error)
922
+ } else {
923
+ throw error
924
+ }
925
925
  })
926
926
 
927
927
  this.websocket.on('message', message => {
@@ -995,10 +995,37 @@ class GoogleChromeDevTools extends EventEmitter {
995
995
  * ```
996
996
  */
997
997
  close() {
998
+ this.closed = true
998
999
  this.websocket.sendClose()
999
- this.websocket.close()
1000
- this.googleChromeForTesting.close()
1000
+ this.websocket.on('close', () => {
1001
+ this.googleChromeForTesting.cmd.on('close', () => {
1002
+ this.emit('close')
1003
+ })
1004
+ this.googleChromeForTesting.close()
1005
+ })
1001
1006
  }
1007
+
1008
+ /**
1009
+ * @name Event: close
1010
+ *
1011
+ * @docs
1012
+ * ```coffeescript [specscript]
1013
+ * emit('close')
1014
+ * ```
1015
+ *
1016
+ * The `close` event. Emitted when the websocket connection to the DevTools server is closed and the Google Chrome for Testing process is terminated.
1017
+ *
1018
+ * Event Data:
1019
+ * * (none)
1020
+ *
1021
+ * ```javascript
1022
+ * googleChromeForTesting.on('close', () => {
1023
+ * console.log('WebSocket connection closed and Google Chrome for Testing process terminated.')
1024
+ * })
1025
+ * ```
1026
+ */
1027
+
1002
1028
  }
1003
1029
 
1030
+
1004
1031
  module.exports = GoogleChromeDevTools
@@ -18,7 +18,7 @@ async function getChromeVersions() {
18
18
  return data
19
19
  }
20
20
 
21
- function updateConsoleLog(message) {
21
+ function updateConsoleLog(message, platform) {
22
22
  readline.cursorTo(process.stdout, 0, undefined);
23
23
  readline.clearLine(process.stdout, 0);
24
24
  process.stdout.write(message);
@@ -33,7 +33,11 @@ function getPlatform() {
33
33
 
34
34
  if (platform == 'mac') {
35
35
  platform = `${platform}-${arch}`
36
- } else {
36
+ }
37
+ else if (platform == 'win32') {
38
+ platform = `win${arch.slice(1)}`
39
+ }
40
+ else {
37
41
  platform = `${platform}${arch.slice(1)}`
38
42
  }
39
43
 
@@ -58,13 +62,26 @@ async function getChromeUrl() {
58
62
  }
59
63
 
60
64
  async function installChrome() {
65
+ const platform = getPlatform()
66
+ const delimiter = platform.startsWith('win') ? '\\' : '/'
61
67
  const url = await getChromeUrl.call(this)
62
- let filepath = `${this.chromeDir}/${url.replace('https://storage.googleapis.com/chrome-for-testing-public/', '')}`
63
- if (!filepath.startsWith('/')) {
68
+
69
+ let filepath = `${this.chromeDir}${delimiter}${url.replace('https://storage.googleapis.com/chrome-for-testing-public/', '')}`
70
+ if (platform.startsWith('win')) {
71
+ filepath = filepath.replace(/\//g, '\\')
72
+ if (!filepath.startsWith(`${__dirname[0]}:`)) {
73
+ filepath = path.join(process.cwd(), filepath)
74
+ }
75
+ } else if (!filepath.startsWith('/')) {
64
76
  filepath = path.join(process.cwd(), filepath)
65
77
  }
66
- let parentDir = `${filepath.split('/').slice(0, -1).join('/')}`
67
- if (!parentDir.startsWith('/')) {
78
+
79
+ let parentDir = `${filepath.split(delimiter).slice(0, -1).join(delimiter)}`
80
+ if (platform.startsWith('win')) {
81
+ if (!filepath.startsWith(`${__dirname[0]}:`)) {
82
+ parentDir = path.join(process.cwd(), parentDir)
83
+ }
84
+ } else if (!parentDir.startsWith('/')) {
68
85
  parentDir = path.join(process.cwd(), parentDir)
69
86
  }
70
87
  await fs.promises.mkdir(parentDir, { recursive: true })
@@ -81,9 +98,9 @@ async function installChrome() {
81
98
  response.on('data', chunk => {
82
99
  downloadedLength += chunk.length
83
100
  if (downloadedLength == contentLength) {
84
- updateConsoleLog(`Downloading ${url} (${downloadedLength} / ${contentLength} bytes)\n`)
101
+ updateConsoleLog(`Downloading ${url} (${downloadedLength} / ${contentLength} bytes)\n`, platform)
85
102
  } else {
86
- updateConsoleLog(`Downloading ${url} (${downloadedLength} / ${contentLength} bytes)`)
103
+ updateConsoleLog(`Downloading ${url} (${downloadedLength} / ${contentLength} bytes)`, platform)
87
104
  }
88
105
 
89
106
  fileStream.write(chunk)
@@ -98,10 +115,11 @@ async function installChrome() {
98
115
  })
99
116
  await promise
100
117
 
118
+ console.log('Extracting', filepath)
101
119
  try {
102
120
  await extract(filepath, { dir: parentDir })
103
- } catch {
104
- await sleep(100)
121
+ } catch (_error) {
122
+ await sleep(1000)
105
123
  await extract(filepath, { dir: parentDir })
106
124
  }
107
125
  }
@@ -114,13 +132,15 @@ async function getChromeFilepath() {
114
132
 
115
133
  try {
116
134
  for await (const filepath of walk(parentDir)) {
117
- console.log(filepath)
118
135
  if (platform.startsWith('mac') && filepath.endsWith('Google Chrome for Testing')) {
119
136
  return filepath
120
137
  }
121
138
  if (platform.startsWith('linux') && filepath.endsWith('chrome')) {
122
139
  return filepath
123
140
  }
141
+ if (platform.startsWith('win') && filepath.endsWith('chrome.exe')) {
142
+ return filepath
143
+ }
124
144
  }
125
145
  } catch (error) {
126
146
  if (error.code == 'ENOENT') {
@@ -173,6 +193,7 @@ async function getChromeFilepath() {
173
193
  * Supported platforms:
174
194
  * * `mac-arm64`
175
195
  * * `linux64`
196
+ * * `win64`
176
197
  *
177
198
  * ## Further Installation
178
199
  * Some further installation may be required for Linux platforms.
@@ -185,10 +206,6 @@ async function getChromeFilepath() {
185
206
  * ### Install headless dependencies for Ubuntu / Debian
186
207
  * ```sh
187
208
  * sudo apt-get update && sudo apt-get install -y libcairo2 libpango-1.0-0 libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libatspi2.0-0 libcups2 libdrm-dev libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm-dev libasound2-dev
188
- *
189
- * # disable AppArmor unprivileged security restriction
190
- * echo "kernel.apparmor_restrict_unprivileged_userns=0" | sudo tee /etc/sysctl.d/60-apparmor-namespace.conf
191
- * sudo sysctl -p /etc/sysctl.d/60-apparmor-namespace.conf
192
209
  * ```
193
210
  */
194
211
  class GoogleChromeForTesting {
@@ -236,6 +253,7 @@ class GoogleChromeForTesting {
236
253
  `--user-data-dir=${this.userDataDir}`,
237
254
  ...this.headless ? ['--headless'] : [],
238
255
  ...this.useMockKeychain ? ['--use-mock-keychain'] : [],
256
+ '--no-sandbox',
239
257
  ])
240
258
  cmd.stdout.pipe(process.stdout)
241
259
  cmd.stderr.pipe(process.stderr)
@@ -288,6 +306,18 @@ class GoogleChromeForTesting {
288
306
  * ```coffeescript [specscript]
289
307
  * close() -> undefined
290
308
  * ```
309
+ *
310
+ * Terminates the Google Chrome for Testing process.
311
+ *
312
+ * Arguments:
313
+ * * (none)
314
+ *
315
+ * Return:
316
+ * * `undefined`
317
+ *
318
+ * ```javascript
319
+ * googleChromeForTesting.close()
320
+ * ```
291
321
  */
292
322
  close() {
293
323
  this.cmd.kill('SIGKILL')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "A library for creating web services",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",