system-testing 1.0.20 → 1.0.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "system-testing",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "System testing with Selenium and browsers.",
5
5
  "keywords": [
6
6
  "system",
@@ -29,6 +29,7 @@
29
29
  "htmlfy": "^1.0.0",
30
30
  "mime": "^4.0.7",
31
31
  "moment": "^2.30.1",
32
+ "scoundrel-remote-eval": "^1.0.6",
32
33
  "ws": "^8.18.3"
33
34
  },
34
35
  "peerDependencies": {
@@ -1,3 +1,5 @@
1
+ import Client from "scoundrel-remote-eval/src/client/index.js"
2
+ import ClientWebSocket from "scoundrel-remote-eval/src/client/connections/web-socket/index.js"
1
3
  import {digg} from "diggerize"
2
4
  import EventEmitter from "events"
3
5
 
@@ -20,6 +22,38 @@ export default class SystemTestBrowserHelper {
20
22
  this.events = new EventEmitter()
21
23
 
22
24
  shared.systemTestBrowserHelper = this
25
+
26
+ this.startScoundrel()
27
+ }
28
+
29
+ async startScoundrel() {
30
+ this.scoundrelWs = new WebSocket("http://localhost:8090")
31
+ this.scoundrelClientWebSocket = new ClientWebSocket(this.scoundrelWs)
32
+
33
+ await this.scoundrelClientWebSocket.waitForOpened()
34
+
35
+ this.scoundrelClient = new Client(this.scoundrelClientWebSocket)
36
+ this.events.emit("scoundrelStarted")
37
+ }
38
+
39
+ waitForScoundrelStarted() {
40
+ return new Promise((resolve) => {
41
+ if (this.scoundrelClient) {
42
+ resolve()
43
+ } else {
44
+ this.events.once("scoundrelStarted", () => {
45
+ resolve()
46
+ })
47
+ }
48
+ })
49
+ }
50
+
51
+ getScoundrel() {
52
+ if (!this.scoundrelClient) {
53
+ throw new Error("Scoundrel client is not started yet")
54
+ }
55
+
56
+ return this.scoundrelClient
23
57
  }
24
58
 
25
59
  connectOnError() {
@@ -83,8 +117,8 @@ export default class SystemTestBrowserHelper {
83
117
  this.overrideConsoleLog()
84
118
  }
85
119
 
86
- getEnabled = () => this._enabled
87
- getEvents = () => this.events
120
+ getEnabled() { return this._enabled }
121
+ getEvents() { return this.events }
88
122
 
89
123
  fakeConsoleError = (...args) => {
90
124
  this.communicator.sendCommand({type: "console.error", value: this.consoleLogMessage(args)})
@@ -63,6 +63,12 @@ export default class SystemTestCommunicator {
63
63
  }
64
64
  }
65
65
 
66
+ /**
67
+ * Sends a command and returns a promise that resolves with the response.
68
+ *
69
+ * @param {Object} data - The command data to send.
70
+ * @returns {Promise} A promise that resolves with the response data.
71
+ */
66
72
  sendCommand(data) {
67
73
  return new Promise((resolve, error) => {
68
74
  const id = this._sendQueueCount
@@ -5,6 +5,8 @@ import fs from "node:fs/promises"
5
5
  import logging from "selenium-webdriver/lib/logging.js"
6
6
  import moment from "moment"
7
7
  import {prettify} from "htmlfy"
8
+ import Server from "scoundrel-remote-eval/src/server/index.js"
9
+ import ServerWebSocket from "scoundrel-remote-eval/src/server/connections/web-socket/index.js"
8
10
  import SystemTestCommunicator from "./system-test-communicator.js"
9
11
  import SystemTestHttpServer from "./system-test-http-server.js"
10
12
  import {wait, waitFor} from "awaitery"
@@ -62,11 +64,24 @@ export default class SystemTest {
62
64
  throw new Error(`Unknown arguments: ${restArgsKeys.join(", ")}`)
63
65
  }
64
66
 
65
- this.communicator = new SystemTestCommunicator({onCommand: this.onCommandReceived})
66
67
  this._host = host
67
68
  this._port = port
68
69
  this._responses = {}
69
70
  this._sendCount = 0
71
+ this.startScoundrel()
72
+ this.communicator = new SystemTestCommunicator({onCommand: this.onCommandReceived})
73
+ }
74
+
75
+ /** Starts Scoundrel server which the browser connects to for remote evaluation in the browser */
76
+ startScoundrel() {
77
+ this.wss = new WebSocketServer({port: 8090})
78
+ this.serverWebSocket = new ServerWebSocket(this.wss)
79
+ this.server = new Server(this.serverWebSocket)
80
+ }
81
+
82
+ stopScoundrel() {
83
+ this.server?.close()
84
+ this.wss?.close()
70
85
  }
71
86
 
72
87
  /**
@@ -494,6 +509,7 @@ export default class SystemTest {
494
509
  * Stops the system test
495
510
  */
496
511
  async stop() {
512
+ this.stopScoundrel()
497
513
  this.systemTestHttpServer?.close()
498
514
  this.wss?.close()
499
515
  await this.driver.quit()