Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init rntr #1

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions packages/community-cli-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"name": "@react-native/community-cli-plugin",
"version": "0.74.0",
"description": "Core CLI commands for React Native",
"keywords": [
"react-native",
"tools"
],
"keywords": ["react-native", "tools"],
"homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/buid-scripts#readme",
"bugs": "https://github.com/facebook/react-native/issues",
"repository": {
Expand All @@ -14,13 +11,8 @@
"directory": "packages/community-cli-plugin"
},
"license": "MIT",
"exports": {
".": "./src/index.js",
"./package.json": "./package.json"
},
"files": [
"dist"
],
"exports": { ".": "./dist/index.js", "./package.json": "./package.json" },
"files": ["dist"],
"dependencies": {
"@react-native/dev-middleware": "0.74.0",
"@react-native-community/cli-server-api": "13.0.0",
Expand All @@ -34,10 +26,6 @@
"node-fetch": "^2.2.0",
"readline": "^1.3.0"
},
"devDependencies": {
"metro-resolver": "^0.80.3"
},
"engines": {
"node": ">=18"
}
"devDependencies": { "metro-resolver": "^0.80.3" },
"engines": { "node": ">=18" }
}
18 changes: 4 additions & 14 deletions packages/dev-middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"name": "@react-native/dev-middleware",
"version": "0.74.0",
"description": "Dev server middleware for React Native",
"keywords": [
"react-native",
"tools"
],
"keywords": ["react-native", "tools"],
"homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/dev-middleware#readme",
"bugs": "https://github.com/facebook/react-native/issues",
"repository": {
Expand All @@ -14,13 +11,8 @@
"directory": "packages/dev-middleware"
},
"license": "MIT",
"exports": {
".": "./src/index.js",
"./package.json": "./package.json"
},
"files": [
"dist"
],
"exports": { ".": "./dist/index.js", "./package.json": "./package.json" },
"files": ["dist"],
"dependencies": {
"@isaacs/ttlcache": "^1.4.1",
"@react-native/debugger-frontend": "0.74.0",
Expand All @@ -34,9 +26,7 @@
"serve-static": "^1.13.1",
"temp-dir": "^2.0.0"
},
"engines": {
"node": ">=18"
},
"engines": { "node": ">=18" },
"devDependencies": {
"data-uri-to-buffer": "^6.0.1",
"undici": "^5.27.2",
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native-test-renderer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dependencies
/node_modules

# Build output
/dist
14 changes: 14 additions & 0 deletions packages/react-native-test-renderer/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/

module.exports = {
presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
plugins: ['@babel/plugin-transform-flow-strip-types', '@babel/plugin-transform-react-jsx'],
};
15 changes: 15 additions & 0 deletions packages/react-native-test-renderer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/

import ReactNativeEnvironment from './src/jest-environment/index';
import * as ReactNativeTestRenderer from './src/renderer/index';
import * as ReactNativeJestSetup from './src/jest-setup/index'

export { ReactNativeEnvironment, ReactNativeTestRenderer, ReactNativeJestSetup };
25 changes: 25 additions & 0 deletions packages/react-native-test-renderer/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

'use strict';

module.exports = {
haste: {
defaultPlatform: 'ios',
platforms: ['android', 'ios', 'native'],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan to have API to specify which platform to render as (ios, android)?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a task to follow up with a way to control this

},
transform: {
'^.+\\.(js|ts|tsx)$': 'babel-jest',
},
transformIgnorePatterns: [
'node_modules/(?!((jest-)?react-native|@react-native(-community)?)/)',
],
setupFilesAfterEnv: ['./src/jest-setup/index'],
testEnvironment: './src/jest-environment/index',
};
22 changes: 22 additions & 0 deletions packages/react-native-test-renderer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@react-native/test-renderer",
"version": "0.0.0",
"description": "A Jest Environment and test rendering library for React Native",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.23.3",
"@babel/plugin-transform-flow-strip-types": "^7.23.3",
"@babel/plugin-transform-react-jsx": "^7.22.15",
"@babel/preset-env": "^7.23.3",
"@types/jest": "^29.5.8",
"eslint": "^8.53.0",
"jest": "^29.7.0"
},
"dependencies": {},
"exports": {
".": "./index.js",
"./jest-environment": "./dist/jest-environment/index.js",
"./jest-setup": "./dist/jest-setup/index.js"
},
"peerDependencies": { "jest": "^29.7.0" }
}
74 changes: 74 additions & 0 deletions packages/react-native-test-renderer/src/jest-environment/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

'use strict';

const NodeEnv = require('jest-environment-node').TestEnvironment;

module.exports = class ReactNativeEnvironment extends NodeEnv {
customExportConditions = ['require', 'react-native'];

constructor(config, context) {
super(config, context);
}

async setup() {
await super.setup();
this.assignGlobals();
this.initializeTurboModuleRegistry();
}

assignGlobals() {
Object.defineProperties(this.global, {
__DEV__: {
configurable: true,
enumerable: true,
value: true,
writable: true,
},
});
this.global.IS_REACT_ACT_ENVIRONMENT= true
}

initializeTurboModuleRegistry() {
const dims = {width: 100, height: 100, scale: 1, fontScale: 1};
const DIMS = {
screen: {
...dims,
},
window: {
...dims,
},
};
this.global.nativeModuleProxy = name => ({}[name])
this.global.__turboModuleProxy = name =>
({
SourceCode: {getConstants: () => ({scriptURL: ''})},
WebSocketModule: {connect: () => {}},
FileReaderModule: {},
AppState: {getConstants: () => ({}), getCurrentAppState: () => ({})},
DeviceInfo: {getConstants: () => ({Dimensions: DIMS})},
UIManager: {getConstants: () => ({})},
Timing: {},
DevSettings: {},
PlatformConstants: {
getConstants: () => ({reactNativeVersion: '1000.0.0'}),
},
Networking: {},
ImageLoader: {},
NativePerformanceCxx: {},
NativePerformanceObserverCxx: {},
LogBox: {},
SettingsManager: {
getConstants: () => ({settings: {}})
},
LinkingManager: {},
})[name];
}
};
Loading