browserstack-cypress-cli 1.23.1 → 1.24.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.
@@ -0,0 +1,88 @@
1
+ const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder } = require('./constants');
2
+ const { debug, batchAndPostEvents } = require('./helper');
3
+
4
+ class RequestQueueHandler {
5
+ constructor() {
6
+ this.queue = [];
7
+ this.started = false;
8
+ this.eventUrl = 'api/v1/batch';
9
+ this.screenshotEventUrl = 'api/v1/screenshots';
10
+ this.BATCH_EVENT_TYPES = ['LogCreated', 'CBTSessionCreated', 'TestRunFinished', 'TestRunSkipped', 'HookRunFinished', 'TestRunStarted', 'HookRunStarted', 'BuildUpdate'];
11
+ this.pollEventBatchInterval = null;
12
+ }
13
+
14
+ start = () => {
15
+ if(!this.started) {
16
+ this.started = true;
17
+ this.startEventBatchPolling();
18
+ }
19
+ }
20
+
21
+ add = (event) => {
22
+ if(this.BATCH_EVENT_TYPES.includes(event.event_type)) {
23
+ if(event.logs && event.logs[0] && event.logs[0].kind === 'TEST_SCREENSHOT') {
24
+ return {
25
+ shouldProceed: true,
26
+ proceedWithData: [event],
27
+ proceedWithUrl: this.screenshotEventUrl
28
+ }
29
+ }
30
+
31
+ this.queue.push(event);
32
+ let data = null, shouldProceed = this.shouldProceed();
33
+ if(shouldProceed) {
34
+ data = this.queue.slice(0,BATCH_SIZE);
35
+ this.queue.splice(0,BATCH_SIZE);
36
+ this.resetEventBatchPolling();
37
+ }
38
+
39
+ return {
40
+ shouldProceed: shouldProceed,
41
+ proceedWithData: data,
42
+ proceedWithUrl: this.eventUrl
43
+ }
44
+ } else {
45
+ return {
46
+ shouldProceed: true
47
+ }
48
+ }
49
+ }
50
+
51
+ shutdown = async () => {
52
+ this.removeEventBatchPolling('REMOVING');
53
+ while(this.queue.length > 0) {
54
+ const data = this.queue.slice(0,BATCH_SIZE);
55
+ this.queue.splice(0,BATCH_SIZE);
56
+ await batchAndPostEvents(this.eventUrl,'Shutdown-Queue',data);
57
+ }
58
+ }
59
+
60
+ startEventBatchPolling = () => {
61
+ this.pollEventBatchInterval = setInterval(async () => {
62
+ if(this.queue.length > 0) {
63
+ const data = this.queue.slice(0,BATCH_SIZE);
64
+ this.queue.splice(0,BATCH_SIZE);
65
+ await batchAndPostEvents(this.eventUrl,'Interval-Queue',data);
66
+ }
67
+ }, BATCH_INTERVAL);
68
+ }
69
+
70
+ resetEventBatchPolling = () => {
71
+ this.removeEventBatchPolling('RESETTING');
72
+ this.startEventBatchPolling();
73
+ }
74
+
75
+ removeEventBatchPolling = (tag) => {
76
+ if(this.pollEventBatchInterval) {
77
+ clearInterval(this.pollEventBatchInterval);
78
+ this.pollEventBatchInterval = null;
79
+ if(tag === 'REMOVING') this.started = false;
80
+ }
81
+ }
82
+
83
+ shouldProceed = () => {
84
+ return this.queue.length >= BATCH_SIZE;
85
+ }
86
+ }
87
+
88
+ module.exports = RequestQueueHandler;
@@ -0,0 +1,40 @@
1
+ const ipc = require('node-ipc');
2
+ const { connectIPCClient } = require('./ipcClient');
3
+ const { IPC_EVENTS } = require('../helper/constants');
4
+
5
+ const browserstackTestObservabilityPlugin = (on, config, callbacks) => {
6
+ connectIPCClient(config);
7
+
8
+ on('task', {
9
+ test_observability_log(log) {
10
+ ipc.of.browserstackTestObservability.emit(IPC_EVENTS.LOG, log);
11
+ return null;
12
+ },
13
+ test_observability_command(commandObj) {
14
+ ipc.of.browserstackTestObservability.emit(IPC_EVENTS.COMMAND, commandObj);
15
+ return null;
16
+ },
17
+ test_observability_platform_details(platformObj) {
18
+ ipc.of.browserstackTestObservability.emit(IPC_EVENTS.PLATFORM_DETAILS, platformObj);
19
+ return null;
20
+ },
21
+ test_observability_step(log) {
22
+ ipc.of.browserstackTestObservability.emit(IPC_EVENTS.CUCUMBER, log);
23
+ return null;
24
+ }
25
+ });
26
+
27
+ on('after:screenshot', (screenshotInfo) => {
28
+ let logMessage;
29
+ if (callbacks && callbacks.screenshotLogFn && typeof callbacks.screenshotLogFn === 'function') {
30
+ logMessage = callbacks.screenshotLogFn(screenshotInfo);
31
+ }
32
+ ipc.of.browserstackTestObservability.emit(IPC_EVENTS.SCREENSHOT, {
33
+ logMessage,
34
+ screenshotInfo,
35
+ });
36
+ return null;
37
+ });
38
+ };
39
+
40
+ module.exports = browserstackTestObservabilityPlugin;
@@ -0,0 +1,16 @@
1
+ const ipc = require('node-ipc');
2
+ const { IPC_EVENTS } = require('../helper/constants');
3
+
4
+ exports.connectIPCClient = (config) => {
5
+ ipc.config.id = 'browserstackTestObservability';
6
+ ipc.config.retry = 1500;
7
+ ipc.config.silent = true;
8
+
9
+ ipc.connectTo('browserstackTestObservability', () => {
10
+ ipc.of.browserstackTestObservability.on('connect', () => {
11
+ ipc.of.browserstackTestObservability.emit(IPC_EVENTS.CONFIG, config);
12
+ });
13
+ ipc.of.browserstackTestObservability.on('disconnect', () => {
14
+ });
15
+ });
16
+ };
@@ -0,0 +1,34 @@
1
+ const ipc = require('node-ipc');
2
+ const { consoleHolder } = require('../helper/constants');
3
+
4
+ exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => {
5
+ if (ipc.server) {
6
+ unsubscribeServerEvents(ipc.server);
7
+ subscribeServerEvents(ipc.server);
8
+ return;
9
+ }
10
+ ipc.config.id = 'browserstackTestObservability';
11
+ ipc.config.retry = 1500;
12
+ ipc.config.silent = true;
13
+
14
+ ipc.serve(() => {
15
+
16
+ ipc.server.on('socket.disconnected', (socket, destroyedSocketID) => {
17
+ ipc.log(`client ${destroyedSocketID} has disconnected!`);
18
+ });
19
+
20
+ ipc.server.on('destroy', () => {
21
+ ipc.log('server destroyed');
22
+ });
23
+
24
+ subscribeServerEvents(ipc.server);
25
+
26
+ process.on('exit', () => {
27
+ unsubscribeServerEvents(ipc.server);
28
+ ipc.server.stop();
29
+ });
30
+
31
+ });
32
+
33
+ ipc.server.start();
34
+ };