forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
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
jackpope
wants to merge
12
commits into
main
Choose a base branch
from
init-rntr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Init rntr #1
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5e8602a
initial setup
3e9f793
Move to src/renderer
dad740d
Tests run and fail
d2bef6a
Passing tests
292f65c
clean up
19225f2
build stuff
70828f9
create preset, jest not defined
03e50d3
running again, but not in linked app
bf29f1e
f
18dd300
clean up
5dd2abd
more cleanup
6de0111
Add to build step
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Dependencies | ||
/node_modules | ||
|
||
# Build output | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}, | ||
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', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
74
packages/react-native-test-renderer/src/jest-environment/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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