Improve unit test robustness

Summary: When running tests locally, some are quite flaky, and there is a lot of error logging noise. This diff doesn't remove all of it, but does reduce it significantly.

Reviewed By: nikoant

Differential Revision: D20034619

fbshipit-source-id: 183f74475b644f803b2f92b1b1301f4d0f6e193a
This commit is contained in:
Michel Weststrate
2020-02-25 14:58:00 -08:00
committed by Facebook Github Bot
parent abb2dc72ee
commit 74004b6338
6 changed files with 19 additions and 11 deletions

View File

@@ -1 +1,3 @@
{}
{
"ignore_dirs": ["node_modules", "build", "dist"]
}

View File

@@ -12,6 +12,7 @@ const util = require('util');
const glob = util.promisify(require('glob'));
const exec = util.promisify(require('child_process').exec);
const PACKAGES = [
'headless-tests',
'static',
'src/plugins/*',
'src/fb/plugins/*',

View File

@@ -12,3 +12,8 @@ import {FlipperPlugin} from 'flipper';
export default class extends FlipperPlugin {
static id = 'Static ID';
}
test('TestPlugin', () => {
// supress jest warning
expect(true).toBeTruthy();
});

View File

@@ -32,7 +32,10 @@ import JSDevice from './devices/JSDevice';
import {WebsocketClientFlipperConnection} from './utils/js-client/websocketClientFlipperConnection';
import querystring from 'querystring';
import {IncomingMessage} from 'http';
const ws = window.require('ws'); // Electron tries to get you to use browser's ws instead, so can't use import.
import {isTest} from './utils/isProduction';
// Electron tries to get you to use browser's ws instead, so can't use import.
// @ts-ignore
const ws = isTest() ? require('ws') : window.require('ws');
type ClientInfo = {
connection: FlipperClientConnection<any, any> | null | undefined;

View File

@@ -13,6 +13,12 @@ const _isProduction = !/node_modules[\\/]electron[\\/]/.test(
process.execPath || electron.remote.process.execPath,
);
const _isTest = !!process.env.JEST_WORKER_ID;
export default function isProduction(): boolean {
return _isProduction;
}
export function isTest(): boolean {
return _isTest;
}

View File

@@ -7,13 +7,4 @@
* @format
*/
const defaultConsoleError = console.error;
console.error = function(...args) {
defaultConsoleError(
'console.error used in a test. This will be an error in the near future.',
);
defaultConsoleError(...args);
};
global.fetch = require('jest-fetch-mock');