Skip to content

Commit

Permalink
Fix all tests
Browse files Browse the repository at this point in the history
It seems we can't use relative requires in tests anymore. Otherwise Jest becomes confused between real file and symlink.
jestjs/jest#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.
  • Loading branch information
gaearon committed Oct 20, 2017
1 parent cf693f9 commit 911cc16
Show file tree
Hide file tree
Showing 38 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
var React;
var ReactNativeCS;

jest.mock('shared/ReactFeatureFlags', () => require('shared/ReactNativeCSFeatureFlags'));
jest.mock('shared/ReactFeatureFlags', () => require('react-cs-renderer/src/ReactNativeCSFeatureFlags'));

describe('ReactNativeCS', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ describe('ReactBrowserEventEmitter', () => {
EventPluginRegistry = require('shared/event/EventPluginRegistry');
React = require('react');
ReactDOM = require('react-dom');
ReactDOMComponentTree = require('../client/ReactDOMComponentTree');
ReactBrowserEventEmitter = require('../client/event/ReactBrowserEventEmitter');
ReactDOMComponentTree = require('react-dom/src/client/ReactDOMComponentTree');
ReactBrowserEventEmitter = require('react-dom/src/client/event/ReactBrowserEventEmitter');
ReactTestUtils = require('react-dom/test-utils');
TapEventPlugin = require('../client/event/plugins/TapEventPlugin');
TapEventPlugin = require('react-dom/src/client/event/plugins/TapEventPlugin');

var container = document.createElement('div');

Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('ReactDOMComponent', () => {
ReactDOMServer = require('react-dom/server');
ReactTestUtils = require('react-dom/test-utils');
// TODO: can we express this test with only public API?
inputValueTracking = require('../client/inputValueTracking');
inputValueTracking = require('react-dom/src/client/inputValueTracking');
});

describe('updateDOM', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('ReactDOMComponentTree', () => {
React = require('react');
ReactDOM = require('react-dom');
// TODO: can we express this test with only public API?
ReactDOMComponentTree = require('../client/ReactDOMComponentTree');
ReactDOMComponentTree = require('react-dom/src/client/ReactDOMComponentTree');
ReactDOMServer = require('react-dom/server');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ describe('ReactDOMEventListener', () => {
React = require('react');
ReactDOM = require('react-dom');
// TODO: can we express this test with only public API?
ReactDOMComponentTree = require('../client/ReactDOMComponentTree');
ReactDOMEventListener = require('../client/event/ReactDOMEventListener');
ReactDOMComponentTree = require('react-dom/src/client/ReactDOMComponentTree');
ReactDOMEventListener = require('react-dom/src/client/event/ReactDOMEventListener');
ReactTestUtils = require('react-dom/test-utils');

handleTopLevel = jest.fn();
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/__tests__/ReactDOMSelection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('ReactDOMSelection', () => {
beforeEach(() => {
React = require('react');
ReactDOM = require('react-dom');
ReactDOMSelection = require('../client/ReactDOMSelection');
ReactDOMSelection = require('react-dom/src/client/ReactDOMSelection');
invariant = require('fbjs/lib/invariant');

({getModernOffsetsFromPoints} = ReactDOMSelection);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/__tests__/ReactMount-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const {COMMENT_NODE} = require('../shared/HTMLNodeType');
const {COMMENT_NODE} = require('react-dom/src/shared/HTMLNodeType');

const invariant = require('invariant');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('ReactDOMServer', () => {
ExecutionEnvironment.canUseDOM = false;
ReactDOMServer = require('react-dom/server');

var DOMProperty = require('../shared/DOMProperty');
var DOMProperty = require('react-dom/src/shared/DOMProperty');
ROOT_ATTRIBUTE_NAME = DOMProperty.ROOT_ATTRIBUTE_NAME;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

var React = require('react');
// TODO: can we express this test with only public API?
var ReactDOMComponentTree = require('../client/ReactDOMComponentTree');
var ReactDOMComponentTree = require('react-dom/src/client/ReactDOMComponentTree');
var ReactTestUtils = require('react-dom/test-utils');

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

describe('escapeTextContentForBrowser', () => {
// TODO: can we express this test with only public API?
var escapeTextContentForBrowser = require('../shared/escapeTextContentForBrowser');
var escapeTextContentForBrowser = require('react-dom/src/shared/escapeTextContentForBrowser');

it('should escape boolean to string', () => {
expect(escapeTextContentForBrowser(true)).toBe('true');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var React = require('react');
var ReactDOM = require('react-dom');
var ReactTestUtils = require('react-dom/test-utils');
// TODO: can we express this test with only public API?
var inputValueTracking = require('../client/inputValueTracking');
var inputValueTracking = require('react-dom/src/client/inputValueTracking');

var getTracker = inputValueTracking._getTrackerFromNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

describe('quoteAttributeValueForBrowser', () => {
// TODO: can we express this test with only public API?
var quoteAttributeValueForBrowser = require('../shared/quoteAttributeValueForBrowser');
var quoteAttributeValueForBrowser = require('react-dom/src/shared/quoteAttributeValueForBrowser');

it('should escape boolean to string', () => {
expect(quoteAttributeValueForBrowser(true)).toBe('"true"');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('ReactContextValidator', () => {
jest.resetModules();

// TODO: can we express this test with only public API?
validateDOMNesting = require('../client/validateDOMNesting');
validateDOMNesting = require('react-dom/src/client/validateDOMNesting');
});

it('allows any tag with no context', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

// TODO: can we express this test with only public API?
var getNodeForCharacterOffset = require('../getNodeForCharacterOffset');
var getNodeForCharacterOffset = require('react-dom/src/client/getNodeForCharacterOffset');

// Create node from HTML string
function createNode(html) {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/client/__tests__/setInnerHTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
'use strict';

// TODO: can we express this test with only public API?
var setInnerHTML = require('../setInnerHTML');
var Namespaces = require('../../shared/DOMNamespaces').Namespaces;
var setInnerHTML = require('react-dom/src/client/setInnerHTML');
var Namespaces = require('react-dom/src/shared/DOMNamespaces').Namespaces;

describe('setInnerHTML', () => {
describe('when the node has innerHTML property', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ describe('SyntheticClipboardEvent', () => {

beforeEach(() => {
// TODO: can we express this test with only public API?
SyntheticClipboardEvent = require('../SyntheticClipboardEvent');
SyntheticClipboardEvent = require('react-dom/src/client/event/SyntheticClipboardEvent');
createEvent = function(nativeEvent) {
var target = require('../getEventTarget')(nativeEvent);
var target = require('react-dom/src/client/event/getEventTarget')(nativeEvent);
return SyntheticClipboardEvent.getPooled({}, '', nativeEvent, target);
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('SyntheticEvent', () => {
ReactTestUtils = require('react-dom/test-utils');

createEvent = function(nativeEvent) {
var target = require('../getEventTarget')(nativeEvent);
var target = require('react-dom/src/client/event/getEventTarget')(nativeEvent);
return SyntheticEvent.getPooled({}, '', nativeEvent, target);
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ describe('SyntheticKeyboardEvent', () => {

beforeEach(() => {
// Mock getEventCharCode for proper unit testing
jest.mock('../getEventCharCode');
getEventCharCode = require('../getEventCharCode');
jest.mock('react-dom/src/client/event/getEventCharCode');
getEventCharCode = require('react-dom/src/client/event/getEventCharCode');

// TODO: can we express this test with only public API?
SyntheticKeyboardEvent = require('../SyntheticKeyboardEvent');
SyntheticKeyboardEvent = require('react-dom/src/client/event/SyntheticKeyboardEvent');
createEvent = function(nativeEvent) {
var target = require('../getEventTarget')(nativeEvent);
var target = require('react-dom/src/client/event/getEventTarget')(nativeEvent);
return SyntheticKeyboardEvent.getPooled({}, '', nativeEvent, target);
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ describe('SyntheticWheelEvent', () => {

beforeEach(() => {
// TODO: can we express this test with only public API?
SyntheticWheelEvent = require('../SyntheticWheelEvent');
SyntheticWheelEvent = require('react-dom/src/client/event/SyntheticWheelEvent');

createEvent = function(nativeEvent) {
var target = require('../getEventTarget')(nativeEvent);
var target = require('react-dom/src/client/event/getEventTarget')(nativeEvent);
return SyntheticWheelEvent.getPooled({}, '', nativeEvent, target);
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

// TODO: can we express this test with only public API?
var getEventCharCode = require('../getEventCharCode');
var getEventCharCode = require('react-dom/src/client/event/getEventCharCode');

describe('getEventCharCode', () => {
describe('when charCode is present in nativeEvent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

// TODO: can we express this test with only public API?
var getEventKey = require('../getEventKey');
var getEventKey = require('react-dom/src/client/event/getEventKey');

describe('getEventKey', () => {
describe('when key is implemented in a browser', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ describe('BeforeInputEventPlugin', function() {
this.ReactDOM = require('react-dom');

// TODO: can we express this test with only public API?
this.ReactDOMComponentTree = require('../../../ReactDOMComponentTree');
this.SyntheticCompositionEvent = require('../../SyntheticCompositionEvent');
this.SyntheticInputEvent = require('../../SyntheticInputEvent');
this.BeforeInputEventPlugin = require('../BeforeInputEventPlugin');
this.ReactDOMComponentTree = require('react-dom/src/client/ReactDOMComponentTree');
this.SyntheticCompositionEvent = require('react-dom/src/client/event/SyntheticCompositionEvent');
this.SyntheticInputEvent = require('react-dom/src/client/event/SyntheticInputEvent');
this.BeforeInputEventPlugin = require('react-dom/src/client/event/plugins/BeforeInputEventPlugin');
}

function extract(node, eventType, optionalData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ var React = require('react');
var ReactDOM = require('react-dom');
var ReactTestUtils = require('react-dom/test-utils');
// TODO: can we express this test with only public API?
var ChangeEventPlugin = require('../ChangeEventPlugin');
var inputValueTracking = require('../../../inputValueTracking');
var ChangeEventPlugin = require('react-dom/src/client/event/plugins/ChangeEventPlugin');
var inputValueTracking = require('react-dom/src/client/inputValueTracking');

function getTrackedValue(elem) {
var tracker = inputValueTracking._getTrackerFromNode(elem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ describe('EnterLeaveEventPlugin', () => {
ReactDOM = require('react-dom');
ReactTestUtils = require('react-dom/test-utils');
// TODO: can we express this test with only public API?
ReactDOMComponentTree = require('../../../ReactDOMComponentTree');
EnterLeaveEventPlugin = require('../EnterLeaveEventPlugin');
ReactDOMComponentTree = require('react-dom/src/client/ReactDOMComponentTree');
EnterLeaveEventPlugin = require('react-dom/src/client/event/plugins/EnterLeaveEventPlugin');
});

it('should set relatedTarget properly in iframe', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('FallbackCompositionState', () => {

beforeEach(() => {
// TODO: can we express this test with only public API?
FallbackCompositionState = require('../FallbackCompositionState');
FallbackCompositionState = require('react-dom/src/client/event/plugins/FallbackCompositionState');
});

function getInput() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ describe('SelectEventPlugin', () => {
ReactDOM = require('react-dom');
ReactTestUtils = require('react-dom/test-utils');
// TODO: can we express this test with only public API?
ReactDOMComponentTree = require('../../../ReactDOMComponentTree');
SelectEventPlugin = require('../SelectEventPlugin');
ReactDOMComponentTree = require('react-dom/src/client/ReactDOMComponentTree');
SelectEventPlugin = require('react-dom/src/client/event/plugins/SelectEventPlugin');
});

it('should skip extraction if no listeners are present', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const findNumericNodeHandle = require('./findNumericNodeHandle');
import type {ReactNativeType} from 'ReactNativeTypes';
import type {ReactNodeList} from 'ReactTypes';

require('ReactNativeInjection');
require('./ReactNativeInjection');

ReactGenericBatching.injection.injectFiberBatchedUpdates(
ReactNativeFiberRenderer.batchedUpdates,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
'use strict';

var ReactNativeAttributePayload = require('../ReactNativeAttributePayload');
var ReactNativePropRegistry = require('../ReactNativePropRegistry');
var ReactNativeAttributePayload = require('react-native-renderer/src/ReactNativeAttributePayload');
var ReactNativePropRegistry = require('react-native-renderer/src/ReactNativePropRegistry');

var diff = ReactNativeAttributePayload.diff;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ beforeEach(() => {
RCTEventEmitter = require('RCTEventEmitter');
React = require('react');
ReactNative = require('react-native-renderer');
ReactNativeBridgeEventPlugin = require('../ReactNativeBridgeEventPlugin');
ReactNativeBridgeEventPlugin = require('react-native-renderer/src/ReactNativeBridgeEventPlugin');
ResponderEventPlugin = require('shared/event/plugins/ResponderEventPlugin');
UIManager = require('UIManager');
createReactNativeComponentClass = require('../createReactNativeComponentClass');
createReactNativeComponentClass = require('react-native-renderer/src/createReactNativeComponentClass');
});

it('fails if unknown/unsupported event types are dispatched', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('ReactNative', () => {
React = require('react');
ReactNative = require('react-native-renderer');
UIManager = require('UIManager');
createReactNativeComponentClass = require('../createReactNativeComponentClass');
createReactNativeComponentClass = require('react-native-renderer/src/createReactNativeComponentClass');
});

it('should be able to create and render a native component', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('createReactNativeComponentClass', () => {
beforeEach(() => {
jest.resetModules();

createReactNativeComponentClass = require('../createReactNativeComponentClass');
createReactNativeComponentClass = require('react-native-renderer/src/createReactNativeComponentClass');
React = require('react');
ReactNative = require('react-native-renderer');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ describe('ReactDebugFiberPerf', () => {
React = require('react');
ReactNoop = require('react-noop-renderer');
// TODO: can we express this test with only public API?
ReactCoroutine = require('../isomorphic/ReactCoroutine');
ReactPortal = require('../isomorphic/ReactPortal');
ReactCoroutine = require('react-reconciler/src/isomorphic/ReactCoroutine');
ReactPortal = require('react-reconciler/src/isomorphic/ReactPortal');
PropTypes = require('prop-types');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('ReactPersistent', () => {

React = require('react');
ReactNoop = require('react-noop-renderer');
ReactPortal = require('../isomorphic/ReactPortal');
ReactPortal = require('react-reconciler/src/isomorphic/ReactPortal');
});

const DEFAULT_ROOT_ID = 'persistent-test';
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/__tests__/ReactErrorUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var ReactErrorUtils;
describe('ReactErrorUtils', () => {
beforeEach(() => {
// TODO: can we express this test with only public API?
ReactErrorUtils = require('../ReactErrorUtils');
ReactErrorUtils = require('shared/ReactErrorUtils');
});

// Run tests in both DEV and production
Expand All @@ -36,7 +36,7 @@ describe('ReactErrorUtils', () => {
};

jest.resetModules();
ReactErrorUtils = require('../ReactErrorUtils');
ReactErrorUtils = require('shared/ReactErrorUtils');
});

afterEach(() => {
Expand Down Expand Up @@ -161,9 +161,9 @@ describe('ReactErrorUtils', () => {
});

it('handles nested errors in separate renderers', () => {
const ReactErrorUtils1 = require('../ReactErrorUtils');
const ReactErrorUtils1 = require('shared/ReactErrorUtils');
jest.resetModules();
const ReactErrorUtils2 = require('../ReactErrorUtils');
const ReactErrorUtils2 = require('shared/ReactErrorUtils');
expect(ReactErrorUtils1).not.toEqual(ReactErrorUtils2);

let ops = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/__tests__/reactProdInvariant-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var reactProdInvariant;
describe('reactProdInvariant', () => {
beforeEach(() => {
jest.resetModules();
reactProdInvariant = require('../reactProdInvariant');
reactProdInvariant = require('shared/reactProdInvariant');
});

it('should throw with the correct number of `%s`s in the URL', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('EventPluginRegistry', () => {
beforeEach(() => {
jest.resetModuleRegistry();
// TODO: can we express this test with only public API?
EventPluginRegistry = require('../EventPluginRegistry');
EventPluginRegistry = require('shared/event/EventPluginRegistry');

createPlugin = function(properties) {
return Object.assign({extractEvents: function() {}}, properties);
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/event/__tests__/accumulateInto-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var accumulateInto;

describe('accumulateInto', () => {
beforeEach(() => {
accumulateInto = require('../accumulateInto');
accumulateInto = require('shared/event/accumulateInto');
});

it('throws if the second item is null', () => {
Expand Down
Loading

0 comments on commit 911cc16

Please sign in to comment.