-
Notifications
You must be signed in to change notification settings - Fork 36
test: add shared jest tests for demo apps #313
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
Open
alpharius-ck
wants to merge
5
commits into
main
Choose a base branch
from
feat/add-shared-unit-tests-for-rn-demo-apps
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7b99a2a
feat: add shared jest tests for demo apps
narefyev91 7111313
feat: use correct version for yarn
narefyev91 d12501f
feat: add change set
alpharius-ck ca838d6
Potential fix for pull request finding
alpharius-ck 643b12c
feat: add required globals
alpharius-ck 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 hidden or 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,7 @@ | ||
| --- | ||
| '@callstack/brownfield-example-shared-tests': minor | ||
| '@callstack/brownie': minor | ||
| '@callstack/brownfield-cli': minor | ||
| --- | ||
|
|
||
| Jest unit tests |
This file contains hidden or 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 hidden or 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,12 @@ | ||
| import PostMessageTab from '../app/(tabs)/postMessage'; | ||
| import Counter from '../components/counter'; | ||
| import RNApp from '../RNApp'; | ||
| import { | ||
| runPostMessageTabSuite, | ||
| runCounterSuite, | ||
| runExpoRnAppSuite, | ||
| } from '@callstack/brownfield-example-shared-tests'; | ||
|
|
||
| runPostMessageTabSuite('ExpoApp54', PostMessageTab); | ||
| runCounterSuite('ExpoApp54', Counter); | ||
| runExpoRnAppSuite('ExpoApp54', RNApp); |
This file contains hidden or 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,30 @@ | ||
| const path = require('path'); | ||
|
|
||
| module.exports = { | ||
| preset: 'jest-expo', | ||
| setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], | ||
| moduleNameMapper: { | ||
| '^react$': require.resolve('react'), | ||
| '^react/jsx-runtime$': require.resolve('react/jsx-runtime'), | ||
| '^react/jsx-dev-runtime$': require.resolve('react/jsx-dev-runtime'), | ||
| '^@testing-library/react-native$': require.resolve( | ||
| '@testing-library/react-native' | ||
| ), | ||
| '^@/(.*)$': '<rootDir>/$1', | ||
| '^@callstack/react-native-brownfield$': path.join( | ||
| __dirname, | ||
| '../../packages/react-native-brownfield/src/index.ts' | ||
| ), | ||
| '^@callstack/brownfield-navigation$': path.join( | ||
| __dirname, | ||
| '../../packages/brownfield-navigation/src/index.ts' | ||
| ), | ||
| '^@callstack/brownie$': path.join( | ||
| __dirname, | ||
| '../../packages/brownie/src/index.ts' | ||
| ), | ||
| }, | ||
| transformIgnorePatterns: [ | ||
| 'node_modules/(?!((jest-)?react-native|@react-native(-community)?|@callstack/brownfield-example-shared-tests|expo|@expo|expo-modules-core)/)', | ||
| ], | ||
| }; |
This file contains hidden or 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 @@ | ||
| require('@callstack/brownfield-example-shared-tests/jest/setup'); |
This file contains hidden or 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 hidden or 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,12 @@ | ||
| import PostMessageTab from '../src/app/postMessage'; | ||
| import Counter from '../src/components/counter'; | ||
| import RNApp from '../RNApp'; | ||
| import { | ||
| runPostMessageTabSuite, | ||
| runCounterSuite, | ||
| runExpoRnAppSuite, | ||
| } from '@callstack/brownfield-example-shared-tests'; | ||
|
|
||
| runPostMessageTabSuite('ExpoApp55', PostMessageTab); | ||
| runCounterSuite('ExpoApp55', Counter); | ||
| runExpoRnAppSuite('ExpoApp55', RNApp); |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,10 +1,18 @@ | ||
| // https://docs.expo.dev/guides/using-eslint/ | ||
| const { defineConfig } = require('eslint/config'); | ||
| const expoConfig = require('eslint-config-expo/flat'); | ||
| const globals = require('globals'); | ||
|
|
||
| module.exports = defineConfig([ | ||
| expoConfig, | ||
| { | ||
| ignores: ['dist/*'], | ||
| }, | ||
| // Jest config is executed by Node (CommonJS); teach ESLint Node globals like __dirname. | ||
| { | ||
| files: ['jest.config.js'], | ||
| languageOptions: { | ||
| globals: globals.node, | ||
| }, | ||
| }, | ||
| ]); |
This file contains hidden or 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,33 @@ | ||
| const path = require('path'); | ||
|
|
||
| module.exports = { | ||
| preset: 'jest-expo', | ||
| setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], | ||
| moduleNameMapper: { | ||
| '^react$': require.resolve('react'), | ||
| '^react/jsx-runtime$': require.resolve('react/jsx-runtime'), | ||
| '^react/jsx-dev-runtime$': require.resolve('react/jsx-dev-runtime'), | ||
| '^@testing-library/react-native$': require.resolve( | ||
| '@testing-library/react-native' | ||
| ), | ||
| // Match before `@/` so `@/global.css` is stubbed (Expo web styling). | ||
| '^.+\\.css$': '<rootDir>/jest/cssMock.js', | ||
| '^@/assets/(.*)$': '<rootDir>/assets/$1', | ||
| '^@/(.*)$': '<rootDir>/src/$1', | ||
| '^@callstack/react-native-brownfield$': path.join( | ||
| __dirname, | ||
| '../../packages/react-native-brownfield/src/index.ts' | ||
| ), | ||
| '^@callstack/brownfield-navigation$': path.join( | ||
| __dirname, | ||
| '../../packages/brownfield-navigation/src/index.ts' | ||
| ), | ||
| '^@callstack/brownie$': path.join( | ||
| __dirname, | ||
| '../../packages/brownie/src/index.ts' | ||
| ), | ||
| }, | ||
| transformIgnorePatterns: [ | ||
| 'node_modules/(?!((jest-)?react-native|@react-native(-community)?|@callstack/brownfield-example-shared-tests|expo|@expo|expo-modules-core)/)', | ||
| ], | ||
| }; |
This file contains hidden or 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 @@ | ||
| require('@callstack/brownfield-example-shared-tests/jest/setup'); |
This file contains hidden or 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,2 @@ | ||
| /** Stub CSS imports for Jest (used by Expo Router / bundler pipeline). */ | ||
| module.exports = {}; |
This file contains hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
| import { | ||
| runCounterSuite, | ||
| runHomeScreenSuite, | ||
| } from '@callstack/brownfield-example-shared-tests'; | ||
| import { HomeScreen } from '../src/HomeScreen'; | ||
| import Counter from '../src/components/counter'; | ||
| import { getRandomTheme } from '../src/utils'; | ||
|
|
||
| const theme = getRandomTheme(); | ||
|
|
||
| runHomeScreenSuite('RNApp', HomeScreen); | ||
| runCounterSuite('RNApp', Counter, { colors: theme }); |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,28 @@ | ||
| const path = require('node:path'); | ||
|
|
||
| module.exports = { | ||
| preset: '@react-native/jest-preset', | ||
| setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], | ||
| moduleNameMapper: { | ||
| '^react$': require.resolve('react'), | ||
| '^react/jsx-runtime$': require.resolve('react/jsx-runtime'), | ||
| '^react/jsx-dev-runtime$': require.resolve('react/jsx-dev-runtime'), | ||
| '^@testing-library/react-native$': | ||
| require.resolve('@testing-library/react-native'), | ||
| '^@callstack/react-native-brownfield$': path.join( | ||
| __dirname, | ||
| '../../packages/react-native-brownfield/src/index.ts' | ||
| ), | ||
| '^@callstack/brownfield-navigation$': path.join( | ||
| __dirname, | ||
| '../../packages/brownfield-navigation/src/index.ts' | ||
| ), | ||
| '^@callstack/brownie$': path.join( | ||
| __dirname, | ||
| '../../packages/brownie/src/index.ts' | ||
| ), | ||
| }, | ||
| transformIgnorePatterns: [ | ||
| 'node_modules/(?!((jest-)?react-native|@react-native(-community)?|@callstack/brownfield-example-shared-tests|@react-navigation|react-native-screens|react-native-safe-area-context)/)', | ||
| ], | ||
| }; |
This file contains hidden or 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 @@ | ||
| require('@callstack/brownfield-example-shared-tests/jest/setup'); |
This file contains hidden or 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 hidden or 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,56 @@ | ||
| /** | ||
| * Shared Jest setup for brownfield example apps. Include via setupFilesAfterEnv. | ||
| * | ||
| * @see https://jestjs.io/docs/configuration#setupfilesafterenv-array | ||
| */ | ||
|
|
||
| global.__brownieExampleCounter = 0; | ||
| global.__resetBrownieExampleStore = () => { | ||
| global.__brownieExampleCounter = 0; | ||
| }; | ||
|
|
||
| jest.mock('@callstack/react-native-brownfield', () => ({ | ||
| __esModule: true, | ||
| default: { | ||
| onMessage: jest.fn(() => ({ remove: jest.fn() })), | ||
| postMessage: jest.fn(), | ||
| setNativeBackGestureAndButtonEnabled: jest.fn(), | ||
| popToNative: jest.fn(), | ||
| }, | ||
| })); | ||
|
|
||
| jest.mock('@callstack/brownfield-navigation', () => ({ | ||
| __esModule: true, | ||
| default: { | ||
| navigateToSettings: jest.fn(), | ||
| navigateToReferrals: jest.fn(), | ||
| }, | ||
| })); | ||
|
|
||
| jest.mock('@callstack/brownie', () => ({ | ||
| __esModule: true, | ||
| /** Resolve React from the app running Jest (cwd), not from this package's nested deps. */ | ||
| useStore(key, selector) { | ||
| const React = require(require.resolve('react', { paths: [process.cwd()] })); | ||
| const [, setRev] = React.useState(0); | ||
| const setState = React.useCallback( | ||
| (action) => { | ||
| const prev = { counter: global.__brownieExampleCounter }; | ||
| const partial = typeof action === 'function' ? action(prev) : action; | ||
| if ( | ||
| partial && | ||
| typeof partial === 'object' && | ||
| partial.counter !== undefined | ||
| ) { | ||
| global.__brownieExampleCounter = partial.counter; | ||
| } | ||
| setRev((r) => r + 1); | ||
| }, | ||
| [selector] | ||
| ); | ||
| return [ | ||
| selector({ counter: global.__brownieExampleCounter }), | ||
| setState, | ||
| ]; | ||
| }, | ||
| })); |
This file contains hidden or 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,28 @@ | ||
| { | ||
| "name": "@callstack/brownfield-example-shared-tests", | ||
| "version": "0.0.1", | ||
| "private": true, | ||
| "scripts": { | ||
| "test": "node -e \"process.exit(0)\"" | ||
| }, | ||
| "main": "src/index.ts", | ||
| "types": "src/index.ts", | ||
| "exports": { | ||
| ".": "./src/index.ts", | ||
| "./jest/setup": "./jest/setup.js" | ||
| }, | ||
| "peerDependencies": { | ||
| "@testing-library/react-native": ">=12", | ||
| "react": ">=18", | ||
| "react-native": ">=0.73", | ||
| "react-test-renderer": ">=18" | ||
| }, | ||
| "devDependencies": { | ||
| "@callstack/brownfield-navigation": "workspace:^", | ||
| "@callstack/react-native-brownfield": "workspace:^", | ||
| "@testing-library/react-native": "^13.3.3", | ||
| "@types/jest": "^30.0.0", | ||
| "@types/react": "^19.1.1", | ||
| "typescript": "5.9.3" | ||
| } | ||
| } |
This file contains hidden or 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,7 @@ | ||
| /* eslint-disable no-var */ | ||
| declare global { | ||
| var __brownieExampleCounter: number; | ||
| var __resetBrownieExampleStore: () => void; | ||
| } | ||
|
|
||
| export {}; |
This file contains hidden or 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,4 @@ | ||
| export { runPostMessageTabSuite } from './suites/postMessageTab.suite'; | ||
| export { runCounterSuite } from './suites/counter.suite'; | ||
| export { runExpoRnAppSuite } from './suites/expoRnApp.suite'; | ||
| export { runHomeScreenSuite } from './suites/homeScreen.suite'; |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.