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

Support React Native #37

Merged
merged 21 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
544e411
Update build system to support a React Native bundle
smithki Apr 10, 2020
cecf18f
Add initial implementation for React Native (requires e2e testing)
smithki Apr 11, 2020
40d5e2c
Fix CJS builds and rename 'WebViewController' to 'ReactNativeWebViewC…
smithki Apr 11, 2020
60c926f
Remove unnecessary return statement
smithki Apr 11, 2020
063b820
Fix React dependency regex in Webpack config
smithki Apr 11, 2020
9e7e68d
Update CircleCI config
smithki Apr 11, 2020
ac50c28
Re-organize '/core' tests to reflect additional view controllers
smithki Apr 11, 2020
93e2657
Organizational comments
smithki Apr 11, 2020
d2e2021
Remove superfluous comment
smithki Apr 11, 2020
73e6c53
Add first draft CHANGELOG entry for React Native feature
smithki Apr 11, 2020
e6a1957
Update 'isViewReady' condition
smithki Apr 11, 2020
768dc7b
Package 'react-native-webview' and 'whatwg-url' in the RN bundle
smithki Apr 11, 2020
1abad60
Add .vscode to git ignores
smithki Apr 11, 2020
337e6c3
Add /dist to eslint ignores
smithki Apr 11, 2020
c62a6a6
Clean up Webpack config
smithki Apr 11, 2020
520e510
Externalize 'react-native-webview' & fix event listener bug in 'Paylo…
smithki Apr 14, 2020
857e503
Merge branch 'master' into react_native
smithki Apr 17, 2020
a690a39
Merge branch 'master' into react_native
smithki Apr 21, 2020
5385d97
Merge branch 'master' into react_native
smithki Apr 21, 2020
849d1b0
React native unit tests (#49)
smithki Apr 22, 2020
62cedc0
Add some testing cleanups
smithki Apr 22, 2020
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
Prev Previous commit
Add some testing cleanups
  • Loading branch information
smithki committed Apr 22, 2020
commit 62cedc083241b589411ce653e0a11b1e696e3bb4
28 changes: 19 additions & 9 deletions test/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
eslint-disable

global-require,
@typescript-eslint/no-var-requires
*/

import sinon from 'sinon';
import mockery from 'mockery';
import * as ConfigConstants from '../src/constants/config';
Expand All @@ -19,19 +26,22 @@ export function removeReactDependencies() {
mockery.registerMock('react', noopModule);
mockery.registerMock('react-native', noopModule);
mockery.registerMock('react-native-webview', noopModule);
}

export function removeWhatwgUrl() {
mockery.registerMock('whatwg-url', noopModule);
}

export function resetModuleCache() {
mockery.resetCache();
}

export function enableMocks() {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
});
}

export function reactNativeStyleSheetStub() {
const ReactNative = require('react-native');

const createStub = sinon.stub();

ReactNative.StyleSheet = {
create: createStub,
};

return createStub;
}
5 changes: 1 addition & 4 deletions test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// NOTE: This module is automatically included at the top of each test file.

import browserEnv from '@ikscodes/browser-env';
import { enableMocks, removeReactDependencies, removeWhatwgUrl } from './mocks';
import { removeReactDependencies } from './mocks';

browserEnv();
enableMocks();

removeReactDependencies();
removeWhatwgUrl();
6 changes: 2 additions & 4 deletions test/spec/core/sdk/react-native/modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import browserEnv from '@ikscodes/browser-env';
import test from 'ava';
import { StyleSheet } from 'react-native';
import sinon from 'sinon';
import { MagicSDKReactNative } from '../../../../../src/core/sdk';
import { TEST_API_KEY } from '../../../../constants';
import { mockConfigConstant } from '../../../../mocks';
import { mockConfigConstant, reactNativeStyleSheetStub } from '../../../../mocks';

test.beforeEach(t => {
browserEnv.restore();
mockConfigConstant('IS_REACT_NATIVE', true);
(StyleSheet as any) = { create: sinon.stub() };
reactNativeStyleSheetStub();
});

