Skip to content

Commit

Permalink
Fix remx optional dependency (#7241)
Browse files Browse the repository at this point in the history
Currently, remx is an optional peer dependency that is required for our mock consumers only. But it is actually being imported from our main `index.ts` which break users who don't import it even though they are not using mocks.
The solution is to change the way users import our mocks and make it explicit. 

Mocks now should be imported from `react-native-navigation/Mock`.


Co-authored-by: Carl-Gerhard Lindesvärd <c.lindesvard@klarna.com>
  • Loading branch information
yogevbd and Carl-Gerhard Lindesvärd authored Sep 2, 2021
1 parent bb2b09e commit e19ff8c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions Mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/dist/Mock';
4 changes: 2 additions & 2 deletions jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const { mockDetox } = require('detox-testing-library-rnn-adapter');
mockDetox(() => require('./playground/index'));

beforeEach(() => {
const { Navigation } = require('react-native-navigation');
const { mockNativeComponents } = require('react-native-navigation/Mock');
setTimeout = (func) => {
func();
};
Navigation.mockNativeComponents();
mockNativeComponents();
mockUILib();
});

Expand Down
13 changes: 13 additions & 0 deletions lib/src/Mock/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
export const ApplicationMock = require('./Application').Application;

export * from './constants';

export function mockNativeComponents() {
const { NativeCommandsSender } = require('./mocks/NativeCommandsSender');
const { NativeEventsReceiver } = require('./mocks/NativeEventsReceiver');
const { AppRegistryService } = require('./mocks/AppRegistryService');
const { Navigation } = require('react-native-navigation');

Navigation.mockNativeComponents(
new NativeCommandsSender(),
new NativeEventsReceiver(),
new AppRegistryService()
);
}
15 changes: 8 additions & 7 deletions lib/src/NavigationDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,15 @@ export class NavigationDelegate {
return this.concreteNavigation.TouchablePreview;
}

public mockNativeComponents() {
const { NativeCommandsSender } = require('./Mock/mocks/NativeCommandsSender');
const { NativeEventsReceiver } = require('./Mock/mocks/NativeEventsReceiver');
const { AppRegistryService } = require('./Mock/mocks/AppRegistryService');
public mockNativeComponents(
mockedNativeCommandsSender: NativeCommandsSender,
mockedNativeEventsReceiver: NativeEventsReceiver,
mockedAppRegistryService: AppRegistryService
) {
this.concreteNavigation = this.createConcreteNavigation(
new NativeCommandsSender(),
new NativeEventsReceiver(),
new AppRegistryService()
mockedNativeCommandsSender,
mockedNativeEventsReceiver,
mockedAppRegistryService
);
}

Expand Down
1 change: 0 additions & 1 deletion lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ export * from './interfaces/NavigationFunctionComponent';
export * from './interfaces/CommandName';
export * from './interfaces/Processors';
export * from './interfaces/ProcessorSubscription';
export * from './Mock';
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
"ts-mockito": "^2.3.1",
"typedoc": "0.x.x",
"typescript": "3.9.5",
"detox-testing-library-rnn-adapter": "1.x.x",
"remx": "4.x.x"
"detox-testing-library-rnn-adapter": "2.x.x",
"remx": "3.x.x"
},
"jest": {
"preset": "react-native",
Expand All @@ -134,6 +134,7 @@
"./jest-setup.js"
],
"moduleNameMapper": {
"react-native-navigation/Mock": "<rootDir>/lib/src/Mock",
"react-native-navigation": "<rootDir>/lib/src",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/playground/img/layouts@2x.png"
},
Expand Down Expand Up @@ -257,4 +258,4 @@
}
}
}
}
}

0 comments on commit e19ff8c

Please sign in to comment.