mirror of
https://github.com/facebook/react.git
synced 2026-02-24 04:33:04 +00:00
* Use relative paths in packages/react * Use relative paths in packages/react-art * Use relative paths in packages/react-cs * Use relative paths in other packages * Fix as many issues as I can This uncovered an interesting problem where ./b from package/src/a would resolve to a different instantiation of package/src/b in Jest. Either this is a showstopper or we can solve it by completely fobbidding remaining /src/. * Fix all tests It seems we can't use relative requires in tests anymore. Otherwise Jest becomes confused between real file and symlink. https://github.com/facebook/jest/issues/3830 This seems bad... Except that we already *don't* want people to create tests that import individual source files. All existing cases of us doing so are actually TODOs waiting to be fixed. So perhaps this requirement isn't too bad because it makes bad code looks bad. Of course, if we go with this, we'll have to lint against relative requires in tests. It also makes moving things more painful. * Prettier * Remove @providesModule * Fix remaining Haste imports I missed earlier * Fix up paths to reflect new flat structure * Fix Flow * Fix CJS and UMD builds * Fix FB bundles * Fix RN bundles * Prettier * Fix lint * Fix warning printing and error codes * Fix buggy return * Fix lint and Flow * Use Yarn on CI * Unbreak Jest * Fix lint * Fix aliased originals getting included in DEV Shouldn't affect correctness (they were ignored) but fixes DEV size regression. * Record sizes * Fix weird version in package.json * Tweak bundle labels * Get rid of output option by introducing react-dom/server.node * Reconciler should depend on prop-types * Update sizes last time
97 lines
2.9 KiB
JavaScript
97 lines
2.9 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 devExpressionWithCodes = require('../replace-invariant-error-codes');
|
|
|
|
function transform(input) {
|
|
return babel.transform(input, {
|
|
plugins: [devExpressionWithCodes],
|
|
}).code;
|
|
}
|
|
|
|
function compare(input, output) {
|
|
var compiled = transform(input);
|
|
expect(compiled).toEqual(output);
|
|
}
|
|
|
|
var oldEnv;
|
|
|
|
describe('dev-expression', () => {
|
|
beforeEach(() => {
|
|
oldEnv = process.env.NODE_ENV;
|
|
process.env.NODE_ENV = '';
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env.NODE_ENV = oldEnv;
|
|
});
|
|
|
|
it("should add `reactProdInvariant` when it finds `require('invariant')`", () => {
|
|
compare(
|
|
"var invariant = require('invariant');",
|
|
`var _prodInvariant = require('shared/reactProdInvariant');
|
|
|
|
var invariant = require('invariant');`
|
|
);
|
|
});
|
|
|
|
it('should replace simple invariant calls', () => {
|
|
compare(
|
|
"invariant(condition, 'Do not override existing functions.');",
|
|
"var _prodInvariant = require('shared/reactProdInvariant');\n\n" +
|
|
'!condition ? ' +
|
|
'__DEV__ ? ' +
|
|
"invariant(false, 'Do not override existing functions.') : " +
|
|
`_prodInvariant('16') : void 0;`
|
|
);
|
|
});
|
|
|
|
it('should only add `reactProdInvariant` once', () => {
|
|
var expectedInvariantTransformResult =
|
|
'!condition ? ' +
|
|
'__DEV__ ? ' +
|
|
"invariant(false, 'Do not override existing functions.') : " +
|
|
`_prodInvariant('16') : void 0;`;
|
|
|
|
compare(
|
|
`var invariant = require('invariant');
|
|
invariant(condition, 'Do not override existing functions.');
|
|
invariant(condition, 'Do not override existing functions.');`,
|
|
`var _prodInvariant = require('shared/reactProdInvariant');
|
|
|
|
var invariant = require('invariant');
|
|
${expectedInvariantTransformResult}
|
|
${expectedInvariantTransformResult}`
|
|
);
|
|
});
|
|
|
|
it('should support invariant calls with args', () => {
|
|
compare(
|
|
"invariant(condition, 'Expected %s target to be an array; got %s', 'foo', 'bar');",
|
|
"var _prodInvariant = require('shared/reactProdInvariant');\n\n" +
|
|
'!condition ? ' +
|
|
'__DEV__ ? ' +
|
|
"invariant(false, 'Expected %s target to be an array; got %s', 'foo', 'bar') : " +
|
|
`_prodInvariant('7', 'foo', 'bar') : void 0;`
|
|
);
|
|
});
|
|
|
|
it('should support invariant calls with a concatenated template string and args', () => {
|
|
compare(
|
|
"invariant(condition, 'Expected a component class, ' + 'got %s.' + '%s', 'Foo', 'Bar');",
|
|
"var _prodInvariant = require('shared/reactProdInvariant');\n\n" +
|
|
'!condition ? ' +
|
|
'__DEV__ ? ' +
|
|
"invariant(false, 'Expected a component class, got %s.%s', 'Foo', 'Bar') : " +
|
|
`_prodInvariant('18', 'Foo', 'Bar') : void 0;`
|
|
);
|
|
});
|
|
});
|