metro/packages/metro-babel7-plugin-react-transform/__tests__/babel-plugin-react-transform-test.js
Rafael Oleza a6b61554ec Export the hmr plugin directly
Summary: This will allow to configure the HMR plugin directly from `.babelrc` again, instead of having to create a bridge file: https://github.com/rafeca/metro-sample-app/blob/master/metro-babel7-plugin-react-transform.js#L3

Reviewed By: davidaurelio

Differential Revision: D7707314

fbshipit-source-id: 4c5612e1e5d27874807f2dce50d99ec0f6354bbc
2018-04-20 09:51:16 -07:00

51 lines
1.3 KiB
JavaScript

/**
* Copyright (c) 2004-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails oncall+javascript_foundation
* @flow
* @format
*/
// Note: these tests were updated to snapshots
'use strict';
const fs = require('fs');
const path = require('path');
/*eslint-disable import/no-extraneous-dependencies*/
const {transformSync} = require('@babel/core');
const reactPlugin = require('../lib/index.js');
describe('finds React components', () => {
const fixturesDir = path.join(__dirname, '__fixtures__');
fs.readdirSync(fixturesDir).map(caseName => {
it(`should ${caseName.split('-').join(' ')}`, () => {
const fixtureDir = path.join(fixturesDir, caseName);
const input = fs.readFileSync(
path.join(fixtureDir, 'actual.js.es6'),
'utf8',
);
const config = fs.readFileSync(
path.join(fixtureDir, 'babel.json'),
'utf8',
);
const output = transformSync(input, {
babelrc: false,
plugins: [
[
reactPlugin,
// note: these originate from the .babelrc files from the real tests
JSON.parse(config),
],
],
}).code;
expect(output).toMatchSnapshot();
});
});
});