run jest tests

Summary:
Adding support for JS testing. Currently there are two environments tests can run in: node and electron. To select which environment to run a test in, name your test file accordingly `*.node.js` or `*.electron.js` and put it in a `__tests__` folder.

- `yarn test` to run node based tests
- `yarn test-electron` to run electron tests

A basic snapshot test of the empty app is added to make sure the app is rendering as expected. A test for the server is added to make sure when Flipper is started the two servers (secure and insecure) are started and ready to accept connections.

Reviewed By: passy

Differential Revision: D10050212

fbshipit-source-id: 8ef7f931339b43251d9d423886bcaca99ae691e4
This commit is contained in:
Daniel Büchele
2018-10-02 04:23:42 -07:00
committed by Facebook Github Bot
parent 8c4e5ec647
commit 5aefb989e0
6 changed files with 18 additions and 33 deletions

View File

@@ -0,0 +1,43 @@
/**
* 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, {SECURE_PORT, INSECURE_PORT} from '../server.js';
import LogManager from '../fb-stubs/Logger';
import path from 'path';
import os from 'os';
import fs from 'fs';
let server;
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());
});
test('servers starting at ports', done => {
const serversToBeStarted = new Set([SECURE_PORT, INSECURE_PORT]);
server.addListener('listening', port => {
if (!serversToBeStarted.has(port)) {
done.fail(Error(`unknown server started at port ${port}`));
} else {
serversToBeStarted.delete(port);
}
if (serversToBeStarted.size === 0) {
done();
}
});
});
afterAll(() => {
server.close();
});