Skip to content

Commit

Permalink
chore: remove all browser-env package usage
Browse files Browse the repository at this point in the history
  • Loading branch information
otabek-magic committed Nov 29, 2024
1 parent 85ba0fe commit 729858d
Show file tree
Hide file tree
Showing 37 changed files with 41 additions and 103 deletions.
3 changes: 0 additions & 3 deletions packages/@magic-ext/aptos/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// NOTE: This module is automatically included at the top of each test file.
import browserEnv from '@ikscodes/browser-env';
import { mockConsole } from '../../../../scripts/utils/mock-console';

browserEnv();

beforeEach(() => {
mockConsole();
});
3 changes: 1 addition & 2 deletions packages/@magic-ext/aptos/test/spec/aptos-extension.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import browserEnv from '@ikscodes/browser-env';
import { BCS, TxnBuilderTypes } from 'aptos';
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
import { AptosExtension } from '../../src';
Expand Down Expand Up @@ -32,7 +31,7 @@ const MESSAGE_PAYLOAD = {
};

beforeEach(() => {
browserEnv.restore();
jest.resetAllMocks();
});

test('Construct GetAccount request with `aptos_getAccount`', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import browserEnv from '@ikscodes/browser-env';
import { BCS, TxnBuilderTypes } from 'aptos';
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
import { AptosExtension, MagicAptosWallet } from '../../src';
Expand Down Expand Up @@ -33,7 +32,7 @@ const MOCK_ACCOUTN_INFO = {
};

beforeEach(() => {
browserEnv.restore();
jest.resetAllMocks();
});

test('Call connect()', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@magic-ext/aptos/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "../../../../tsconfig.settings.test.json",
"extends": "../../../../tsconfig.settings.test.json"
}
2 changes: 0 additions & 2 deletions packages/@magic-ext/gdkms/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// NOTE: This module is automatically included at the top of each test file.
import browserEnv from '@ikscodes/browser-env';
import { Crypto } from '@peculiar/webcrypto';
import { mockConsole } from '../../../../scripts/utils/mock-console';

browserEnv();
(window as any).crypto = new Crypto();

beforeEach(() => {
Expand Down
3 changes: 1 addition & 2 deletions packages/@magic-ext/gdkms/test/spec/gdkms.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import browserEnv from '@ikscodes/browser-env';
import { MagicPayloadMethod } from '@magic-sdk/types';
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
import { GDKMSExtension } from '../../src';

beforeEach(() => {
browserEnv.restore();
jest.resetAllMocks();
});

test('Construct Encrypt Request with `magic_auth_encrypt_v1`', async () => {
Expand Down
3 changes: 0 additions & 3 deletions packages/@magic-ext/harmony/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// NOTE: This module is automatically included at the top of each test file.
import browserEnv from '@ikscodes/browser-env';
import { mockConsole } from '../../../../scripts/utils/mock-console';

browserEnv();

beforeEach(() => {
mockConsole();
});
3 changes: 1 addition & 2 deletions packages/@magic-ext/harmony/test/spec/harmony.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import browserEnv from '@ikscodes/browser-env';
import { HarmonyPayloadMethod } from '../../src/types';
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
import { HarmonyExtension } from '../../src';

beforeEach(() => {
browserEnv.restore();
jest.resetAllMocks();
});

test('Sends params as payload', async () => {
Expand Down
3 changes: 0 additions & 3 deletions packages/@magic-ext/kadena/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// NOTE: This module is automatically included at the top of each test file.
import browserEnv from '@ikscodes/browser-env';
import { mockConsole } from '../../../../scripts/utils/mock-console';

browserEnv();

beforeEach(() => {
mockConsole();
});
3 changes: 1 addition & 2 deletions packages/@magic-ext/kadena/test/spec/kadena.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import browserEnv from '@ikscodes/browser-env';
import { KadenaPayloadMethod } from '../../src/types';
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
import { KadenaExtension } from '../../src';

beforeEach(() => {
browserEnv.restore();
jest.resetAllMocks();
});

test('Sends params as payload', () => {
Expand Down
3 changes: 0 additions & 3 deletions packages/@magic-ext/sui/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// NOTE: This module is automatically included at the top of each test file.
import browserEnv from '@ikscodes/browser-env';
import { mockConsole } from '../../../../scripts/utils/mock-console';

browserEnv();

beforeEach(() => {
mockConsole();
});
3 changes: 1 addition & 2 deletions packages/@magic-ext/sui/test/spec/sui.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import browserEnv from '@ikscodes/browser-env';
import { SuiExtension } from '../../src/index';
import { SuiPayloadMethod } from '../../src/types';
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';

beforeEach(() => {
browserEnv.restore();
jest.resetAllMocks();
});

test('Sends params as payload', async () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/@magic-sdk/react-native-bare/test/factories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import browserEnv from '@ikscodes/browser-env';
import { MAGIC_RELAYER_FULL_URL, ENCODED_QUERY_PARAMS, TEST_API_KEY } from './constants';

export function createReactNativeWebViewController(endpoint = MAGIC_RELAYER_FULL_URL) {
Expand All @@ -10,6 +9,6 @@ export function createReactNativeWebViewController(endpoint = MAGIC_RELAYER_FULL

export function createMagicSDK(endpoint = MAGIC_RELAYER_FULL_URL) {
const { Magic } = jest.requireActual('../src/index.ts');
browserEnv.stub('console.warn', jest.fn());
jest.spyOn(console, 'warn').mockImplementation(jest.fn());
return new Magic(TEST_API_KEY, { endpoint });
}
11 changes: 0 additions & 11 deletions packages/@magic-sdk/react-native-bare/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,12 @@

import 'regenerator-runtime/runtime';

import browserEnv from '@ikscodes/browser-env';
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';
import { removeReactDependencies } from './mocks';
import { mockConsole } from '../../../../scripts/utils/mock-console';

jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage);

browserEnv([
'setTimeout',
'clearTimeout',
'postMessage',
'addEventListener',
'removeEventListener',
'document',
'console',
'window',
]);
beforeEach(() => {
mockConsole();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import browserEnv from '@ikscodes/browser-env';
import { createMagicSDK } from '../../factories';
import { reactNativeStyleSheetStub } from '../../mocks';

beforeEach(() => {
browserEnv.restore();
jest.restoreAllMocks();
reactNativeStyleSheetStub();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import browserEnv from '@ikscodes/browser-env';
import { createModalNotReadyError } from '@magic-sdk/provider';
import { createReactNativeWebViewController } from '../../factories';
import { reactNativeStyleSheetStub } from '../../mocks';

beforeEach(() => {
browserEnv.restore();
jest.resetAllMocks();
reactNativeStyleSheetStub();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import browserEnv from '@ikscodes/browser-env';
import { ENCODED_QUERY_PARAMS } from '../../constants';
import { createReactNativeWebViewController } from '../../factories';

beforeEach(() => {
browserEnv();
jest.resetAllMocks();
});

test('Ignores events with different origin than expected', (done) => {
test('Ignores events with different origin than expected', done => {
const viewController = createReactNativeWebViewController('asdf');
const onHandlerStub = jest.fn();
viewController.messageHandlers.add(onHandlerStub);
Expand All @@ -24,7 +23,7 @@ test('Ignores events with different origin than expected', (done) => {
}, 100);
});

test('Ignores events with non-string data', (done) => {
test('Ignores events with non-string data', done => {
const viewController = createReactNativeWebViewController('asdf');
const onHandlerStub = jest.fn();
viewController.messageHandlers.add(onHandlerStub);
Expand All @@ -42,7 +41,7 @@ test('Ignores events with non-string data', (done) => {
}, 100);
});

test('Replaces `undefined` or `null` response with an empty object', (done) => {
test('Replaces `undefined` or `null` response with an empty object', done => {
const viewController = createReactNativeWebViewController('asdf');
const onHandlerStub = jest.fn();
viewController.messageHandlers.add(onHandlerStub);
Expand All @@ -61,7 +60,7 @@ test('Replaces `undefined` or `null` response with an empty object', (done) => {
}, 100);
});

test('Executes event handlers where `messageHandlers` size is > 0', (done) => {
test('Executes event handlers where `messageHandlers` size is > 0', done => {
const viewController = createReactNativeWebViewController('asdf');
const onHandlerStub = jest.fn();
viewController.messageHandlers.add(onHandlerStub);
Expand All @@ -80,7 +79,7 @@ test('Executes event handlers where `messageHandlers` size is > 0', (done) => {
}, 100);
});

test('Ignores event handlers where `messageHandlers` size is === 0', (done) => {
test('Ignores event handlers where `messageHandlers` size is === 0', done => {
const viewController = createReactNativeWebViewController('asdf');
viewController.messageHandlers = { size: 0 };

Expand All @@ -96,7 +95,7 @@ test('Ignores event handlers where `messageHandlers` size is === 0', (done) => {
}, 100);
});

test('Process Typed Array in Solana Payload', (done) => {
test('Process Typed Array in Solana Payload', done => {
const viewController = createReactNativeWebViewController('asdf');
const onHandlerStub = jest.fn();

Expand Down Expand Up @@ -130,7 +129,7 @@ test('Process Typed Array in Solana Payload', (done) => {
}, 100);
});

test('Process Typed Array in Solana Payload', (done) => {
test('Process Typed Array in Solana Payload', done => {
const viewController = createReactNativeWebViewController('asdf');
const onHandlerStub = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import browserEnv from '@ikscodes/browser-env';
import { createReactNativeWebViewController } from '../../factories';
import { reactNativeStyleSheetStub } from '../../mocks';

beforeEach(() => {
browserEnv();
jest.resetAllMocks();
reactNativeStyleSheetStub();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import browserEnv from '@ikscodes/browser-env';
import { createReactNativeWebViewController } from '../../factories';
import { reactNativeStyleSheetStub } from '../../mocks';

beforeEach(() => {
browserEnv();
jest.resetAllMocks();
});

test("Intializes 'webView' with null", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import browserEnv from '@ikscodes/browser-env';
import { createReactNativeWebViewController } from '../../factories';
import { reactNativeStyleSheetStub } from '../../mocks';

beforeEach(() => {
browserEnv();
jest.resetAllMocks();
reactNativeStyleSheetStub();
});

Expand Down
3 changes: 1 addition & 2 deletions packages/@magic-sdk/react-native-expo/test/factories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import browserEnv from '@ikscodes/browser-env';
import { MAGIC_RELAYER_FULL_URL, ENCODED_QUERY_PARAMS, TEST_API_KEY } from './constants';

export function createReactNativeWebViewController(endpoint = MAGIC_RELAYER_FULL_URL) {
Expand All @@ -10,6 +9,6 @@ export function createReactNativeWebViewController(endpoint = MAGIC_RELAYER_FULL

export function createMagicSDK(endpoint = MAGIC_RELAYER_FULL_URL) {
const { Magic } = jest.requireActual('../src/index.ts');
browserEnv.stub('console.warn', jest.fn());
jest.spyOn(console, 'warn').mockImplementation(jest.fn());
return new Magic(TEST_API_KEY, { endpoint });
}
11 changes: 0 additions & 11 deletions packages/@magic-sdk/react-native-expo/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,12 @@

import 'regenerator-runtime/runtime';

import browserEnv from '@ikscodes/browser-env';
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';
import { removeReactDependencies } from './mocks';
import { mockConsole } from '../../../../scripts/utils/mock-console';

jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage);

browserEnv([
'setTimeout',
'clearTimeout',
'postMessage',
'addEventListener',
'removeEventListener',
'document',
'console',
'window',
]);
beforeEach(() => {
mockConsole();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import browserEnv from '@ikscodes/browser-env';
import { createMagicSDK } from '../../factories';
import { reactNativeStyleSheetStub } from '../../mocks';

beforeEach(() => {
browserEnv.restore();
jest.resetAllMocks();
reactNativeStyleSheetStub();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import browserEnv from '@ikscodes/browser-env';
import { createModalNotReadyError } from '@magic-sdk/provider';
import { createReactNativeWebViewController } from '../../factories';
import { reactNativeStyleSheetStub } from '../../mocks';

beforeEach(() => {
browserEnv.restore();
jest.resetAllMocks();
reactNativeStyleSheetStub();
});

Expand Down
Loading

0 comments on commit 729858d

Please sign in to comment.