test('`MagicSDKReactNative.Modal` returns `ReactNativeWebViewController.Modal`', async t => {
Expand Down
6 changes: 2 additions & 4 deletions test/spec/core/sdk/react-native/overlay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import browserEnv from '@ikscodes/browser-env';
import test from 'ava';
import { StyleSheet } from 'react-native';
import sinon from 'sinon';
import { MagicSDK, MagicSDKReactNative } from '../../../../../src/core/sdk';
import { TEST_API_KEY } from '../../../../constants';
import { mockConfigConstant } from '../../../../mocks';
import { mockConfigConstant, reactNativeStyleSheetStub } from '../../../../mocks';
import { ReactNativeWebViewController } from '../../../../../src/core/views/react-native-webview-controller';

test.beforeEach(t => {
browserEnv.restore();
mockConfigConstant('IS_REACT_NATIVE', true);
(StyleSheet as any) = { create: sinon.stub() };
reactNativeStyleSheetStub();
});

test('`MagicSDKReactNative.overlay` is lazy loaded', async t => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import browserEnv from '@ikscodes/browser-env';
import test from 'ava';
import sinon from 'sinon';
import { StyleSheet } from 'react-native';
import { createReactNativeWebViewController } from '../../../../factories';
import { ReactNativeWebViewController } from '../../../../../src/core/views/react-native-webview-controller';
import { PayloadTransport } from '../../../../../src/core/payload-transport';
import { MAGIC_RELAYER_FULL_URL, ENCODED_QUERY_PARAMS } from '../../../../constants';
import { mockConfigConstant } from '../../../../mocks';
import { mockConfigConstant, reactNativeStyleSheetStub } from '../../../../mocks';

test.beforeEach(t => {
browserEnv.restore();
Expand All @@ -19,7 +18,8 @@ test('Instantiates `ReactNativeWebViewController`', async t => {
const listenStub = sinon.stub();
const waitForReadyStub = sinon.stub();

(StyleSheet as any) = { create: sinon.stub().returns({ hello: 'world' }) };
const createStyleSheetStub = reactNativeStyleSheetStub();
createStyleSheetStub.returns({ hello: 'world' });

(ReactNativeWebViewController.prototype as any).listen = listenStub;
(ReactNativeWebViewController.prototype as any).waitForReady = waitForReadyStub;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import browserEnv from '@ikscodes/browser-env';
import test from 'ava';
import sinon from 'sinon';
import { StyleSheet } from 'react-native';
import { createReactNativeWebViewController } from '../../../../factories';
import { MSG_TYPES, ENCODED_QUERY_PARAMS } from '../../../../constants';
import { mockConfigConstant } from '../../../../mocks';
import { mockConfigConstant, reactNativeStyleSheetStub } from '../../../../mocks';

test.beforeEach(t => {
browserEnv();
mockConfigConstant('IS_REACT_NATIVE', true);
(StyleSheet as any) = { create: sinon.stub() };
reactNativeStyleSheetStub();
});

test.cb('Receive MAGIC_HIDE_OVERLAY, call `hideOverlay` if present', t => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import browserEnv from '@ikscodes/browser-env';
import sinon from 'sinon';
import test from 'ava';
import { StyleSheet } from 'react-native';
import { createReactNativeWebViewController } from '../../../../factories';
import { MSG_TYPES, ENCODED_QUERY_PARAMS } from '../../../../constants';
import { mockConfigConstant } from '../../../../mocks';
import { mockConfigConstant, reactNativeStyleSheetStub } from '../../../../mocks';

test.beforeEach(t => {
browserEnv();
mockConfigConstant('IS_REACT_NATIVE', true);
(StyleSheet as any) = { create: sinon.stub() };
reactNativeStyleSheetStub();
});

test.cb('Receive MAGIC_OVERLAY_READY, resolve `waitForReady` promise', t => {
Expand Down
2 changes: 2 additions & 0 deletions test/spec/modules/base-module/request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const requestPayload: JsonRpcRequestPayload = {

test.beforeEach(t => {
browserEnv.restore();
// Silence the "duplicate iframes" warning.
browserEnv.stub('console.warn', () => {});
});

test.serial('Resolves with a successful response', async t => {
Expand Down