Moving the jest configuration from jest-react-native to react native.
Reviewed By: cpojer Differential Revision: D3923609 fbshipit-source-id: 62804df81b064871b499ae8c091e13dd1e0f229b
This commit is contained in:
parent
3e332d9cc8
commit
6a462fb085
|
@ -21,7 +21,10 @@ exports[`TouchableHighlight renders correctly 1`] = `
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
testID={undefined}>
|
testID={undefined}>
|
||||||
<Text>
|
<Text
|
||||||
|
accessible={true}
|
||||||
|
allowFontScaling={true}
|
||||||
|
ellipsizeMode="tail">
|
||||||
Touchable
|
Touchable
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the BSD-style license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const React = require('React');
|
|
||||||
const StyleSheetPropType = require('StyleSheetPropType');
|
|
||||||
const ViewStylePropTypes = require('ViewStylePropTypes');
|
|
||||||
|
|
||||||
class View extends React.Component {
|
|
||||||
render() {
|
|
||||||
const {children, ...props} = this.props;
|
|
||||||
return React.createElement('View', props, children);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
View.propTypes = {
|
|
||||||
style: StyleSheetPropType(ViewStylePropTypes),
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = View;
|
|
|
@ -1,26 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the BSD-style license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const ImageResizeMode = require('ImageResizeMode');
|
|
||||||
const React = require('React');
|
|
||||||
const {Component} = React;
|
|
||||||
|
|
||||||
class Image extends Component {
|
|
||||||
static get resizeMode() {
|
|
||||||
return ImageResizeMode;
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
const {children, ...props} = this.props;
|
|
||||||
return React.createElement('Image', props, children);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Image;
|
|
|
@ -8,6 +8,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
jest.unmock('Platform');
|
||||||
|
const Platform = require('Platform');
|
||||||
|
let requestId = 1;
|
||||||
|
|
||||||
|
function setRequestId(id){
|
||||||
|
if (Platform.OS === 'ios') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
requestId = id;
|
||||||
|
}
|
||||||
|
|
||||||
jest
|
jest
|
||||||
.disableAutomock()
|
.disableAutomock()
|
||||||
|
@ -18,11 +28,11 @@ jest
|
||||||
removeListeners: function() {},
|
removeListeners: function() {},
|
||||||
sendRequest(options, callback) {
|
sendRequest(options, callback) {
|
||||||
if (typeof callback === 'function') { // android does not pass a callback
|
if (typeof callback === 'function') { // android does not pass a callback
|
||||||
callback(1);
|
callback(requestId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
abortRequest: function() {},
|
abortRequest: function() {},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const XMLHttpRequest = require('XMLHttpRequest');
|
const XMLHttpRequest = require('XMLHttpRequest');
|
||||||
|
@ -112,15 +122,17 @@ describe('XMLHttpRequest', function() {
|
||||||
|
|
||||||
xhr.open('GET', 'blabla');
|
xhr.open('GET', 'blabla');
|
||||||
xhr.send();
|
xhr.send();
|
||||||
xhr.__didReceiveData(1, 'Some data');
|
setRequestId(2);
|
||||||
|
xhr.__didReceiveData(requestId, 'Some data');
|
||||||
expect(xhr.responseText).toBe('Some data');
|
expect(xhr.responseText).toBe('Some data');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call ontimeout function when the request times out', function() {
|
it('should call ontimeout function when the request times out', function() {
|
||||||
xhr.open('GET', 'blabla');
|
xhr.open('GET', 'blabla');
|
||||||
xhr.send();
|
xhr.send();
|
||||||
xhr.__didCompleteResponse(1, 'Timeout', true);
|
setRequestId(3);
|
||||||
xhr.__didCompleteResponse(1, 'Timeout', true);
|
xhr.__didCompleteResponse(requestId, 'Timeout', true);
|
||||||
|
xhr.__didCompleteResponse(requestId, 'Timeout', true);
|
||||||
|
|
||||||
expect(xhr.readyState).toBe(xhr.DONE);
|
expect(xhr.readyState).toBe(xhr.DONE);
|
||||||
|
|
||||||
|
@ -138,7 +150,8 @@ describe('XMLHttpRequest', function() {
|
||||||
it('should call onerror function when the request times out', function() {
|
it('should call onerror function when the request times out', function() {
|
||||||
xhr.open('GET', 'blabla');
|
xhr.open('GET', 'blabla');
|
||||||
xhr.send();
|
xhr.send();
|
||||||
xhr.__didCompleteResponse(1, 'Generic error');
|
setRequestId(4);
|
||||||
|
xhr.__didCompleteResponse(requestId, 'Generic error');
|
||||||
|
|
||||||
expect(xhr.readyState).toBe(xhr.DONE);
|
expect(xhr.readyState).toBe(xhr.DONE);
|
||||||
|
|
||||||
|
@ -158,7 +171,8 @@ describe('XMLHttpRequest', function() {
|
||||||
it('should call onload function when there is no error', function() {
|
it('should call onload function when there is no error', function() {
|
||||||
xhr.open('GET', 'blabla');
|
xhr.open('GET', 'blabla');
|
||||||
xhr.send();
|
xhr.send();
|
||||||
xhr.__didCompleteResponse(1, null);
|
setRequestId(5);
|
||||||
|
xhr.__didCompleteResponse(requestId, null);
|
||||||
|
|
||||||
expect(xhr.readyState).toBe(xhr.DONE);
|
expect(xhr.readyState).toBe(xhr.DONE);
|
||||||
|
|
||||||
|
@ -182,8 +196,8 @@ describe('XMLHttpRequest', function() {
|
||||||
xhr.upload.onprogress = jest.fn();
|
xhr.upload.onprogress = jest.fn();
|
||||||
var handleProgress = jest.fn();
|
var handleProgress = jest.fn();
|
||||||
xhr.upload.addEventListener('progress', handleProgress);
|
xhr.upload.addEventListener('progress', handleProgress);
|
||||||
|
setRequestId(6);
|
||||||
xhr.__didUploadProgress(1, 42, 100);
|
xhr.__didUploadProgress(requestId, 42, 100);
|
||||||
|
|
||||||
expect(xhr.upload.onprogress.mock.calls.length).toBe(1);
|
expect(xhr.upload.onprogress.mock.calls.length).toBe(1);
|
||||||
expect(handleProgress.mock.calls.length).toBe(1);
|
expect(handleProgress.mock.calls.length).toBe(1);
|
||||||
|
@ -197,7 +211,8 @@ describe('XMLHttpRequest', function() {
|
||||||
it('should combine response headers with CRLF', function() {
|
it('should combine response headers with CRLF', function() {
|
||||||
xhr.open('GET', 'blabla');
|
xhr.open('GET', 'blabla');
|
||||||
xhr.send();
|
xhr.send();
|
||||||
xhr.__didReceiveResponse(1, 200, {
|
setRequestId(7);
|
||||||
|
xhr.__didReceiveResponse(requestId, 200, {
|
||||||
'Content-Type': 'text/plain; charset=utf-8',
|
'Content-Type': 'text/plain; charset=utf-8',
|
||||||
'Content-Length': '32',
|
'Content-Length': '32',
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the BSD-style license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const React = require('React');
|
|
||||||
const {Component} = React;
|
|
||||||
|
|
||||||
const RealText = require.requireActual('Text');
|
|
||||||
|
|
||||||
class Text extends Component {
|
|
||||||
render() {
|
|
||||||
const {children, ...props} = this.props;
|
|
||||||
return React.createElement('Text', props, children);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text.propTypes = RealText.propTypes;
|
|
||||||
|
|
||||||
module.exports = Text;
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2013-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = moduleName => {
|
||||||
|
const RealComponent = require.requireActual(moduleName);
|
||||||
|
const React = require('react');
|
||||||
|
|
||||||
|
const Component = class extends RealComponent {
|
||||||
|
render() {
|
||||||
|
return React.createElement(
|
||||||
|
RealComponent.displayName || RealComponent.name,
|
||||||
|
this.props,
|
||||||
|
this.props.children,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return Component;
|
||||||
|
};
|
|
@ -0,0 +1,160 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2015-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const mockComponent = require.requireActual('./mockComponent');
|
||||||
|
|
||||||
|
require.requireActual('../packager/react-packager/src/Resolver/polyfills/babelHelpers.js');
|
||||||
|
require.requireActual('../packager/react-packager/src/Resolver/polyfills/Object.es7.js');
|
||||||
|
require.requireActual('../packager/react-packager/src/Resolver/polyfills/error-guard');
|
||||||
|
|
||||||
|
global.__DEV__ = true;
|
||||||
|
|
||||||
|
global.Promise = require.requireActual('promise');
|
||||||
|
global.regeneratorRuntime = require.requireActual('regenerator-runtime/runtime');
|
||||||
|
|
||||||
|
jest
|
||||||
|
.mock('npmlog');
|
||||||
|
|
||||||
|
// there's a __mock__ for it.
|
||||||
|
jest.setMock('ErrorUtils', require('ErrorUtils'));
|
||||||
|
|
||||||
|
jest
|
||||||
|
.mock('ReactNativeDefaultInjection')
|
||||||
|
.mock('Image', () => mockComponent('Image'))
|
||||||
|
.mock('Text', () => mockComponent('Text'))
|
||||||
|
.mock('TextInput', () => mockComponent('TextInput'))
|
||||||
|
.mock('Modal', () => mockComponent('Modal'))
|
||||||
|
.mock('View', () => mockComponent('View'))
|
||||||
|
.mock('ScrollView', () => mockComponent('ScrollView'))
|
||||||
|
.mock(
|
||||||
|
'ActivityIndicator',
|
||||||
|
() => mockComponent('ActivityIndicator'),
|
||||||
|
)
|
||||||
|
.mock('ListView', () => {
|
||||||
|
const RealListView = require.requireActual('ListView');
|
||||||
|
const ListView = mockComponent('ListView');
|
||||||
|
ListView.prototype.render = RealListView.prototype.render;
|
||||||
|
return ListView;
|
||||||
|
})
|
||||||
|
.mock('ListViewDataSource', () => {
|
||||||
|
const DataSource = require.requireActual('ListViewDataSource');
|
||||||
|
DataSource.prototype.toJSON = function() {
|
||||||
|
function ListViewDataSource(dataBlob) {
|
||||||
|
this.items = 0;
|
||||||
|
// Ensure this doesn't throw.
|
||||||
|
try {
|
||||||
|
Object.keys(dataBlob).forEach(key => {
|
||||||
|
this.items += dataBlob[key] && dataBlob[key].length;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
this.items = 'unknown';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ListViewDataSource(this._dataBlob);
|
||||||
|
};
|
||||||
|
return DataSource;
|
||||||
|
})
|
||||||
|
.mock('ensureComponentIsNative', () => () => true);
|
||||||
|
|
||||||
|
const mockEmptyObject = {};
|
||||||
|
const mockNativeModules = {
|
||||||
|
AlertManager: {
|
||||||
|
alertWithArgs: jest.fn(),
|
||||||
|
},
|
||||||
|
AsyncLocalStorage: {
|
||||||
|
clear: jest.fn(),
|
||||||
|
getItem: jest.fn(),
|
||||||
|
removeItem: jest.fn(),
|
||||||
|
setItem: jest.fn(),
|
||||||
|
},
|
||||||
|
BuildInfo: {
|
||||||
|
appVersion: '0',
|
||||||
|
buildVersion: '0',
|
||||||
|
},
|
||||||
|
Clipboard: {
|
||||||
|
setString: jest.fn(),
|
||||||
|
},
|
||||||
|
DataManager: {
|
||||||
|
queryData: jest.fn(),
|
||||||
|
},
|
||||||
|
FacebookSDK: {
|
||||||
|
login: jest.fn(),
|
||||||
|
logout: jest.fn(),
|
||||||
|
queryGraphPath: jest.fn((path, method, params, callback) => callback()),
|
||||||
|
},
|
||||||
|
FbRelayNativeAdapter: {
|
||||||
|
updateCLC: jest.fn(),
|
||||||
|
},
|
||||||
|
GraphPhotoUpload: {
|
||||||
|
upload: jest.fn(),
|
||||||
|
},
|
||||||
|
I18n: {
|
||||||
|
translationsDictionary: JSON.stringify({
|
||||||
|
'Good bye, {name}!|Bye message': '\u{00A1}Adi\u{00F3}s {name}!',
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
ImageLoader: {
|
||||||
|
getSize: jest.fn(
|
||||||
|
(uri, success) => process.nextTick(() => success(320, 240))
|
||||||
|
),
|
||||||
|
prefetchImage: jest.fn(),
|
||||||
|
},
|
||||||
|
ImageViewManager: {
|
||||||
|
getSize: jest.fn(
|
||||||
|
(uri, success) => process.nextTick(() => success(320, 240))
|
||||||
|
),
|
||||||
|
prefetchImage: jest.fn(),
|
||||||
|
},
|
||||||
|
ModalFullscreenViewManager: {},
|
||||||
|
SourceCode: {
|
||||||
|
scriptURL: null,
|
||||||
|
},
|
||||||
|
Timing: {
|
||||||
|
createTimer: jest.fn(),
|
||||||
|
deleteTimer: jest.fn(),
|
||||||
|
},
|
||||||
|
UIManager: {
|
||||||
|
customBubblingEventTypes: {},
|
||||||
|
customDirectEventTypes: {},
|
||||||
|
Dimensions: {
|
||||||
|
window: {
|
||||||
|
fontScale: 2,
|
||||||
|
height: 1334,
|
||||||
|
scale: 2,
|
||||||
|
width: 750,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RCTModalFullscreenView: {
|
||||||
|
Constants: {},
|
||||||
|
},
|
||||||
|
RCTScrollView: {
|
||||||
|
Constants: {},
|
||||||
|
},
|
||||||
|
RCTView: {
|
||||||
|
Constants: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.keys(mockNativeModules).forEach(module => {
|
||||||
|
try {
|
||||||
|
jest.doMock(module, () => mockNativeModules[module]); // needed by FacebookSDK-test
|
||||||
|
} catch (e) {
|
||||||
|
jest.doMock(module, () => mockNativeModules[module], {virtual: true});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
jest
|
||||||
|
.doMock('NativeModules', () => mockNativeModules)
|
||||||
|
.doMock('ReactNativePropRegistry', () => ({
|
||||||
|
register: id => id,
|
||||||
|
getByID: () => mockEmptyObject,
|
||||||
|
}));
|
|
@ -1,37 +1,13 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
* Copyright (c) 2013-present, Facebook, Inc.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the BSD-style license found in the
|
* This source code is licensed under the BSD-style license found in the
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
*/
|
*/
|
||||||
'use strict';
|
|
||||||
|
|
||||||
require.requireActual('../packager/react-packager/src/Resolver/polyfills/babelHelpers.js');
|
throw new Error(
|
||||||
require.requireActual('../packager/react-packager/src/Resolver/polyfills/Object.es7.js');
|
'React-Native and Jest should be tested together with the jest-react-native preset:' +
|
||||||
|
'http://facebook.github.io/jest/docs/tutorial-react-native.html'
|
||||||
global.__DEV__ = true;
|
);
|
||||||
global.__fbBatchedBridgeConfig = {
|
|
||||||
remoteModuleConfig: [],
|
|
||||||
localModulesConfig: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
global.Promise = require('promise');
|
|
||||||
global.regeneratorRuntime = require.requireActual('regenerator-runtime/runtime');
|
|
||||||
|
|
||||||
jest
|
|
||||||
.mock('ensureComponentIsNative')
|
|
||||||
.mock('Image')
|
|
||||||
.mock('npmlog')
|
|
||||||
.mock('NativeModules')
|
|
||||||
.mock('Text')
|
|
||||||
.mock('View');
|
|
||||||
|
|
||||||
const mockEmptyObject = {};
|
|
||||||
jest.mock('ReactNativePropRegistry', () => ({
|
|
||||||
register: id => id,
|
|
||||||
getByID: () => mockEmptyObject,
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.setMock('ErrorUtils', require('ErrorUtils'));
|
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"automock": true,
|
"automock": true,
|
||||||
"scriptPreprocessor": "jestSupport/preprocessor.js",
|
"scriptPreprocessor": "jest/preprocessor.js",
|
||||||
"setupFiles": [
|
"setupFiles": [
|
||||||
"jestSupport/env.js"
|
"jest/setup.js"
|
||||||
],
|
],
|
||||||
"timers": "fake",
|
"timers": "fake",
|
||||||
"moduleNameMapper": {
|
"moduleNameMapper": {
|
||||||
|
@ -117,7 +117,7 @@
|
||||||
"LICENSE",
|
"LICENSE",
|
||||||
"PATENTS",
|
"PATENTS",
|
||||||
"README.md",
|
"README.md",
|
||||||
"jestSupport",
|
"jest",
|
||||||
".flowconfig",
|
".flowconfig",
|
||||||
"flow"
|
"flow"
|
||||||
],
|
],
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
"node": ">=4"
|
"node": ">=4"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"setupEnvScriptFile": "jestSupport/env.js",
|
"setupEnvScriptFile": "jest/setup.js",
|
||||||
"testPathIgnorePatterns": [
|
"testPathIgnorePatterns": [
|
||||||
"/node_modules/"
|
"/node_modules/"
|
||||||
],
|
],
|
||||||
|
|
|
@ -8,15 +8,18 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
jest.disableAutomock();
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
const jsDocs = require('../jsdocs');
|
const jsDocs = require('../jsdocs');
|
||||||
const libs = __dirname + '/../../../Libraries/';
|
const libs = path.join(__dirname, '/../../../Libraries/');
|
||||||
|
|
||||||
function checkWeCanParse(library) {
|
function checkWeCanParse(library) {
|
||||||
let path = libs + library;
|
const pathToCode = path.join(libs, library);
|
||||||
let code = fs.readFileSync(path).toString();
|
const code = fs.readFileSync(pathToCode).toString();
|
||||||
let json = jsDocs(code);
|
const json = jsDocs(code);
|
||||||
expect(json).toBeTruthy();
|
expect(json).toBeTruthy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +33,7 @@ describe('parseSource', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not parse invalid code', () => {
|
it('should not parse invalid code', () => {
|
||||||
let code = `
|
const code = `
|
||||||
for x in range(10):
|
for x in range(10):
|
||||||
print 'oops this isnt python'
|
print 'oops this isnt python'
|
||||||
`;
|
`;
|
||||||
|
|
Loading…
Reference in New Issue