mirror of
https://github.com/facebook/react.git
synced 2026-02-25 05:03:03 +00:00
* use different eslint config for es6 and es5 * remove confusing eslint/baseConfig.js & add more eslint setting for es5, es6 * more clear way to run eslint on es5 & es6 file * seperate ESNext, ES6, ES6 path, and use different lint config * rename eslint config file & update eslint rules * Undo yarn.lock changes * Rename a file * Remove unnecessary exceptions * Refactor a little bit * Refactor and tweak the logic * Minor issues
50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
/**
|
|
* Copyright (c) 2013-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.
|
|
*/
|
|
/* eslint-disable quotes */
|
|
'use strict';
|
|
|
|
let babel = require('babel-core');
|
|
let wrapWarningWithEnvCheck = require('../wrap-warning-with-env-check');
|
|
|
|
function transform(input) {
|
|
return babel.transform(input, {
|
|
plugins: [wrapWarningWithEnvCheck],
|
|
}).code;
|
|
}
|
|
|
|
function compare(input, output) {
|
|
const compiled = transform(input);
|
|
expect(compiled).toEqual(output);
|
|
}
|
|
|
|
let oldEnv;
|
|
|
|
describe('wrap-warning-with-env-check', () => {
|
|
beforeEach(() => {
|
|
oldEnv = process.env.NODE_ENV;
|
|
process.env.NODE_ENV = '';
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env.NODE_ENV = oldEnv;
|
|
});
|
|
|
|
it('should wrap warning calls', () => {
|
|
compare(
|
|
"warning(condition, 'a %s b', 'c');",
|
|
"__DEV__ ? warning(condition, 'a %s b', 'c') : void 0;"
|
|
);
|
|
});
|
|
|
|
it('should not wrap invariant calls', () => {
|
|
compare(
|
|
"invariant(condition, 'a %s b', 'c');",
|
|
"invariant(condition, 'a %s b', 'c');"
|
|
);
|
|
});
|
|
});
|