Skip to content

Commit

Permalink
fix: Fix ESLint Jest configuration
Browse files Browse the repository at this point in the history
The ESLint configuration for Jest has been updated to include all Jest
modules, excluding a few with lint errors that will be addressed in a
later PR.

Relates to #27544
  • Loading branch information
Gudahtt committed Oct 1, 2024
1 parent 5639952 commit aad80ff
Show file tree
Hide file tree
Showing 37 changed files with 500 additions and 458 deletions.
66 changes: 42 additions & 24 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,32 +307,46 @@ module.exports = {
{
files: [
'**/__snapshots__/*.snap',
'app/scripts/controllers/app-state.test.js',
'app/scripts/controllers/mmi-controller.test.ts',
'app/scripts/metamask-controller.actions.test.js',
'app/scripts/detect-multiple-instances.test.js',
'app/scripts/controllers/bridge.test.ts',
'app/scripts/controllers/swaps/**/*.test.js',
'app/scripts/controllers/swaps/**/*.test.ts',
'app/scripts/controllers/metametrics.test.js',
'app/scripts/controllers/permissions/**/*.test.js',
'app/scripts/controllers/preferences.test.js',
'app/scripts/lib/**/*.test.js',
'app/scripts/metamask-controller.test.js',
'app/scripts/migrations/*.test.js',
'app/scripts/platforms/*.test.js',
'development/**/*.test.js',
'development/**/*.test.ts',
'shared/**/*.test.js',
'shared/**/*.test.ts',
'test/helpers/*.js',
'**/__mocks__/*.js',
'test/helpers/setup-after-helper.js',
'test/helpers/setup-helper.js',
'test/jest/*.js',
'test/lib/timer-helpers.js',
'test/e2e/helpers.test.js',
'test/unit-global/*.test.js',
'ui/**/*.test.js',
'ui/__mocks__/*.js',
'shared/lib/error-utils.test.js',
'*.test.{js,ts,tsx}',
],
// TODO: Fix lint errors in these files and remove them from this list
// Tracked by https://github.com/MetaMask/metamask-extension/issues/27544
excludedFiles: [
'app/scripts/controllers/decrypt-message.test.ts',
'app/scripts/controllers/metametrics-data-deletion/metametrics-data-deletion.test.ts',
'app/scripts/lib/transaction/util.test.ts',
'app/scripts/lib/snap-keyring/snap-keyring.test.ts',
'app/scripts/lib/stream-utils.test.ts',
'app/scripts/migrations/110.test.ts',
'app/scripts/migrations/119.test.ts',
'app/scripts/migrations/121.test.ts',
'app/scripts/migrations/127.test.ts',
'test/integration/confirmations/transactions/alerts.test.tsx',
'test/integration/confirmations/transactions/contract-interaction.test.tsx',
'test/integration/confirmations/transactions/erc20-approve.test.tsx',
'test/integration/confirmations/transactions/erc721-approve.test.tsx',
'ui/components/app/currency-input/hooks/useStateWithFirstTouch.test.tsx',
'ui/components/app/name/name.test.tsx',
'ui/components/component-library/avatar-icon/avatar-icon.test.tsx',
'ui/components/component-library/avatar-network/avatar-network.test.tsx',
'ui/components/component-library/avatar-token/avatar-token.test.tsx',
'ui/components/component-library/select-wrapper/select-wrapper.test.tsx',
'ui/components/multichain/asset-picker-amount/swappable-currency-input/swappable-currency-input.test.tsx',
'ui/components/multichain/pages/send/components/recipient.test.tsx',
'ui/components/multichain/pages/send/components/your-accounts.test.tsx',
'ui/ducks/locale/locale.test.ts',
'ui/pages/confirmations/components/confirm/header/wallet-initiated-header.test.tsx',
'ui/pages/confirmations/components/simulation-details/useSimulationMetrics.test.ts',
'ui/pages/confirmations/hooks/useConfirmationAlertMetrics.test.ts',
'ui/pages/confirmations/utils/confirm.test.ts',
'ui/pages/snap-account-redirect/create-snap-redirect.test.tsx',
'ui/selectors/institutional/selectors.test.ts',
'ui/selectors/metamask-notifications/authentication.test.ts',
],
extends: ['@metamask/eslint-config-jest'],
parserOptions: {
Expand Down Expand Up @@ -369,6 +383,10 @@ module.exports = {
ignore: ['describe'],
},
],

// TODO: Re-enable this rule
// Tracked by https://github.com/MetaMask/metamask-extension/issues/27544
'jest/prefer-strict-equal': 'off',
},
},
/**
Expand Down
53 changes: 25 additions & 28 deletions app/scripts/controllers/decrypt-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('DecryptMessageController', () => {
it('should clear unapproved messages', () => {
decryptMessageController.clearUnapproved();
expect(decryptMessageController.state).toStrictEqual(getDefaultState());
expect(decryptMessageManagerMock.update).toBeCalledTimes(1);
expect(decryptMessageManagerMock.update).toHaveBeenCalledTimes(1);
});
it('should add unapproved messages', async () => {
await decryptMessageController.newRequestDecryptMessage(
Expand All @@ -152,13 +152,12 @@ describe('DecryptMessageController', () => {
undefined as any,
);

expect(decryptMessageManagerMock.addUnapprovedMessageAsync).toBeCalledTimes(
1,
);
expect(decryptMessageManagerMock.addUnapprovedMessageAsync).toBeCalledWith(
messageMock,
undefined,
);
expect(
decryptMessageManagerMock.addUnapprovedMessageAsync,
).toHaveBeenCalledTimes(1);
expect(
decryptMessageManagerMock.addUnapprovedMessageAsync,
).toHaveBeenCalledWith(messageMock, undefined);
});

it('should decrypt message', async () => {
Expand All @@ -182,23 +181,21 @@ describe('DecryptMessageController', () => {
messageToDecrypt,
);

expect(decryptMessageManagerMock.approveMessage).toBeCalledTimes(1);
expect(decryptMessageManagerMock.approveMessage).toBeCalledWith(
expect(decryptMessageManagerMock.approveMessage).toHaveBeenCalledTimes(1);
expect(decryptMessageManagerMock.approveMessage).toHaveBeenCalledWith(
messageToDecrypt,
);
expect(decryptMessageActionCallbackMock).toBeCalledTimes(1);
expect(decryptMessageActionCallbackMock).toBeCalledWith(
expect(decryptMessageActionCallbackMock).toHaveBeenCalledTimes(1);
expect(decryptMessageActionCallbackMock).toHaveBeenCalledWith(
'KeyringController:decryptMessage',
messageToDecrypt,
);
expect(decryptMessageManagerMock.setMessageStatusAndResult).toBeCalledTimes(
1,
);
expect(decryptMessageManagerMock.setMessageStatusAndResult).toBeCalledWith(
messageIdMock,
'decryptedMessage',
'decrypted',
);
expect(
decryptMessageManagerMock.setMessageStatusAndResult,
).toHaveBeenCalledTimes(1);
expect(
decryptMessageManagerMock.setMessageStatusAndResult,
).toHaveBeenCalledWith(messageIdMock, 'decryptedMessage', 'decrypted');
expect(result).toBe(mockExtState);
});

Expand Down Expand Up @@ -252,8 +249,8 @@ describe('DecryptMessageController', () => {
messageToDecrypt,
);

expect(decryptMessageManagerMock.setResult).toBeCalledTimes(1);
expect(decryptMessageManagerMock.setResult).toBeCalledWith(
expect(decryptMessageManagerMock.setResult).toHaveBeenCalledTimes(1);
expect(decryptMessageManagerMock.setResult).toHaveBeenCalledWith(
messageMock.metamaskId,
'decryptedMessage',
);
Expand Down Expand Up @@ -281,8 +278,8 @@ describe('DecryptMessageController', () => {
messageIdMock,
);

expect(decryptMessageManagerMock.rejectMessage).toBeCalledTimes(1);
expect(decryptMessageManagerMock.rejectMessage).toBeCalledWith(
expect(decryptMessageManagerMock.rejectMessage).toHaveBeenCalledTimes(1);
expect(decryptMessageManagerMock.rejectMessage).toHaveBeenCalledWith(
messageIdMock,
);
expect(result).toBe(mockExtState);
Expand All @@ -297,12 +294,12 @@ describe('DecryptMessageController', () => {

await decryptMessageController.rejectUnapproved('reason to cancel');

expect(decryptMessageManagerMock.rejectMessage).toBeCalledTimes(1);
expect(decryptMessageManagerMock.rejectMessage).toBeCalledWith(
expect(decryptMessageManagerMock.rejectMessage).toHaveBeenCalledTimes(1);
expect(decryptMessageManagerMock.rejectMessage).toHaveBeenCalledWith(
messageIdMock,
);
expect(metricsEventMock).toBeCalledTimes(1);
expect(metricsEventMock).toBeCalledWith({
expect(metricsEventMock).toHaveBeenCalledTimes(1);
expect(metricsEventMock).toHaveBeenCalledWith({
event: 'reason to cancel',
category: MetaMetricsEventCategory.Messages,
properties: {
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/controllers/encryption-public-key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ describe('EncryptionPublicKeyController', () => {
addressMock,
requestMock,
),
).rejects.toThrowError(
).rejects.toThrow(
`${keyringName} does not support eth_getEncryptionPublicKey.`,
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const {
const { processNotification } = NotificationServicesController.Processors;

describe('notification-message tests', () => {
test('displays erc20 sent notification', () => {
it('displays erc20 sent notification', () => {
const notification = processNotification(createMockNotificationERC20Sent());
const result = createNotificationMessage(notification);

expect(result?.title).toBe('Funds sent');
expect(result?.description).toContain('You successfully sent 4.96K USDC');
});

test('displays erc20 received notification', () => {
it('displays erc20 received notification', () => {
const notification = processNotification(
createMockNotificationERC20Received(),
);
Expand All @@ -40,15 +40,15 @@ describe('notification-message tests', () => {
expect(result?.description).toContain('You received 8.38B SHIB');
});

test('displays eth/native sent notification', () => {
it('displays eth/native sent notification', () => {
const notification = processNotification(createMockNotificationEthSent());
const result = createNotificationMessage(notification);

expect(result?.title).toBe('Funds sent');
expect(result?.description).toContain('You successfully sent 0.005 ETH');
});

test('displays eth/native received notification', () => {
it('displays eth/native received notification', () => {
const notification = processNotification(
createMockNotificationEthReceived(),
);
Expand All @@ -58,7 +58,7 @@ describe('notification-message tests', () => {
expect(result?.description).toContain('You received 808 ETH');
});

test('displays metamask swap completed notification', () => {
it('displays metamask swap completed notification', () => {
const notification = processNotification(
createMockNotificationMetaMaskSwapsCompleted(),
);
Expand All @@ -68,7 +68,7 @@ describe('notification-message tests', () => {
expect(result?.description).toContain('Your MetaMask Swap was successful');
});

test('displays erc721 sent notification', () => {
it('displays erc721 sent notification', () => {
const notification = processNotification(
createMockNotificationERC721Sent(),
);
Expand All @@ -78,7 +78,7 @@ describe('notification-message tests', () => {
expect(result?.description).toContain('You have successfully sent an NFT');
});

test('displays erc721 received notification', () => {
it('displays erc721 received notification', () => {
const notification = processNotification(
createMockNotificationERC721Received(),
);
Expand All @@ -88,7 +88,7 @@ describe('notification-message tests', () => {
expect(result?.description).toContain('You received new NFTs');
});

test('displays erc1155 sent notification', () => {
it('displays erc1155 sent notification', () => {
const notification = processNotification(
createMockNotificationERC1155Sent(),
);
Expand All @@ -98,7 +98,7 @@ describe('notification-message tests', () => {
expect(result?.description).toContain('You have successfully sent an NFT');
});

test('displays erc1155 received notification', () => {
it('displays erc1155 received notification', () => {
const notification = processNotification(
createMockNotificationERC1155Received(),
);
Expand All @@ -108,7 +108,7 @@ describe('notification-message tests', () => {
expect(result?.description).toContain('You received new NFTs');
});

test('displays rocketpool stake completed notification', () => {
it('displays rocketpool stake completed notification', () => {
const notification = processNotification(
createMockNotificationRocketPoolStakeCompleted(),
);
Expand All @@ -120,7 +120,7 @@ describe('notification-message tests', () => {
);
});

test('displays rocketpool unstake completed notification', () => {
it('displays rocketpool unstake completed notification', () => {
const notification = processNotification(
createMockNotificationRocketPoolUnStakeCompleted(),
);
Expand All @@ -132,7 +132,7 @@ describe('notification-message tests', () => {
);
});

test('displays lido stake completed notification', () => {
it('displays lido stake completed notification', () => {
const notification = processNotification(
createMockNotificationLidoStakeCompleted(),
);
Expand All @@ -142,7 +142,7 @@ describe('notification-message tests', () => {
expect(result?.description).toContain('Your Lido stake was successful');
});

test('displays lido stake ready to be withdrawn notification', () => {
it('displays lido stake ready to be withdrawn notification', () => {
const notification = processNotification(
createMockNotificationLidoReadyToBeWithdrawn(),
);
Expand All @@ -154,7 +154,7 @@ describe('notification-message tests', () => {
);
});

test('displays lido withdrawal requested notification', () => {
it('displays lido withdrawal requested notification', () => {
const notification = processNotification(
createMockNotificationLidoWithdrawalRequested(),
);
Expand All @@ -166,7 +166,7 @@ describe('notification-message tests', () => {
);
});

test('displays lido withdrawal completed notification', () => {
it('displays lido withdrawal completed notification', () => {
const notification = processNotification(
createMockNotificationLidoWithdrawalCompleted(),
);
Expand Down
4 changes: 1 addition & 3 deletions app/scripts/lib/AbstractPetnamesBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ describe('AbstractPetnamesBridge', () => {
const petnamesListener = messenger.subscribe.mock
.calls[0][1] as () => void;
petnamesListener();
}).toThrowError(
'updateSourceEntry must be overridden for two-way bridges',
);
}).toThrow('updateSourceEntry must be overridden for two-way bridges');
});

it('calls updateSourceEntry with ADDED entry when Petnames entry is added', () => {
Expand Down
14 changes: 7 additions & 7 deletions app/scripts/lib/WeakRefObjectMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('WeakDomainProxyMap', () => {

it('iterates over entries correctly', () => {
const entries = Array.from(map.entries());
expect(entries.length).toBe(2);
expect(entries).toHaveLength(2);
expect(entries).toEqual(
expect.arrayContaining([
['key1', { objKey1: { detail: 'value1' } }],
Expand All @@ -72,13 +72,13 @@ describe('WeakDomainProxyMap', () => {

it('iterates over keys correctly', () => {
const keys = Array.from(map.keys());
expect(keys.length).toBe(2);
expect(keys).toHaveLength(2);
expect(keys).toEqual(expect.arrayContaining(['key1', 'key2']));
});

it('iterates over values correctly', () => {
const values = Array.from(map.values());
expect(values.length).toBe(2);
expect(values).toHaveLength(2);
expect(values).toEqual(
expect.arrayContaining([
{ objKey1: { detail: 'value1' } },
Expand All @@ -91,7 +91,7 @@ describe('WeakDomainProxyMap', () => {
const mockCallback = jest.fn();
map.forEach(mockCallback);

expect(mockCallback.mock.calls.length).toBe(2);
expect(mockCallback.mock.calls).toHaveLength(2);
expect(mockCallback).toHaveBeenCalledWith(
{ objKey1: { detail: 'value1' } },
'key1',
Expand All @@ -106,9 +106,9 @@ describe('WeakDomainProxyMap', () => {

it('handles empty map in iterations', () => {
const emptyMap = new WeakRefObjectMap<Record<string, object>>();
expect(Array.from(emptyMap.entries()).length).toBe(0);
expect(Array.from(emptyMap.keys()).length).toBe(0);
expect(Array.from(emptyMap.values()).length).toBe(0);
expect(Array.from(emptyMap.entries())).toHaveLength(0);
expect(Array.from(emptyMap.keys())).toHaveLength(0);
expect(Array.from(emptyMap.values())).toHaveLength(0);

const mockCallback = jest.fn();
emptyMap.forEach(mockCallback);
Expand Down
Loading

0 comments on commit aad80ff

Please sign in to comment.