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:
committed by
Facebook Github Bot
parent
abb2dc72ee
commit
74004b6338
@@ -1 +1,3 @@
|
|||||||
{}
|
{
|
||||||
|
"ignore_dirs": ["node_modules", "build", "dist"]
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ const util = require('util');
|
|||||||
const glob = util.promisify(require('glob'));
|
const glob = util.promisify(require('glob'));
|
||||||
const exec = util.promisify(require('child_process').exec);
|
const exec = util.promisify(require('child_process').exec);
|
||||||
const PACKAGES = [
|
const PACKAGES = [
|
||||||
|
'headless-tests',
|
||||||
'static',
|
'static',
|
||||||
'src/plugins/*',
|
'src/plugins/*',
|
||||||
'src/fb/plugins/*',
|
'src/fb/plugins/*',
|
||||||
|
|||||||
@@ -12,3 +12,8 @@ import {FlipperPlugin} from 'flipper';
|
|||||||
export default class extends FlipperPlugin {
|
export default class extends FlipperPlugin {
|
||||||
static id = 'Static ID';
|
static id = 'Static ID';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test('TestPlugin', () => {
|
||||||
|
// supress jest warning
|
||||||
|
expect(true).toBeTruthy();
|
||||||
|
});
|
||||||
|
|||||||
@@ -32,7 +32,10 @@ import JSDevice from './devices/JSDevice';
|
|||||||
import {WebsocketClientFlipperConnection} from './utils/js-client/websocketClientFlipperConnection';
|
import {WebsocketClientFlipperConnection} from './utils/js-client/websocketClientFlipperConnection';
|
||||||
import querystring from 'querystring';
|
import querystring from 'querystring';
|
||||||
import {IncomingMessage} from 'http';
|
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 = {
|
type ClientInfo = {
|
||||||
connection: FlipperClientConnection<any, any> | null | undefined;
|
connection: FlipperClientConnection<any, any> | null | undefined;
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ const _isProduction = !/node_modules[\\/]electron[\\/]/.test(
|
|||||||
process.execPath || electron.remote.process.execPath,
|
process.execPath || electron.remote.process.execPath,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const _isTest = !!process.env.JEST_WORKER_ID;
|
||||||
|
|
||||||
export default function isProduction(): boolean {
|
export default function isProduction(): boolean {
|
||||||
return _isProduction;
|
return _isProduction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isTest(): boolean {
|
||||||
|
return _isTest;
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,13 +7,4 @@
|
|||||||
* @format
|
* @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');
|
global.fetch = require('jest-fetch-mock');
|
||||||
|
|||||||
Reference in New Issue
Block a user