Skip to content

Commit 5045f3f

Browse files
otabek-magicsherzod-bakhodirovEthella
authored
chore: remove @ikscodes/browser-env (#842)
* chore: remove @ikscodes/browser-env * chore: replace browserEnv fn with jest.spyOn * chore: add typescript-eslint rules for test files * chore: remove all browser-env package usage * fix: provider tests * fix: fix types in tests * fix: kadena tests * fix: deepsource 'any' * fix: deepsourse * fix: deepsourse * fix: signTransaction type * feat: add test to react native * fix: deepsource * fix tests * remove console --------- Co-authored-by: sherzod-bakhodirov <[email protected]> Co-authored-by: ethella <[email protected]>
1 parent 099866d commit 5045f3f

File tree

147 files changed

+1545
-1869
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+1545
-1869
lines changed

eslint.config.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export default [
1515
'**/dist',
1616
'**/jest.config.ts',
1717
'scripts/bin/scaffold/template/**/*',
18-
'.prettierrc.js',
18+
'**/.prettierrc.js',
19+
'**/README.md',
1920
],
2021
},
2122
{
@@ -41,6 +42,7 @@ export default [
4142
files: ['**/*.ts', '**/*.tsx'],
4243

4344
rules: {
45+
'no-undef': 0,
4446
'no-alert': 'off',
4547
'no-dupe-class-members': 'off',
4648
'no-underscore-dangle': 'off',
@@ -72,4 +74,13 @@ export default [
7274
},
7375
},
7476
},
77+
{
78+
files: ['**/*.spec.*'],
79+
80+
rules: {
81+
'@typescript-eslint/no-explicit-any': 'off',
82+
'@typescript-eslint/naming-convention': 'off',
83+
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'off',
84+
},
85+
},
7586
];

jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const config: Config.InitialOptions = {
77
collectCoverageFrom: ['./src/**/*.{ts,tsx,}'],
88
collectCoverage: true,
99
testTimeout: 30000, // 30s
10+
testEnvironment: 'jsdom',
1011
coverageThreshold: {
1112
global: {
1213
lines: 99,

package.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"@eslint/compat": "^1.2.2",
2020
"@eslint/eslintrc": "^3.1.0",
2121
"@eslint/js": "^9.14.0",
22-
"@ikscodes/browser-env": "~0.3.1",
2322
"@istanbuljs/nyc-config-typescript": "~0.1.3",
2423
"@peculiar/webcrypto": "^1.5.0",
2524
"@types/fs-extra": "^9.0.13",
@@ -33,22 +32,22 @@
3332
"@types/rimraf": "^3.0.2",
3433
"@types/tsc-watch": "^4.2.0",
3534
"@types/whatwg-url": "^6.4.0",
36-
"@typescript-eslint/eslint-plugin": "^7.18.0",
37-
"@typescript-eslint/parser": "7.12.0",
35+
"@typescript-eslint/eslint-plugin": "^8.29.1",
36+
"@typescript-eslint/parser": "^8.29.1",
3837
"auto": "^11.1.2",
3938
"babel-jest": "^29.7.0",
4039
"brotli-size": "^4.0.0",
4140
"chalk": "~4.1.2",
4241
"enquirer": "^2.3.6",
4342
"esbuild": "^0.14.13",
44-
"eslint": "9.14.0",
45-
"eslint-config-prettier": "^9.1.0",
46-
"eslint-import-resolver-typescript": "^3.6.3",
43+
"eslint": "^9.24.0",
44+
"eslint-config-prettier": "^10.1.1",
45+
"eslint-import-resolver-typescript": "^4.3.2",
4746
"eslint-plugin-import": "^2.31.0",
4847
"eslint-plugin-jsx-a11y": "^6.10.2",
49-
"eslint-plugin-prettier": "^5.2.1",
50-
"eslint-plugin-react": "^7.37.2",
51-
"eslint-plugin-react-hooks": "^4.6.0",
48+
"eslint-plugin-prettier": "^5.2.6",
49+
"eslint-plugin-react": "^7.37.5",
50+
"eslint-plugin-react-hooks": "^5.2.0",
5251
"execa": "~5.1.1",
5352
"fs-extra": "^10.0.0",
5453
"globals": "^15.12.0",
@@ -57,6 +56,7 @@
5756
"inquirer": "^8.1.2",
5857
"is-ci": "^3.0.0",
5958
"jest": "^29.7.0",
59+
"jest-environment-jsdom": "^29.7.0",
6060
"lerna": "8.0.2",
6161
"lint-staged": "^10.0.7",
6262
"lodash": "^4.17.21",
@@ -88,8 +88,7 @@
8888
]
8989
},
9090
"resolutions": {
91-
"@rollup/plugin-commonjs": "^17.0.0",
92-
"eslint": "9.14.0"
91+
"@rollup/plugin-commonjs": "^17.0.0"
9392
},
9493
"repository": "magiclabs/magic-js",
9594
"author": "Magic Labs <[email protected]>",
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// NOTE: This module is automatically included at the top of each test file.
2-
import browserEnv from '@ikscodes/browser-env';
32
import { mockConsole } from '../../../../scripts/utils/mock-console';
43

5-
browserEnv();
6-
74
beforeEach(() => {
85
mockConsole();
96
});

packages/@magic-ext/aptos/test/spec/aptos-extension.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import browserEnv from '@ikscodes/browser-env';
21
import { BCS, TxnBuilderTypes } from 'aptos';
32
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
43
import { AptosExtension } from '../../src';
54
import { AptosPayloadMethod } from '../../src/type';
5+
import { TextEncoder, TextDecoder } from 'util';
66

77
const APTOS_NODE_URL = 'https://fullnode.testnet.aptoslabs.com';
88

@@ -31,8 +31,12 @@ const MESSAGE_PAYLOAD = {
3131
nonce: 'random-nonce',
3232
};
3333

34+
beforeAll(() => {
35+
Object.assign(global, { TextEncoder, TextDecoder });
36+
})
37+
3438
beforeEach(() => {
35-
browserEnv.restore();
39+
jest.resetAllMocks();
3640
});
3741

3842
test('Construct GetAccount request with `aptos_getAccount`', async () => {

packages/@magic-ext/aptos/test/spec/magic-aptos-wallet.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import browserEnv from '@ikscodes/browser-env';
21
import { BCS, TxnBuilderTypes } from 'aptos';
32
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
43
import { AptosExtension, MagicAptosWallet } from '../../src';
@@ -33,7 +32,7 @@ const MOCK_ACCOUTN_INFO = {
3332
};
3433

3534
beforeEach(() => {
36-
browserEnv.restore();
35+
jest.resetAllMocks();
3736
});
3837

3938
test('Call connect()', async () => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"extends": "../../../../tsconfig.settings.test.json",
2+
"extends": "../../../../tsconfig.settings.test.json"
33
}

packages/@magic-ext/gdkms/test/setup.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// NOTE: This module is automatically included at the top of each test file.
2-
import browserEnv from '@ikscodes/browser-env';
32
import { Crypto } from '@peculiar/webcrypto';
43
import { mockConsole } from '../../../../scripts/utils/mock-console';
54

6-
browserEnv();
75
(window as any).crypto = new Crypto();
86

97
beforeEach(() => {

packages/@magic-ext/gdkms/test/spec/gdkms.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import browserEnv from '@ikscodes/browser-env';
21
import { MagicPayloadMethod } from '@magic-sdk/types';
32
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
43
import { GDKMSExtension } from '../../src';
54

65
beforeEach(() => {
7-
browserEnv.restore();
6+
jest.resetAllMocks();
87
});
98

109
test('Construct Encrypt Request with `magic_auth_encrypt_v1`', async () => {
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// NOTE: This module is automatically included at the top of each test file.
2-
import browserEnv from '@ikscodes/browser-env';
32
import { mockConsole } from '../../../../scripts/utils/mock-console';
43

5-
browserEnv();
6-
74
beforeEach(() => {
85
mockConsole();
96
});

packages/@magic-ext/harmony/test/spec/harmony.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import browserEnv from '@ikscodes/browser-env';
21
import { HarmonyPayloadMethod } from '../../src/types';
32
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
43
import { HarmonyExtension } from '../../src';
54

65
beforeEach(() => {
7-
browserEnv.restore();
6+
jest.resetAllMocks();
87
});
98

109
test('Sends params as payload', async () => {

packages/@magic-ext/kadena/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class KadenaExtension extends Extension.Internal<'kadena'> {
2929
}
3030

3131
public signTransaction(hash: string): Promise<SignatureWithPublicKey> {
32-
return this.request(this.utils.createJsonRpcRequestPayload(KadenaPayloadMethod.KadenaSignTransaction, [{ hash }]));
32+
return this.request<SignatureWithPublicKey>(this.utils.createJsonRpcRequestPayload(KadenaPayloadMethod.KadenaSignTransaction, [{ hash }]));
3333
}
3434

3535
public async signTransactionWithSpireKey(
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// NOTE: This module is automatically included at the top of each test file.
2-
import browserEnv from '@ikscodes/browser-env';
32
import { mockConsole } from '../../../../scripts/utils/mock-console';
43

5-
browserEnv();
6-
74
beforeEach(() => {
85
mockConsole();
96
});

packages/@magic-ext/kadena/test/spec/kadena.spec.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import browserEnv from '@ikscodes/browser-env';
21
import { KadenaPayloadMethod } from '../../src/types';
32
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
43
import { KadenaExtension } from '../../src';
54

65
beforeEach(() => {
7-
browserEnv.restore();
6+
jest.resetAllMocks();
87
});
98

109
test('signTransaction - Sends params as payload', () => {
@@ -13,7 +12,6 @@ test('signTransaction - Sends params as payload', () => {
1312
rpcUrl: '',
1413
chainId: '1',
1514
networkId: 'testnet04',
16-
network: 'testnet',
1715
createAccountsOnChain: true,
1816
}),
1917
]);
@@ -34,7 +32,6 @@ test('signTransactionWithSpireKey - Sends params as payload', () => {
3432
rpcUrl: '',
3533
chainId: '1',
3634
networkId: 'testnet04',
37-
network: 'testnet',
3835
createAccountsOnChain: true,
3936
}),
4037
]);
@@ -59,7 +56,6 @@ test('Generate JSON RPC request payload with method `kda_loginWithSpireKey`', ()
5956
rpcUrl: '',
6057
chainId: '1',
6158
networkId: 'testnet04',
62-
network: 'testnet',
6359
createAccountsOnChain: true,
6460
}),
6561
]);
@@ -77,7 +73,6 @@ test('Generate JSON RPC request payload with method `kda_getUserInfo`', () => {
7773
rpcUrl: '',
7874
chainId: '1',
7975
networkId: 'testnet04',
80-
network: 'testnet',
8176
createAccountsOnChain: true,
8277
}),
8378
]);

packages/@magic-ext/sui/test/setup.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// NOTE: This module is automatically included at the top of each test file.
2-
import browserEnv from '@ikscodes/browser-env';
32
import { mockConsole } from '../../../../scripts/utils/mock-console';
43

5-
browserEnv();
6-
74
beforeEach(() => {
85
mockConsole();
96
});

packages/@magic-ext/sui/test/spec/sui.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import browserEnv from '@ikscodes/browser-env';
21
import { SuiExtension } from '../../src/index';
32
import { SuiPayloadMethod } from '../../src/types';
43
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
54

65
beforeEach(() => {
7-
browserEnv.restore();
6+
jest.resetAllMocks();
87
});
98

109
test('Sends params as payload', async () => {

packages/@magic-ext/web3modal-ethers5/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class Web3ModalExtension extends Extension.Internal<'web3modal'> {
4343
this.sdk.thirdPartyWallets.isConnected = Boolean(localStorage.getItem(LocalStorageKeys.ADDRESS));
4444
this.sdk.thirdPartyWallets.eventListeners.push({
4545
event: ThirdPartyWalletEvents.Web3ModalSelected,
46-
callback: async (payloadId) => {
46+
callback: async payloadId => {
4747
await this.connectToWeb3modal(payloadId);
4848
},
4949
});
@@ -105,7 +105,7 @@ export class Web3ModalExtension extends Extension.Internal<'web3modal'> {
105105
});
106106

107107
// Listen for modal close before user connects wallet
108-
const unsubscribeFromModalEvents = modal.subscribeEvents((event) => {
108+
const unsubscribeFromModalEvents = modal.subscribeEvents(event => {
109109
if (event.data.event === 'MODAL_CLOSE') {
110110
unsubscribeFromModalEvents();
111111
unsubscribeFromProviderEvents();
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
// NOTE: This module is automatically included at the top of each test file.
2-
import browserEnv from '@ikscodes/browser-env';
3-
4-
browserEnv();

packages/@magic-ext/web3modal-ethers5/test/spec/accountsChanged.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
import browserEnv from '@ikscodes/browser-env';
21
import { Web3ModalExtension } from '../../src/index';
32
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
43
import { mockLocalStorage } from '../../../../@magic-sdk/provider/test/mocks';
54

65
jest.mock('@web3modal/ethers5', () => ({
76
Web3Modal: jest.fn(),
87
defaultConfig: jest.fn(),
9-
createWeb3Modal: jest.fn(() => {
8+
createWeb3Modal: () => {
109
return {
1110
getIsConnected: jest.fn(),
1211
getAddress: jest.fn(() => '0x123'),
1312
getChainId: jest.fn(() => 1),
1413
subscribeProvider: jest.fn(),
1514
};
16-
}),
15+
},
1716
}));
1817

1918
beforeEach(() => {
20-
browserEnv.restore();
19+
jest.resetAllMocks();
2120
mockLocalStorage();
2221
});
2322

packages/@magic-ext/web3modal-ethers5/test/spec/chainChanged.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
import browserEnv from '@ikscodes/browser-env';
21
import { Web3ModalExtension } from '../../src/index';
32
import { createMagicSDKWithExtension } from '../../../../@magic-sdk/provider/test/factories';
43
import { mockLocalStorage } from '../../../../@magic-sdk/provider/test/mocks';
54

65
jest.mock('@web3modal/ethers5', () => ({
76
Web3Modal: jest.fn(),
87
defaultConfig: jest.fn(),
9-
createWeb3Modal: jest.fn(() => {
8+
createWeb3Modal: () => {
109
return {
1110
getIsConnected: jest.fn(),
1211
getAddress: jest.fn(() => '0x123'),
1312
getChainId: jest.fn(() => 1),
1413
subscribeProvider: jest.fn(),
1514
};
16-
}),
15+
},
1716
}));
1817

1918
beforeEach(() => {
20-
browserEnv.restore();
19+
jest.resetAllMocks();
2120
mockLocalStorage();
2221
});
2322

0 commit comments

Comments
 (0)