Skip to content

Commit 2b8f1d7

Browse files
authored
Rewrite the browser/connection/remotes-queue.js file to TypeScript (DevExpress#4607)
* rewrite browser/connection/remotes-queue.js to TypeScript * fix test
1 parent a1387db commit 2b8f1d7

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

Diff for: @types/time-limit-promise/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module 'time-limit-promise' {
2+
export default function (promise: Promise<any>, timeout: number, options?: { resolveWith: any, rejectWith: any }): Promise<any>;
3+
}

Diff for: src/browser/connection/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default class BrowserConnection extends EventEmitter {
5656
private opened: boolean;
5757
private heartbeatTimeout: NodeJS.Timeout | null;
5858
private pendingTestRunUrl: string | null;
59-
private readonly url: string;
59+
public readonly url: string;
6060
public readonly idleUrl: string;
6161
private forcedIdleUrl: string;
6262
private readonly initScriptUrl: string;

Diff for: src/browser/connection/remotes-queue.js renamed to src/browser/connection/remotes-queue.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
import { EventEmitter } from 'events';
22
import promisifyEvent from 'promisify-event';
33
import getTimeLimitedPromise from 'time-limit-promise';
4-
4+
import { Dictionary } from '../../configuration/interfaces';
5+
import BrowserConnection from './index';
56

67
const REMOTE_REDIRECT_TIMEOUT = 10000;
78
const ADDING_CONNECTION_WAITING_TIMEOUT = 10000;
89

10+
interface PendingConnection {
11+
connection: BrowserConnection;
12+
readyPromise: Promise<void>;
13+
}
14+
915
export default class RemotesQueue {
10-
constructor () {
16+
private readonly events: EventEmitter;
17+
private shiftingTimeout: Promise<void>;
18+
private readonly pendingConnections: Dictionary<PendingConnection>;
19+
20+
public constructor () {
1121
this.events = new EventEmitter();
1222
this.shiftingTimeout = Promise.resolve();
1323
this.pendingConnections = {};
1424
}
1525

16-
add (remoteConnection) {
26+
public add (remoteConnection: BrowserConnection): void {
1727
const connectionReadyPromise = promisifyEvent(remoteConnection, 'ready')
1828
.then(() => this.remove(remoteConnection));
1929

@@ -25,11 +35,11 @@ export default class RemotesQueue {
2535
this.events.emit('connection-added', remoteConnection.id);
2636
}
2737

28-
remove (remoteConnection) {
38+
public remove (remoteConnection: BrowserConnection): void {
2939
delete this.pendingConnections[remoteConnection.id];
3040
}
3141

32-
shift () {
42+
public shift (): Promise<BrowserConnection | null> {
3343
const shiftingPromise = this.shiftingTimeout
3444
.then(async () => {
3545
let headId = Object.keys(this.pendingConnections)[0];

Diff for: test/server/util-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ describe('Utils', () => {
7272
expected: {
7373
name: 'Other',
7474
version: '0.0',
75-
platform: 'desktop',
76-
os: { name: 'Windows', version: '0.0' },
75+
platform: 'other',
76+
os: { name: 'Other', version: '0.0' },
7777
engine: { name: 'Other', version: '0.0' },
78-
prettyUserAgent: 'Other 0.0 / Windows 0.0',
78+
prettyUserAgent: 'Other 0.0 / Other 0.0',
7979
userAgent: 'Windows'
8080
}
8181
},

0 commit comments

Comments
 (0)