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:
committed by
Facebook Github Bot
parent
8c4e5ec647
commit
5aefb989e0
@@ -35,6 +35,7 @@ matrix:
|
||||
- yarn
|
||||
|
||||
script:
|
||||
- yarn test
|
||||
- yarn lint
|
||||
- yarn build --mac --version=$TRAVIS_BUILD_NUMBER
|
||||
|
||||
|
||||
@@ -27,9 +27,7 @@
|
||||
"jest": {
|
||||
"transform": {
|
||||
"\\.(js)$": "<rootDir>/static/transforms/index.js"
|
||||
},
|
||||
"runner": "@jest-runner/electron",
|
||||
"testEnvironment": "@jest-runner/electron/environment"
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jest-runner/electron": "^0.0.8",
|
||||
@@ -102,7 +100,8 @@
|
||||
"start": "cross-env NODE_ENV=development node scripts/start-dev-server.js",
|
||||
"build": "yarn rm-dist && cross-env NODE_ENV=production node scripts/build-release.js $@",
|
||||
"fix": "eslint . --fix",
|
||||
"test": "jest",
|
||||
"test": "jest --testPathPattern=node\\.js$",
|
||||
"test-electron": "jest --testPathPattern=electron\\.js$ --testEnvironment=@jest-runner/electron/environment --runner=@jest-runner/electron",
|
||||
"lint": "eslint . && flow check"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
export default function init() {
|
||||
// no-op
|
||||
}
|
||||
@@ -16,8 +16,6 @@ import BugReporter from '../fb-stubs/BugReporter.js';
|
||||
// create redux store with initial state
|
||||
const mockStore = configureStore([])(reducers(undefined, {type: 'INIT'}));
|
||||
|
||||
beforeEach(() => {});
|
||||
|
||||
test('Empty app state matches snapshot', () => {
|
||||
const logger = new Logger();
|
||||
const bugReporter = new BugReporter(logger);
|
||||
@@ -88,9 +88,9 @@ exports[`Empty app state matches snapshot 1`] = `
|
||||
title="Toggle Plugins"
|
||||
>
|
||||
<div
|
||||
className="css-1pfn0zl"
|
||||
className="css-1221zh3"
|
||||
color="#80a6f5"
|
||||
size={20}
|
||||
size={12}
|
||||
src="icons/sidebar_left.svg"
|
||||
/>
|
||||
</div>
|
||||
@@ -103,9 +103,9 @@ exports[`Empty app state matches snapshot 1`] = `
|
||||
title="Toggle Details"
|
||||
>
|
||||
<div
|
||||
className="css-13cmaba"
|
||||
className="css-1fkfe9s"
|
||||
color="#acacac"
|
||||
size={20}
|
||||
size={12}
|
||||
src="icons/sidebar_right.svg"
|
||||
/>
|
||||
</div>
|
||||
@@ -5,14 +5,21 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type Client from '../Client';
|
||||
|
||||
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());
|
||||
});
|
||||
|
||||
@@ -21,7 +28,7 @@ test('servers starting at ports', done => {
|
||||
|
||||
server.addListener('listening', port => {
|
||||
if (!serversToBeStarted.has(port)) {
|
||||
throw Error(`unknown server started at port ${port}`);
|
||||
done.fail(Error(`unknown server started at port ${port}`));
|
||||
} else {
|
||||
serversToBeStarted.delete(port);
|
||||
}
|
||||
@@ -31,16 +38,6 @@ test('servers starting at ports', done => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Layout plugin is connecting', done => {
|
||||
server.addListener('new-client', (client: Client) => {
|
||||
if (client.plugins.indexOf('Inspector -') === -1) {
|
||||
done.fail(new Error('Layout inspector plugin not found'));
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
server.close();
|
||||
});
|
||||
Reference in New Issue
Block a user