Move tests to internal repo
Summary: Some of the tests need to mock behavior of fb-internal dependencies. These fb deps get swapped out with a babel transform and it's become hard to maintain now that we're mocking them as well. For simplicity of mocking, moving them out of the public repo, they'll get run on PRs. Reviewed By: priteshrnandgaonkar Differential Revision: D18086247 fbshipit-source-id: 001e258e00da67a112cb754e851253e5480e578a
This commit is contained in:
committed by
Facebook Github Bot
parent
f6dc82f2af
commit
2cd6be2d0f
@@ -1,84 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
jest.mock('../fb-stubs/Logger');
|
||||
try {
|
||||
jest.mock('../fb/Logger');
|
||||
} catch {
|
||||
// Allowed to fail when fb modules are not present.
|
||||
}
|
||||
|
||||
import Server from '../server';
|
||||
import {init as initLogger} from '../fb-stubs/Logger';
|
||||
import reducers, {Store} from '../reducers/index';
|
||||
import {createStore} from 'redux';
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
import fs from 'fs';
|
||||
import androidDevice from '../dispatcher/androidDevice';
|
||||
import iosDevice from '../dispatcher/iOSDevice';
|
||||
import Client from '../Client';
|
||||
import {BaseDevice} from 'flipper';
|
||||
|
||||
let server: Server;
|
||||
let androidCleanup: () => Promise<void>;
|
||||
const store: Store = createStore(reducers);
|
||||
|
||||
beforeAll(() => {
|
||||
// create config directory, which is usually created by static/index.js
|
||||
const flipperDir = path.join(os.homedir(), '.flipper');
|
||||
if (!fs.existsSync(flipperDir)) {
|
||||
fs.mkdirSync(flipperDir);
|
||||
}
|
||||
|
||||
const logger = initLogger(store);
|
||||
|
||||
androidCleanup = androidDevice(store, logger);
|
||||
iosDevice(store, logger);
|
||||
|
||||
server = new Server(logger, store);
|
||||
return server.init();
|
||||
});
|
||||
|
||||
test('Device can connect successfully', done => {
|
||||
let testFinished = false;
|
||||
let disconnectedTooEarly = false;
|
||||
const registeredClients: Client[] = [];
|
||||
server.addListener('new-client', (client: Client) => {
|
||||
// Check there is a connected device that has the same device_id as the new client
|
||||
const deviceId = client.query.device_id;
|
||||
expect(deviceId).toBeTruthy();
|
||||
const devices = store.getState().connections.devices;
|
||||
expect(devices.map((device: BaseDevice) => device.serial)).toContain(
|
||||
deviceId,
|
||||
);
|
||||
|
||||
// Make sure it only connects once
|
||||
registeredClients.push(client);
|
||||
expect(registeredClients).toHaveLength(1);
|
||||
|
||||
// Make sure client stays connected for some time before passing test
|
||||
setTimeout(() => {
|
||||
testFinished = true;
|
||||
expect(disconnectedTooEarly).toBe(false);
|
||||
done();
|
||||
}, 5000);
|
||||
});
|
||||
server.addListener('removed-client', (_id: string) => {
|
||||
if (!testFinished) {
|
||||
disconnectedTooEarly = true;
|
||||
}
|
||||
});
|
||||
}, 20000);
|
||||
|
||||
afterAll(() =>
|
||||
androidCleanup().then(() => {
|
||||
server.close();
|
||||
}),
|
||||
);
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
jest.mock('../fb/Logger');
|
||||
try {
|
||||
jest.mock('../fb/Logger');
|
||||
} catch {
|
||||
// Allowed to fail when fb modules are not present.
|
||||
}
|
||||
|
||||
import {init as initLogger} from '../fb-stubs/Logger';
|
||||
import Server from '../server';
|
||||
import reducers, {Store} from '../reducers/index';
|
||||
import configureStore from 'redux-mock-store';
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
import fs from 'fs';
|
||||
|
||||
let server: Server | null = null;
|
||||
const mockStore: Store = configureStore([])(
|
||||
reducers(undefined, {type: 'INIT'}),
|
||||
) as Store;
|
||||
|
||||
beforeAll(() => {
|
||||
// create config directory, which is usually created by static/index.js
|
||||
const flipperDir = path.join(os.homedir(), '.flipper');
|
||||
if (!fs.existsSync(flipperDir)) {
|
||||
fs.mkdirSync(flipperDir);
|
||||
}
|
||||
|
||||
const logger = initLogger(mockStore);
|
||||
server = new Server(logger, mockStore);
|
||||
});
|
||||
|
||||
test('servers starting at ports', done => {
|
||||
const ports = mockStore.getState().application.serverPorts;
|
||||
const serversToBeStarted = new Set([ports.secure, ports.insecure]);
|
||||
|
||||
// Resolve promise when we get a listen event for each port
|
||||
const listenerPromise = new Promise((resolve, reject) => {
|
||||
server!.addListener('listening', port => {
|
||||
if (!serversToBeStarted.has(port)) {
|
||||
throw Error(`unknown server started at port ${port}`);
|
||||
} else {
|
||||
serversToBeStarted.delete(port);
|
||||
}
|
||||
if (serversToBeStarted.size === 0) {
|
||||
done();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Initialise server after the listeners have been setup
|
||||
server!.init();
|
||||
|
||||
return listenerPromise;
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
return server!.close();
|
||||
});
|
||||
@@ -1,59 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
jest.mock('../../fb-stubs/Logger');
|
||||
try {
|
||||
jest.mock('../../fb/Logger');
|
||||
} catch {
|
||||
// Allowed to fail when fb modules are not present.
|
||||
}
|
||||
|
||||
import {default as PluginInstaller, PluginDefinition} from '../PluginInstaller';
|
||||
|
||||
import React from 'react';
|
||||
import {render, waitForElement} from '@testing-library/react';
|
||||
import configureStore from 'redux-mock-store';
|
||||
|
||||
const mockStore = configureStore([])({application: {sessionId: 'mysession'}});
|
||||
import {Provider} from 'react-redux';
|
||||
|
||||
const SEARCH_RESULTS = ({
|
||||
hits: [
|
||||
{name: 'flipper-plugin-hello', version: '0.1.0', description: 'World?'},
|
||||
{name: 'flipper-plugin-world', version: '0.2.0', description: 'Hello?'},
|
||||
],
|
||||
} as unknown) as algoliasearch.Response<any>;
|
||||
|
||||
// *Very* incomplete mock, but that's all we use.
|
||||
const indexMock: algoliasearch.Index = ({
|
||||
search: jest.fn(),
|
||||
} as unknown) as algoliasearch.Index;
|
||||
|
||||
beforeEach(() => {
|
||||
indexMock.search = jest.fn(async () => SEARCH_RESULTS);
|
||||
});
|
||||
|
||||
test('load PluginInstaller list', async () => {
|
||||
const component = (
|
||||
<Provider store={mockStore}>
|
||||
<PluginInstaller
|
||||
getInstalledPlugins={async () => new Map<string, PluginDefinition>()}
|
||||
searchIndexFactory={() => indexMock}
|
||||
// Bit ugly to have this as an effectively test-only option, but
|
||||
// without, we rely on height information from Electron which we don't
|
||||
// have, causing no items to be rendered.
|
||||
autoHeight={true}
|
||||
/>
|
||||
</Provider>
|
||||
);
|
||||
const {container, getByText} = render(component);
|
||||
await waitForElement(() => getByText('flipper-plugin-hello'));
|
||||
expect((indexMock.search as jest.Mock).mock.calls.length).toBe(2);
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
@@ -1,238 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`load PluginInstaller list 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="css-1nm3y77"
|
||||
>
|
||||
<div
|
||||
class="css-4zga7z"
|
||||
>
|
||||
<div
|
||||
class="css-e0frhe"
|
||||
>
|
||||
<input
|
||||
class="css-ww9vf1"
|
||||
placeholder="Search Flipper plugins..."
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="css-1nekdsz"
|
||||
>
|
||||
<div
|
||||
class="css-1k4677w"
|
||||
>
|
||||
<div
|
||||
class="css-vd30c4"
|
||||
>
|
||||
<div
|
||||
class="css-1vb6sy6"
|
||||
title="name"
|
||||
width="25%"
|
||||
>
|
||||
<div
|
||||
class="css-glr1wj"
|
||||
style="z-index: auto; right: 0px; bottom: 0px; width: 100%; height: 100%;"
|
||||
>
|
||||
<div
|
||||
class="css-1db3q1"
|
||||
>
|
||||
Name
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="css-1xchw24"
|
||||
title="version"
|
||||
width="10%"
|
||||
>
|
||||
<div
|
||||
class="css-glr1wj"
|
||||
style="z-index: auto; right: 0px; bottom: 0px; width: 100%; height: 100%;"
|
||||
>
|
||||
<div
|
||||
class="css-1db3q1"
|
||||
>
|
||||
Version
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="css-173sh01"
|
||||
title="description"
|
||||
width="flex"
|
||||
>
|
||||
<div
|
||||
class="css-glr1wj"
|
||||
style="z-index: auto; right: 0px; bottom: 0px; width: 100%; height: 100%;"
|
||||
>
|
||||
<div
|
||||
class="css-1db3q1"
|
||||
>
|
||||
Description
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="css-f0p3z5"
|
||||
title="install"
|
||||
width="15%"
|
||||
>
|
||||
<div
|
||||
class="css-glr1wj"
|
||||
style="z-index: auto; right: 0px; bottom: 0px; width: 100%; height: 100%;"
|
||||
>
|
||||
<div
|
||||
class="css-1db3q1"
|
||||
>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="css-1nekdsz"
|
||||
>
|
||||
<div
|
||||
class="css-1jjayz9"
|
||||
data-key="flipper-plugin-hello"
|
||||
>
|
||||
<div
|
||||
class="css-1jes4os"
|
||||
title=""
|
||||
width="25%"
|
||||
>
|
||||
<span
|
||||
class="css-1pso8q0"
|
||||
>
|
||||
flipper-plugin-hello
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="css-1kkefm9"
|
||||
title=""
|
||||
width="10%"
|
||||
>
|
||||
<span
|
||||
class="css-1pso8q0"
|
||||
>
|
||||
0.1.0
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="css-v10b1x"
|
||||
title=""
|
||||
width="flex"
|
||||
>
|
||||
<div
|
||||
class="css-9qtipk"
|
||||
>
|
||||
<span
|
||||
class="css-1pso8q0"
|
||||
>
|
||||
World?
|
||||
</span>
|
||||
<div
|
||||
class="css-12zzrdt"
|
||||
/>
|
||||
<span
|
||||
class="css-1b8mb9l"
|
||||
>
|
||||
<div
|
||||
class="css-1fev88q"
|
||||
color="#bec2c9"
|
||||
size="16"
|
||||
src="https://external.xx.fbcdn.net/assets/?name=info-circle&variant=filled&size=16&set=facebook_icons&density=1x"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="css-yt1ntn"
|
||||
title=""
|
||||
width="15%"
|
||||
>
|
||||
<div
|
||||
class="css-z1ci4f"
|
||||
type="primary"
|
||||
>
|
||||
Install
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="css-1ut44ht"
|
||||
data-key="flipper-plugin-world"
|
||||
>
|
||||
<div
|
||||
class="css-1jes4os"
|
||||
title=""
|
||||
width="25%"
|
||||
>
|
||||
<span
|
||||
class="css-1pso8q0"
|
||||
>
|
||||
flipper-plugin-world
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="css-1kkefm9"
|
||||
title=""
|
||||
width="10%"
|
||||
>
|
||||
<span
|
||||
class="css-1pso8q0"
|
||||
>
|
||||
0.2.0
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="css-v10b1x"
|
||||
title=""
|
||||
width="flex"
|
||||
>
|
||||
<div
|
||||
class="css-9qtipk"
|
||||
>
|
||||
<span
|
||||
class="css-1pso8q0"
|
||||
>
|
||||
Hello?
|
||||
</span>
|
||||
<div
|
||||
class="css-12zzrdt"
|
||||
/>
|
||||
<span
|
||||
class="css-1b8mb9l"
|
||||
>
|
||||
<div
|
||||
class="css-1fev88q"
|
||||
color="#bec2c9"
|
||||
size="16"
|
||||
src="https://external.xx.fbcdn.net/assets/?name=info-circle&variant=filled&size=16&set=facebook_icons&density=1x"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="css-yt1ntn"
|
||||
title=""
|
||||
width="15%"
|
||||
>
|
||||
<div
|
||||
class="css-z1ci4f"
|
||||
type="primary"
|
||||
>
|
||||
Install
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
Reference in New Issue
Block a user