Files
react/scripts/rollup/plugins/__tests__/wrap-warning-with-env-check-test.js
Jack Hou e8e62ebb59 use different eslint config for es6 and es5 (#11794)
* 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
2017-12-11 15:52:46 +00:00

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');"
);
});
});