Permalink
Browse files

Adding Jest preset so that people can configure Jest using react-nati…

…ve as preset

Reviewed By: cpojer

Differential Revision: D4081817

fbshipit-source-id: 43cf2ec467ea69651705162b6a58e0b3f1ad1dbf
  • Loading branch information...
1 parent bb84c37 commit 6d3e074dd453e8335abc61ecbf2f3d6405dcbca0 Cristian Carlesso committed with Facebook Github Bot Oct 31, 2016
Showing with 73 additions and 29 deletions.
  1. +25 −0 jest-preset.json
  2. +20 −0 jest/setup.js
  3. +3 −3 local-cli/generator/index.js
  4. +14 −13 package.json
  5. +11 −13 scripts/run-ci-e2e-tests.js
View
@@ -0,0 +1,25 @@
+{
+ "haste": {
+ "defaultPlatform": "ios",
+ "platforms": ["android", "ios"],
+ "providesModuleNodeModules": [
+ "react",
+ "react-native"
+ ]
+ },
+ "moduleNameMapper": {
+ "^image![a-zA-Z0-9$_-]+$": "GlobalImageStub",
+ "^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|png|psd|svg|webp)$": "RelativeImageStub"
+ },
+ "modulePathIgnorePatterns": [
+ "<rootDir>/node_modules/react-native/Libraries/react-native/",
+ "<rootDir>/node_modules/react-native/packager/"
+ ],
+ "preprocessorIgnorePatterns": [
+ "node_modules/(?!(jest-)?react-native|react-clone-referenced-element)"
+ ],
+ "setupFiles": [
+ "<rootDir>/node_modules/react-native/jest/setup.js"
+ ],
+ "testEnvironment": "node"
+}
View
@@ -20,6 +20,7 @@ global.Promise = require.requireActual('promise');
global.regeneratorRuntime = require.requireActual('regenerator-runtime/runtime');
jest
+ .mock('setupDevtools')
.mock('npmlog');
// there's a __mock__ for it.
@@ -113,7 +114,17 @@ const mockNativeModules = {
),
prefetchImage: jest.fn(),
},
+ KeyboardObserver: {
+ addListener: jest.fn(),
+ removeListeners: jest.fn(),
+ },
ModalFullscreenViewManager: {},
+ Networking: {
+ sendRequest: jest.fn(),
+ abortRequest: jest.fn(),
+ addListener: jest.fn(),
+ removeListeners: jest.fn(),
+ },
SourceCode: {
scriptURL: null,
},
@@ -142,6 +153,15 @@ const mockNativeModules = {
Constants: {},
},
},
+ WebSocketModule: {
+ connect: jest.fn(),
+ send: jest.fn(),
+ sendBinary: jest.fn(),
+ ping: jest.fn(),
+ close: jest.fn(),
+ addListener: jest.fn(),
+ removeListeners: jest.fn(),
+ },
};
Object.keys(mockNativeModules).forEach(module => {
@@ -10,8 +10,8 @@
var fs = require('fs');
var path = require('path');
-var yeoman = require('yeoman-generator');
var utils = require('../generator-utils');
+var yeoman = require('yeoman-generator');
module.exports = yeoman.generators.NamedBase.extend({
constructor: function() {
@@ -114,7 +114,7 @@ module.exports = yeoman.generators.NamedBase.extend({
this.npmInstall(`react@${reactVersion}`, { '--save': true, '--save-exact': true });
if (!this.options['skip-jest']) {
- this.npmInstall(`jest babel-jest jest-react-native babel-preset-react-native react-test-renderer@${reactVersion}`.split(' '), {
+ this.npmInstall(`jest babel-jest babel-preset-react-native react-test-renderer@${reactVersion}`.split(' '), {
saveDev: true,
'--save-exact': true
});
@@ -145,7 +145,7 @@ module.exports = yeoman.generators.NamedBase.extend({
);
packageJSON.scripts.test = 'jest';
packageJSON.jest = {
- preset: 'jest-react-native'
+ preset: 'react-native'
};
fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, '\t'));
}
View
@@ -102,24 +102,25 @@
},
"main": "Libraries/react-native/react-native.js",
"files": [
- "React",
- "React.podspec",
- "ReactAndroid",
- "ReactCommon",
- "react.gradle",
+ ".flowconfig",
"android",
- "Libraries",
- "lib",
- "packager",
"cli.js",
- "local-cli",
+ "flow",
"init.sh",
+ "jest-preset.json",
+ "jest",
+ "lib",
+ "Libraries",
"LICENSE",
+ "local-cli",
+ "packager",
"PATENTS",
- "README.md",
- "jest",
- ".flowconfig",
- "flow"
+ "react.gradle",
+ "React.podspec",
+ "React",
+ "ReactAndroid",
+ "ReactCommon",
+ "README.md"
],
"scripts": {
"test": "jest",
@@ -57,7 +57,7 @@ try {
}
}
- if (argv['android']) {
+ if (argv.android) {
if (exec('./gradlew :ReactAndroid:installArchives -Pjobs=1 -Dorg.gradle.jvmargs="-Xmx512m -XX:+HeapDumpOnOutOfMemoryError"').code) {
echo('Failed to compile Android binaries');
exitCode = 1;
@@ -88,7 +88,7 @@ try {
cd('EndToEndTest');
- if (argv['android']) {
+ if (argv.android) {
echo('Running an Android e2e test');
echo('Installing e2e framework');
if (tryExecNTimes(
@@ -122,7 +122,7 @@ try {
exitCode = 1;
throw Error(exitCode);
}
- let packagerEnv = Object.create(process.env);
+ const packagerEnv = Object.create(process.env);
packagerEnv.REACT_NATIVE_MAX_WORKERS = 1;
// shelljs exec('', {async: true}) does not emit stdout events, so we rely on good old spawn
const packagerProcess = spawn('npm', ['start'], {
@@ -146,7 +146,7 @@ try {
}
}
- if (argv['ios']) {
+ if (argv.ios) {
echo('Running an iOS app');
cd('ios');
// Make sure we installed local version of react-native
@@ -156,7 +156,7 @@ try {
throw Error(exitCode);
}
// shelljs exec('', {async: true}) does not emit stdout events, so we rely on good old spawn
- let packagerEnv = Object.create(process.env);
+ const packagerEnv = Object.create(process.env);
packagerEnv.REACT_NATIVE_MAX_WORKERS = 1;
const packagerProcess = spawn('npm', ['start', '--', '--non-persistent'],
{
@@ -183,7 +183,7 @@ try {
cd('..');
}
- if (argv['js']) {
+ if (argv.js) {
// Check the packager produces a bundle (doesn't throw an error)
if (exec('react-native bundle --platform android --dev true --entry-file index.android.js --bundle-output android-bundle.js').code) {
echo('Could not build android package');
@@ -200,13 +200,11 @@ try {
exitCode = 1;
throw Error(exitCode);
}
- // Temporarily removed jest test until a RN fix to jest lands in a couple of days
- // ping @bestander after 27.09.2016 if you see this
- // if (exec(`npm test`).code) {
- // echo('Jest test failure');
- // exitCode = 1;
- // throw Error(exitCode);
- // }
+ if (exec('npm test').code) {
+ echo('Jest test failure');
+ exitCode = 1;
+ throw Error(exitCode);
+ }
}
exitCode = 0;

0 comments on commit 6d3e074

Please sign in to comment.