/**
 * Copyright 2018-present Facebook.
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 * @format
 */

import Server from '../server.js';
import LogManager from '../fb-stubs/Logger';
import reducers from '../reducers/index.js';
import configureStore from 'redux-mock-store';
import path from 'path';
import os from 'os';
import fs from 'fs';

let server;
const mockStore = configureStore([])(reducers(undefined, {type: 'INIT'}));

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);
  }

  server = new Server(new LogManager(), mockStore);
  return server.init();
});

test.skip(
  'Device can connect successfully',
  done => {
    var testFinished = false;
    server.addListener('new-client', (client: Client) => {
      console.debug('new-client ' + new Date().toString());
      setTimeout(() => {
        testFinished = true;
        done();
      }, 5000);
    });
    server.addListener('removed-client', (id: string) => {
      console.debug('removed-client ' + new Date().toString());
      if (!testFinished) {
        done.fail('client disconnected too early');
      }
    });
  },
  20000,
);

afterAll(() => {
  return server.close();
});

/**
 * Copyright 2018-present Facebook.
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 * @format
 */

import Server from '../server.js';
import LogManager from '../fb-stubs/Logger';
import reducers from '../reducers/index.js';
import configureStore from 'redux-mock-store';
import path from 'path';
import os from 'os';
import fs from 'fs';

let server;
const mockStore = configureStore([])(reducers(undefined, {type: 'INIT'}));

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);
  }

  server = new Server(new LogManager(), mockStore);
  return server.init();
});

test(
  'Device can connect successfully',
  done => {
    var testFinished = false;
    server.addListener('new-client', (client: Client) => {
      console.debug('new-client ' + new Date().toString());
      setTimeout(() => {
        testFinished = true;
        done();
      }, 5000);
    });
    server.addListener('removed-client', (id: string) => {
      console.debug('removed-client ' + new Date().toString());
      if (!testFinished) {
        done.fail('client disconnected too early');
      }
    });
  },
  20000,
);

afterAll(() => {
  return server.close();
});

Apply oneworld-fix patch before testing connectivity
Apply oneworld-fix patch before testing connectivity

Summary:
Making the runner apply the necessary oneworld fix patch before running the tests.

This can't be a long term solution, but at least means not getting that breaking change landed doesn't stop our tests from running.

Since that change is only necessary for the tests, maybe we'll get away with fixing the update process before having to land it.

Reviewed By: priteshrnandgaonkar

Differential Revision: D10852110

fbshipit-source-id: b53a6d0ae9cb51e62cafc0c0f2cfe359ee6aff46
