adding jest test setup
Summary: Adds a test runner for jest test and adds three simple test cases: - render the app - start a server - client connecting to the app Test can be run using `yarn test`. To make the test runner work, some changes needed to be made: - remove the export of `init()` from `'flipper'`, because it was a cyclic dependency - updating Button.js to the new ref-API Reviewed By: jknoxville Differential Revision: D10027078 fbshipit-source-id: 49107b0dd4dec666b92ecd841422fe7e6b3a7756
This commit is contained in:
committed by
Facebook Github Bot
parent
af1ff7f039
commit
a455520ecb
@@ -8,11 +8,11 @@
|
||||
const generate = require('@babel/generator').default;
|
||||
const babylon = require('@babel/parser');
|
||||
const babel = require('@babel/core');
|
||||
const metro = require('metro');
|
||||
|
||||
exports.transform = function({filename, options, src}) {
|
||||
function transform({filename, options, src}) {
|
||||
const presets = [require('../node_modules/@babel/preset-react')];
|
||||
const isPlugin = !__dirname.startsWith(options.projectRoot);
|
||||
const isPlugin =
|
||||
options.projectRoot && !__dirname.startsWith(options.projectRoot);
|
||||
|
||||
let ast = babylon.parse(src, {
|
||||
filename,
|
||||
@@ -33,10 +33,18 @@ exports.transform = function({filename, options, src}) {
|
||||
require('../node_modules/@babel/plugin-proposal-class-properties'),
|
||||
require('../node_modules/@babel/plugin-transform-flow-strip-types'),
|
||||
require('../node_modules/@babel/plugin-proposal-optional-chaining'),
|
||||
require('./electron-requires.js'),
|
||||
require('./fb-stubs.js'),
|
||||
require('./dynamic-requires.js'),
|
||||
];
|
||||
|
||||
if (!options.isTestRunner) {
|
||||
// Replacing require statements with electronRequire to prevent metro from
|
||||
// resolving them. electronRequire are resolved during runtime by electron.
|
||||
// As the tests are not bundled by metro and run in @jest-runner/electron,
|
||||
// electron imports are working out of the box.
|
||||
plugins.push(require('./electron-requires.js'));
|
||||
}
|
||||
|
||||
if (isPlugin) {
|
||||
plugins.push(require('./flipper-requires.js'));
|
||||
} else {
|
||||
@@ -64,11 +72,22 @@ exports.transform = function({filename, options, src}) {
|
||||
},
|
||||
src,
|
||||
);
|
||||
|
||||
return {
|
||||
ast,
|
||||
code: result.code,
|
||||
filename,
|
||||
map: result.rawMappings.map(metro.sourceMaps.compactMapping),
|
||||
map: result.map,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
transform,
|
||||
process(src, filename, config, options) {
|
||||
return transform({
|
||||
src,
|
||||
filename,
|
||||
config,
|
||||
options: {...options, isTestRunner: true},
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user