server.device.tsx

Summary: _typescript_

Reviewed By: jknoxville

Differential Revision: D17284631

fbshipit-source-id: 79d407c6d90b91f16caf226f41c0b4cfbd78fc95
This commit is contained in:
Daniel Büchele
2019-09-11 03:01:18 -07:00
committed by Facebook Github Bot
parent 4fd059f4a1
commit 9aef4f55cf

View File

@@ -7,7 +7,7 @@
import Server from '../server'; import Server from '../server';
import {init as initLogger} from '../fb-stubs/Logger'; import {init as initLogger} from '../fb-stubs/Logger';
import reducers from '../reducers/index'; import reducers, {Store} from '../reducers/index';
import {createStore} from 'redux'; import {createStore} from 'redux';
import path from 'path'; import path from 'path';
import os from 'os'; import os from 'os';
@@ -15,10 +15,11 @@ import fs from 'fs';
import androidDevice from '../dispatcher/androidDevice'; import androidDevice from '../dispatcher/androidDevice';
import iosDevice from '../dispatcher/iOSDevice'; import iosDevice from '../dispatcher/iOSDevice';
import Client from '../Client'; import Client from '../Client';
import {BaseDevice} from 'flipper';
let server; let server: Server;
let androidCleanup; let androidCleanup: () => Promise<void>;
const store = createStore(reducers); const store: Store = createStore(reducers);
beforeAll(() => { beforeAll(() => {
// create config directory, which is usually created by static/index.js // create config directory, which is usually created by static/index.js
@@ -39,13 +40,15 @@ beforeAll(() => {
test('Device can connect successfully', done => { test('Device can connect successfully', done => {
let testFinished = false; let testFinished = false;
let disconnectedTooEarly = false; let disconnectedTooEarly = false;
const registeredClients = []; const registeredClients: Client[] = [];
server.addListener('new-client', (client: Client) => { server.addListener('new-client', (client: Client) => {
// Check there is a connected device that has the same device_id as the new client // Check there is a connected device that has the same device_id as the new client
const deviceId = client.query.device_id; const deviceId = client.query.device_id;
expect(deviceId).toBeTruthy(); expect(deviceId).toBeTruthy();
const devices = store.getState().connections.devices; const devices = store.getState().connections.devices;
expect(devices.map(device => device.serial)).toContain(deviceId); expect(devices.map((device: BaseDevice) => device.serial)).toContain(
deviceId,
);
// Make sure it only connects once // Make sure it only connects once
registeredClients.push(client); registeredClients.push(client);
@@ -58,15 +61,15 @@ test('Device can connect successfully', done => {
done(); done();
}, 5000); }, 5000);
}); });
server.addListener('removed-client', (id: string) => { server.addListener('removed-client', (_id: string) => {
if (!testFinished) { if (!testFinished) {
disconnectedTooEarly = true; disconnectedTooEarly = true;
} }
}); });
}, 20000); }, 20000);
afterAll(() => { afterAll(() =>
return androidCleanup().then(() => { androidCleanup().then(() => {
server.close(); server.close();
}); }),
}); );