From f6acedb6cc72f79f043317e5e1390e3cd62c05f7 Mon Sep 17 00:00:00 2001 From: Norbert Elter <72046715+itsyoboieltr@users.noreply.github.com> Date: Mon, 24 Jun 2024 17:41:42 +0200 Subject: [PATCH 1/7] feat: Convert Metamask controller actions tests from mocha to jest (#25336) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25336?quickstart=1) This PR converts `app/scripts/metamask-controller.actions.test.js` from mocha to jest. In particular, replaces instances of `assert` with `expect`, and removes `sinon` and uses `jest`'s mocking capabilities in its place. The `jest.config.js` was updated to include `app/scripts/metamask-controller.actions.test.js` in the `testMatch` array. The `.mocharc.js` was updated to ignore the test. ## **Related issues** Fixes: #19355 ## **Manual testing steps** 1. Running `yarn jest -- app/scripts/metamask-controller.actions.test.js` and seeing all tests pass 2. Running `yarn test:unit:mocha` and not seeing the metamask controller actions tests run. ## **Screenshots/Recordings** Not applicable ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- .circleci/config.yml | 21 --- .eslintrc.js | 2 + .mocharc.js | 1 + .../metamask-controller.actions.test.js | 173 +++++++++--------- jest.config.js | 1 + package.json | 7 +- yarn.lock | 42 +---- 7 files changed, 93 insertions(+), 154 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ee9633490b0d..86ed5e0d3aa9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -209,9 +209,6 @@ workflows: - /^Version-v(\d+)[.](\d+)[.](\d+)/ requires: - prep-build - - test-unit-mocha: - requires: - - prep-deps - test-unit-jest-main: requires: - prep-deps @@ -222,7 +219,6 @@ workflows: requires: - test-unit-jest-main - test-unit-jest-development - - test-unit-mocha - test-unit-global: requires: - prep-deps @@ -269,7 +265,6 @@ workflows: - test-unit-jest-main - test-unit-jest-development - test-unit-global - - test-unit-mocha - upload-and-validate-coverage - validate-source-maps - validate-source-maps-beta @@ -1594,22 +1589,6 @@ jobs: git config user.email metamaskbot@users.noreply.github.com yarn ts-migration:dashboard:deploy - test-unit-mocha: - executor: node-browsers-small - steps: - - run: *shallow-git-clone - - run: sudo corepack enable - - attach_workspace: - at: . - - run: - name: test:coverage:mocha - command: yarn test:coverage:mocha - - persist_to_workspace: - root: . - paths: - - .nyc_output - - coverage - test-unit-jest-development: executor: node-browsers-small steps: diff --git a/.eslintrc.js b/.eslintrc.js index 73e3ec7e5214..2fa4b8cf9846 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -269,6 +269,7 @@ module.exports = { excludedFiles: [ 'app/scripts/controllers/app-state.test.js', 'app/scripts/controllers/mmi-controller.test.js', + 'app/scripts/metamask-controller.actions.test.js', 'app/scripts/detect-multiple-instances.test.js', 'app/scripts/controllers/swaps.test.js', 'app/scripts/controllers/metametrics.test.js', @@ -303,6 +304,7 @@ module.exports = { '**/__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/swaps.test.js', 'app/scripts/controllers/metametrics.test.js', diff --git a/.mocharc.js b/.mocharc.js index 59d4e01f8735..890fca78e6b9 100644 --- a/.mocharc.js +++ b/.mocharc.js @@ -8,6 +8,7 @@ module.exports = { './app/scripts/controllers/app-state.test.js', './app/scripts/controllers/permissions/**/*.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/swaps.test.js', './app/scripts/controllers/metametrics.test.js', diff --git a/app/scripts/metamask-controller.actions.test.js b/app/scripts/metamask-controller.actions.test.js index 8d6bc1cfcf5a..28dcc00c35a9 100644 --- a/app/scripts/metamask-controller.actions.test.js +++ b/app/scripts/metamask-controller.actions.test.js @@ -1,6 +1,6 @@ -import { strict as assert } from 'assert'; -import sinon from 'sinon'; -import proxyquire from 'proxyquire'; +/** + * @jest-environment node + */ import { ListNames, METAMASK_STALELIST_URL, @@ -13,6 +13,7 @@ import { ApprovalRequestNotFoundError } from '@metamask/approval-controller'; import { PermissionsRequestNotFoundError } from '@metamask/permission-controller'; import nock from 'nock'; import mockEncryptor from '../../test/lib/mock-encryptor'; +import MetaMaskController from './metamask-controller'; const { Ganache } = require('../../test/e2e/seeder/ganache'); @@ -31,13 +32,23 @@ const browserPolyfillMock = { }, storage: { local: { - get: sinon.stub().resolves({}), - set: sinon.stub().resolves(), + get: jest.fn().mockReturnValue({}), + set: jest.fn(), }, }, }; let loggerMiddlewareMock; +const initializeMockMiddlewareLog = () => { + loggerMiddlewareMock = { + requests: [], + responses: [], + }; +}; +const tearDownMockMiddlewareLog = () => { + loggerMiddlewareMock = undefined; +}; + const createLoggerMiddlewareMock = () => (req, res, next) => { if (loggerMiddlewareMock) { loggerMiddlewareMock.requests.push(req); @@ -49,20 +60,16 @@ const createLoggerMiddlewareMock = () => (req, res, next) => { } next(); }; +jest.mock('./lib/createLoggerMiddleware', () => createLoggerMiddlewareMock); const TEST_SEED = 'debris dizzy just program just float decrease vacant alarm reduce speak stadium'; -const MetaMaskController = proxyquire('./metamask-controller', { - './lib/createLoggerMiddleware': { default: createLoggerMiddlewareMock }, -}).default; - describe('MetaMaskController', function () { let metamaskController; - const sandbox = sinon.createSandbox(); const noop = () => undefined; - before(async function () { + beforeAll(async function () { await ganacheServer.start(); }); @@ -106,26 +113,26 @@ describe('MetaMaskController', function () { browser: browserPolyfillMock, infuraProjectId: 'foo', }); + initializeMockMiddlewareLog(); }); afterEach(function () { - sandbox.restore(); + jest.restoreAllMocks(); nock.cleanAll(); + tearDownMockMiddlewareLog(); }); - after(async function () { + afterAll(async function () { await ganacheServer.quit(); }); describe('Phishing Detection Mock', function () { it('should be updated to use v1 of the API', function () { // Update the fixture above if this test fails - assert.equal( - METAMASK_STALELIST_URL, + expect(METAMASK_STALELIST_URL).toStrictEqual( 'https://phishing-detection.api.cx.metamask.io/v1/stalelist', ); - assert.equal( - METAMASK_HOTLIST_DIFF_URL, + expect(METAMASK_HOTLIST_DIFF_URL).toStrictEqual( 'https://phishing-detection.api.cx.metamask.io/v1/diffsSince', ); }); @@ -138,21 +145,21 @@ describe('MetaMaskController', function () { metamaskController.addNewAccount(1), metamaskController.addNewAccount(1), ]); - assert.equal(addNewAccountResult1, addNewAccountResult2); + expect(addNewAccountResult1).toStrictEqual(addNewAccountResult2); }); it('two successive calls with same accountCount give same result', async function () { await metamaskController.createNewVaultAndKeychain('test@123'); const addNewAccountResult1 = await metamaskController.addNewAccount(1); const addNewAccountResult2 = await metamaskController.addNewAccount(1); - assert.equal(addNewAccountResult1, addNewAccountResult2); + expect(addNewAccountResult1).toStrictEqual(addNewAccountResult2); }); it('two successive calls with different accountCount give different results', async function () { await metamaskController.createNewVaultAndKeychain('test@123'); const addNewAccountResult1 = await metamaskController.addNewAccount(1); const addNewAccountResult2 = await metamaskController.addNewAccount(2); - assert.notEqual(addNewAccountResult1, addNewAccountResult2); + expect(addNewAccountResult1).not.toStrictEqual(addNewAccountResult2); }); }); @@ -182,7 +189,7 @@ describe('MetaMaskController', function () { ); }), ]); - assert.deepEqual(keyringControllerState1, keyringControllerState2); + expect(keyringControllerState1).toStrictEqual(keyringControllerState2); }); }); @@ -196,7 +203,7 @@ describe('MetaMaskController', function () { 'test@123', TEST_SEED, ); - assert.deepEqual(result1, result2); + expect(result1).toStrictEqual(result2); }); }); @@ -208,16 +215,16 @@ describe('MetaMaskController', function () { const result2 = await metamaskController.createNewVaultAndKeychain( 'test@123', ); - assert.notEqual(result1, undefined); - assert.deepEqual(result1, result2); + expect(result1).not.toStrictEqual(undefined); + expect(result1).toStrictEqual(result2); }); }); describe('#setLocked', function () { it('should lock the wallet', async function () { const { isUnlocked, keyrings } = await metamaskController.setLocked(); - assert(!isUnlocked); - assert.deepEqual(keyrings, []); + expect(isUnlocked).toStrictEqual(false); + expect(keyrings).toStrictEqual([]); }); }); @@ -227,38 +234,26 @@ describe('MetaMaskController', function () { const decimals = 18; it('two parallel calls with same token details give same result', async function () { - const supportsInterfaceStub = sinon - .stub() - .returns(Promise.resolve(false)); - sinon - .stub(metamaskController.tokensController, '_createEthersContract') - .callsFake(() => - Promise.resolve({ supportsInterface: supportsInterfaceStub }), - ); + const supportsInterfaceStub = jest.fn().mockResolvedValue(false); + jest + .spyOn(metamaskController.tokensController, '_createEthersContract') + .mockResolvedValue({ supportsInterface: supportsInterfaceStub }); const [token1, token2] = await Promise.all([ metamaskController.getApi().addToken({ address, symbol, decimals }), metamaskController.getApi().addToken({ address, symbol, decimals }), ]); - assert.deepEqual(token1, token2); + expect(token1).toStrictEqual(token2); }); it('networkClientId is used when provided', async function () { - const supportsInterfaceStub = sinon - .stub() - .returns(Promise.resolve(false)); - sinon - .stub(metamaskController.tokensController, '_createEthersContract') - .callsFake(() => - Promise.resolve({ supportsInterface: supportsInterfaceStub }), - ); - sinon - .stub(metamaskController.controllerMessenger, 'call') - .callsFake(() => ({ - configuration: { - chainId: '0xa', - }, - })); + const supportsInterfaceStub = jest.fn().mockResolvedValue(false); + jest + .spyOn(metamaskController.tokensController, '_createEthersContract') + .mockResolvedValue({ supportsInterface: supportsInterfaceStub }); + const callSpy = jest + .spyOn(metamaskController.controllerMessenger, 'call') + .mockReturnValue({ configuration: { chainId: '0xa' } }); await metamaskController.getApi().addToken({ address, @@ -266,10 +261,10 @@ describe('MetaMaskController', function () { decimals, networkClientId: 'networkClientId1', }); - assert.deepStrictEqual( - metamaskController.controllerMessenger.call.getCall(0).args, - ['NetworkController:getNetworkClientById', 'networkClientId1'], - ); + expect(callSpy.mock.calls[0]).toStrictEqual([ + 'NetworkController:getNetworkClientById', + 'networkClientId1', + ]); }); }); @@ -281,8 +276,9 @@ describe('MetaMaskController', function () { throw error; }, }; - // Line below will not throw error, in case it throws this test case will fail. - metamaskController.removePermissionsFor({ subject: 'test_subject' }); + expect(() => + metamaskController.removePermissionsFor({ subject: 'test_subject' }), + ).not.toThrow(error); }); it('should propagate Error other than PermissionsRequestNotFoundError', function () { @@ -292,9 +288,9 @@ describe('MetaMaskController', function () { throw error; }, }; - assert.throws(() => { - metamaskController.removePermissionsFor({ subject: 'test_subject' }); - }, error); + expect(() => + metamaskController.removePermissionsFor({ subject: 'test_subject' }), + ).toThrow(error); }); }); @@ -306,8 +302,9 @@ describe('MetaMaskController', function () { throw error; }, }; - // Line below will not throw error, in case it throws this test case will fail. - metamaskController.rejectPermissionsRequest('DUMMY_ID'); + expect(() => + metamaskController.rejectPermissionsRequest('DUMMY_ID'), + ).not.toThrow(error); }); it('should propagate Error other than PermissionsRequestNotFoundError', function () { @@ -317,9 +314,9 @@ describe('MetaMaskController', function () { throw error; }, }; - assert.throws(() => { - metamaskController.rejectPermissionsRequest('DUMMY_ID'); - }, error); + expect(() => + metamaskController.rejectPermissionsRequest('DUMMY_ID'), + ).toThrow(error); }); }); @@ -331,8 +328,9 @@ describe('MetaMaskController', function () { throw error; }, }; - // Line below will not throw error, in case it throws this test case will fail. - metamaskController.acceptPermissionsRequest('DUMMY_ID'); + expect(() => + metamaskController.acceptPermissionsRequest('DUMMY_ID'), + ).not.toThrow(error); }); it('should propagate Error other than PermissionsRequestNotFoundError', function () { @@ -342,9 +340,9 @@ describe('MetaMaskController', function () { throw error; }, }; - assert.throws(() => { - metamaskController.acceptPermissionsRequest('DUMMY_ID'); - }, error); + expect(() => + metamaskController.acceptPermissionsRequest('DUMMY_ID'), + ).toThrow(error); }); }); @@ -356,25 +354,21 @@ describe('MetaMaskController', function () { throw error; }, }; - // Line below will not throw error, in case it throws this test case will fail. - await metamaskController.resolvePendingApproval( - 'DUMMY_ID', - 'DUMMY_VALUE', - ); + await expect( + metamaskController.resolvePendingApproval('DUMMY_ID', 'DUMMY_VALUE'), + ).resolves.not.toThrow(error); }); - it('should propagate Error other than ApprovalRequestNotFoundError', function () { + it('should propagate Error other than ApprovalRequestNotFoundError', async function () { const error = new Error(); metamaskController.approvalController = { accept: () => { throw error; }, }; - assert.rejects( - () => - metamaskController.resolvePendingApproval('DUMMY_ID', 'DUMMY_VALUE'), - error, - ); + await expect( + metamaskController.resolvePendingApproval('DUMMY_ID', 'DUMMY_VALUE'), + ).rejects.toThrow(error); }); }); @@ -386,12 +380,13 @@ describe('MetaMaskController', function () { throw error; }, }; - // Line below will not throw error, in case it throws this test case will fail. - metamaskController.rejectPendingApproval('DUMMY_ID', { - code: 1, - message: 'DUMMY_MESSAGE', - data: 'DUMMY_DATA', - }); + expect(() => + metamaskController.rejectPendingApproval('DUMMY_ID', { + code: 1, + message: 'DUMMY_MESSAGE', + data: 'DUMMY_DATA', + }), + ).not.toThrow(error); }); it('should propagate Error other than ApprovalRequestNotFoundError', function () { @@ -401,13 +396,13 @@ describe('MetaMaskController', function () { throw error; }, }; - assert.throws(() => { + expect(() => metamaskController.rejectPendingApproval('DUMMY_ID', { code: 1, message: 'DUMMY_MESSAGE', data: 'DUMMY_DATA', - }); - }, error); + }), + ).toThrow(error); }); }); }); diff --git a/jest.config.js b/jest.config.js index ee0ad87af9d2..1d6f86938950 100644 --- a/jest.config.js +++ b/jest.config.js @@ -58,6 +58,7 @@ module.exports = { '/app/scripts/controllers/push-platform-notifications/**/*.test.ts', '/app/scripts/controllers/user-storage/**/*.test.ts', '/app/scripts/controllers/metamask-notifications/**/*.test.ts', + '/app/scripts/metamask-controller.actions.test.js', '/app/scripts/detect-multiple-instances.test.js', '/app/scripts/controllers/swaps.test.js', '/app/scripts/controllers/metametrics.test.js', diff --git a/package.json b/package.json index 3024d90d35ab..722e82bae00b 100644 --- a/package.json +++ b/package.json @@ -38,11 +38,10 @@ "dapp-chain": "GANACHE_ARGS='-b 2' concurrently -k -n ganache,dapp -p '[{time}][{name}]' 'yarn ganache:start' 'sleep 5 && yarn dapp'", "forwarder": "node ./development/static-server.js ./node_modules/@metamask/forwarder/dist/ --port 9010", "dapp-forwarder": "concurrently -k -n forwarder,dapp -p '[{time}][{name}]' 'yarn forwarder' 'yarn dapp'", - "test:unit": "node ./test/run-unit-tests.js --mocha --jestGlobal --jestDev", + "test:unit": "node ./test/run-unit-tests.js --jestGlobal --jestDev", "test:unit:jest": "node ./test/run-unit-tests.js --jestGlobal --jestDev", "test:unit:jest:watch": "node --inspect ./node_modules/.bin/jest --watch", "test:unit:global": "mocha test/unit-global/*.test.js", - "test:unit:mocha": "node ./test/run-unit-tests.js --mocha", "test:e2e:chrome": "SELENIUM_BROWSER=chrome node test/e2e/run-all.js", "test:e2e:chrome:mmi": "SELENIUM_BROWSER=chrome node test/e2e/run-all.js --mmi", "test:e2e:chrome:flask": "SELENIUM_BROWSER=chrome node test/e2e/run-all.js --build-type flask", @@ -58,11 +57,10 @@ "test:e2e:firefox": "SELENIUM_BROWSER=firefox node test/e2e/run-all.js", "test:e2e:firefox:flask": "SELENIUM_BROWSER=firefox node test/e2e/run-all.js --build-type flask", "test:e2e:single": "node test/e2e/run-e2e-test.js", - "test:coverage:mocha": "node ./test/run-unit-tests.js --mocha --coverage", "test:coverage:jest": "node ./test/run-unit-tests.js --jestGlobal --coverage", "test:coverage:jest:dev": "node ./test/run-unit-tests.js --jestDev --coverage", "test:coverage:validate": "node ./test/merge-coverage.js", - "test:coverage": "node ./test/run-unit-tests.js --mocha --jestGlobal --jestDev --coverage && yarn test:coverage:validate", + "test:coverage": "node ./test/run-unit-tests.js --jestGlobal --jestDev --coverage && yarn test:coverage:validate", "test:coverage:html": "yarn test:coverage --html", "ganache:start": "./development/run-ganache.sh", "sentry:publish": "node ./development/sentry-publish.js", @@ -599,7 +597,6 @@ "prettier": "^2.7.1", "prettier-eslint": "^16.3.0", "prettier-plugin-sort-json": "^1.0.0", - "proxyquire": "^2.1.3", "pumpify": "^2.0.1", "randomcolor": "^0.5.4", "react-devtools": "^4.11.0", diff --git a/yarn.lock b/yarn.lock index 1030d1c3f8cb..c67266bb695b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18612,16 +18612,6 @@ __metadata: languageName: node linkType: hard -"fill-keys@npm:^1.0.2": - version: 1.0.2 - resolution: "fill-keys@npm:1.0.2" - dependencies: - is-object: "npm:~1.0.1" - merge-descriptors: "npm:~1.0.0" - checksum: 10/6e78e314dc6852060086a8edc754d6a5b8efea5389ba8ec48367c1d0fa14272f9fad2f5c1ced1dcbd73306ffbfa3aa8cc64add884150ccf729f2a45ebc22d2eb - languageName: node - linkType: hard - "fill-range@npm:^2.1.0": version: 2.2.4 resolution: "fill-range@npm:2.2.4" @@ -21782,13 +21772,6 @@ __metadata: languageName: node linkType: hard -"is-object@npm:~1.0.1": - version: 1.0.1 - resolution: "is-object@npm:1.0.1" - checksum: 10/c3a6f2bb14f35dcf5605dfc085c824fe1ccbdf7484e3ab74a963d49eb2cacb0648cea67eee2761fabef0eb79c1290f17dcc058ffb5db91409d8746fe0356c8ee - languageName: node - linkType: hard - "is-path-cwd@npm:^2.2.0": version: 2.2.0 resolution: "is-path-cwd@npm:2.2.0" @@ -24986,7 +24969,7 @@ __metadata: languageName: node linkType: hard -"merge-descriptors@npm:1.0.1, merge-descriptors@npm:~1.0.0": +"merge-descriptors@npm:1.0.1": version: 1.0.1 resolution: "merge-descriptors@npm:1.0.1" checksum: 10/5abc259d2ae25bb06d19ce2b94a21632583c74e2a9109ee1ba7fd147aa7362b380d971e0251069f8b3eb7d48c21ac839e21fa177b335e82c76ec172e30c31a26 @@ -25330,7 +25313,6 @@ __metadata: prettier-plugin-sort-json: "npm:^1.0.0" promise-to-callback: "npm:^1.0.0" prop-types: "npm:^15.6.1" - proxyquire: "npm:^2.1.3" pumpify: "npm:^2.0.1" punycode: "npm:^2.1.1" qrcode-generator: "npm:1.4.1" @@ -26314,13 +26296,6 @@ __metadata: languageName: node linkType: hard -"module-not-found-error@npm:^1.0.1": - version: 1.0.1 - resolution: "module-not-found-error@npm:1.0.1" - checksum: 10/ebd65339d4d5980dd55cd32dbf112ec02b8e33f30866312b94caeee4783322259f18cf2270e9d2e600df3bd1876c35612b87f5c2525c21885fb1f83e85a9b9b0 - languageName: node - linkType: hard - "moo-color@npm:^1.0.2": version: 1.0.2 resolution: "moo-color@npm:1.0.2" @@ -28920,17 +28895,6 @@ __metadata: languageName: node linkType: hard -"proxyquire@npm:^2.1.3": - version: 2.1.3 - resolution: "proxyquire@npm:2.1.3" - dependencies: - fill-keys: "npm:^1.0.2" - module-not-found-error: "npm:^1.0.1" - resolve: "npm:^1.11.1" - checksum: 10/c124bdb6f732d680c59c2d4cf0ff66ebae7b3c76af0c1bb05d5c9b982ba05db22c1df6ad4cb486d1d8a5f6b1fe0534cbea864917e82dacaf947cfa84c4c30463 - languageName: node - linkType: hard - "pseudomap@npm:^1.0.2": version: 1.0.2 resolution: "pseudomap@npm:1.0.2" @@ -30697,7 +30661,7 @@ __metadata: languageName: node linkType: hard -"resolve@npm:1.22.8, resolve@npm:^1.1.4, resolve@npm:^1.1.6, resolve@npm:^1.1.7, resolve@npm:^1.10.0, resolve@npm:^1.10.1, resolve@npm:^1.11.1, resolve@npm:^1.14.2, resolve@npm:^1.17.0, resolve@npm:^1.18.1, resolve@npm:^1.19.0, resolve@npm:^1.20.0, resolve@npm:^1.22.0, resolve@npm:^1.22.1, resolve@npm:^1.22.2, resolve@npm:^1.22.3, resolve@npm:^1.4.0": +"resolve@npm:1.22.8, resolve@npm:^1.1.4, resolve@npm:^1.1.6, resolve@npm:^1.1.7, resolve@npm:^1.10.0, resolve@npm:^1.10.1, resolve@npm:^1.14.2, resolve@npm:^1.17.0, resolve@npm:^1.18.1, resolve@npm:^1.19.0, resolve@npm:^1.20.0, resolve@npm:^1.22.0, resolve@npm:^1.22.1, resolve@npm:^1.22.2, resolve@npm:^1.22.3, resolve@npm:^1.4.0": version: 1.22.8 resolution: "resolve@npm:1.22.8" dependencies: @@ -30723,7 +30687,7 @@ __metadata: languageName: node linkType: hard -? "resolve@patch:resolve@npm%3A1.22.8#optional!builtin, resolve@patch:resolve@npm%3A^1.1.4#optional!builtin, resolve@patch:resolve@npm%3A^1.1.6#optional!builtin, resolve@patch:resolve@npm%3A^1.1.7#optional!builtin, resolve@patch:resolve@npm%3A^1.10.0#optional!builtin, resolve@patch:resolve@npm%3A^1.10.1#optional!builtin, resolve@patch:resolve@npm%3A^1.11.1#optional!builtin, resolve@patch:resolve@npm%3A^1.14.2#optional!builtin, resolve@patch:resolve@npm%3A^1.17.0#optional!builtin, resolve@patch:resolve@npm%3A^1.18.1#optional!builtin, resolve@patch:resolve@npm%3A^1.19.0#optional!builtin, resolve@patch:resolve@npm%3A^1.20.0#optional!builtin, resolve@patch:resolve@npm%3A^1.22.0#optional!builtin, resolve@patch:resolve@npm%3A^1.22.1#optional!builtin, resolve@patch:resolve@npm%3A^1.22.2#optional!builtin, resolve@patch:resolve@npm%3A^1.22.3#optional!builtin, resolve@patch:resolve@npm%3A^1.4.0#optional!builtin" +? "resolve@patch:resolve@npm%3A1.22.8#optional!builtin, resolve@patch:resolve@npm%3A^1.1.4#optional!builtin, resolve@patch:resolve@npm%3A^1.1.6#optional!builtin, resolve@patch:resolve@npm%3A^1.1.7#optional!builtin, resolve@patch:resolve@npm%3A^1.10.0#optional!builtin, resolve@patch:resolve@npm%3A^1.10.1#optional!builtin, resolve@patch:resolve@npm%3A^1.14.2#optional!builtin, resolve@patch:resolve@npm%3A^1.17.0#optional!builtin, resolve@patch:resolve@npm%3A^1.18.1#optional!builtin, resolve@patch:resolve@npm%3A^1.19.0#optional!builtin, resolve@patch:resolve@npm%3A^1.20.0#optional!builtin, resolve@patch:resolve@npm%3A^1.22.0#optional!builtin, resolve@patch:resolve@npm%3A^1.22.1#optional!builtin, resolve@patch:resolve@npm%3A^1.22.2#optional!builtin, resolve@patch:resolve@npm%3A^1.22.3#optional!builtin, resolve@patch:resolve@npm%3A^1.4.0#optional!builtin" : version: 1.22.8 resolution: "resolve@patch:resolve@npm%3A1.22.8#optional!builtin::version=1.22.8&hash=c3c19d" From b4b06da23a323265579aa577178783396b19c938 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 24 Jun 2024 14:08:52 -0230 Subject: [PATCH 2/7] chore: Bump Firefox outdated browser version (#25365) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** The outdated browser version for Firefox has been bumped to 102. Users on older versions of Firefox will now see a warning saying that their browser is outdated. This is inpreparation for updating our minimum supported Firefox version to 102. 102 is the previous ESR version, which matches our browser support policy (we support the current and previous ESR Firefox versions). [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25365?quickstart=1) ## **Related issues** N/A ## **Manual testing steps** Run this build with any Firefox version between v91 and 101 (inclusive), and see that the outdated browser version notice appears on the Home screen. ## **Screenshots/Recordings** None ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- ui/helpers/constants/common.ts | 6 ++++-- ui/helpers/utils/util.test.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ui/helpers/constants/common.ts b/ui/helpers/constants/common.ts index 8170536690b0..ce7bdf44b7e9 100644 --- a/ui/helpers/constants/common.ts +++ b/ui/helpers/constants/common.ts @@ -21,8 +21,10 @@ export const OUTDATED_BROWSER_VERSIONS = { // or the earliest version that supports our MV3 functionality, whichever is higher chrome: '<109', edge: '<109', - // Firefox should match the most recent end-of-life extended support release - firefox: '<91', + // Firefox should match the previous extended support release + // Current ESR: 115 + // Previous ESR: 102 + firefox: '<102', // Opera versions correspond to differently numbered Chromium versions. // Opera should be set to the equivalent of the Chromium version set // Opera 95 is based on Chromium 109 diff --git a/ui/helpers/utils/util.test.js b/ui/helpers/utils/util.test.js index ce60fcdd85f8..fdcfe4e48972 100644 --- a/ui/helpers/utils/util.test.js +++ b/ui/helpers/utils/util.test.js @@ -218,14 +218,14 @@ describe('util', () => { }); it('should return false when given a modern firefox browser', () => { const browser = Bowser.getParser( - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/91.0', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/102.0', ); const result = util.getIsBrowserDeprecated(browser); expect(result).toStrictEqual(false); }); it('should return true when given an outdated firefox browser', () => { const browser = Bowser.getParser( - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/90.0', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/91.0', ); const result = util.getIsBrowserDeprecated(browser); expect(result).toStrictEqual(true); From 230dec79bb27315178eb9bcbf82a7b26213b5384 Mon Sep 17 00:00:00 2001 From: Victor Thomas <10986371+vthomas13@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:14:47 -0400 Subject: [PATCH 3/7] ci: Adding node-linux-medium executor (#25476) We want to monitor these changes over the next week(s) to make sure we are not increasing the runtime of CI jobs --- .circleci/config.yml | 62 ++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 86ed5e0d3aa9..091dbdf6189e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,6 +13,12 @@ executors: resource_class: medium environment: NODE_OPTIONS: --max_old_space_size=3072 + node-linux-medium: + machine: + image: ubuntu-2404:2024.05.1 + resource_class: medium #// linux medium: 2 CPUs, 7.5 GB RAM, 10 credits/min + environment: + NODE_OPTIONS: --max_old_space_size=6144 node-browsers-medium-plus: docker: - image: cimg/node:20.11-browsers @@ -497,10 +503,10 @@ jobs: command: .circleci/scripts/check-working-tree.sh prep-build: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - when: @@ -534,10 +540,10 @@ jobs: - builds prep-build-mv2: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - when: @@ -577,10 +583,10 @@ jobs: - builds-mv2 prep-build-mmi: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - when: @@ -621,10 +627,10 @@ jobs: destination: builds-mmi prep-build-flask: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - when: @@ -662,10 +668,10 @@ jobs: - builds-flask prep-build-flask-mv2: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - when: @@ -703,10 +709,10 @@ jobs: - builds-flask-mv2 prep-build-test-flask: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - run: @@ -725,10 +731,10 @@ jobs: - builds-test-flask prep-build-test-flask-mv2: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - run: @@ -747,10 +753,10 @@ jobs: - builds-test-flask-mv2 prep-build-test-mmi: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - run: @@ -769,10 +775,10 @@ jobs: - builds-test-mmi prep-build-test-mmi-playwright: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - run: *check-mmi-optional @@ -798,10 +804,10 @@ jobs: destination: builds-test-mmi-playwright prep-build-test: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - run: @@ -822,10 +828,10 @@ jobs: - builds-test prep-build-test-mv2: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - run: @@ -846,10 +852,10 @@ jobs: - builds-test-mv2 prep-build-confirmation-redesign-test: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - run: @@ -868,10 +874,10 @@ jobs: - builds-test-confirmations prep-build-confirmation-redesign-test-mv2: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - run: @@ -890,10 +896,10 @@ jobs: - builds-test-confirmations-mv2 prep-build-storybook: - executor: node-browsers-medium-plus + executor: node-linux-medium steps: - run: *shallow-git-clone - - run: sudo corepack enable + - run: corepack enable - attach_workspace: at: . - run: From a4455296d36125583ec42d6f8cf2d92b77cc19de Mon Sep 17 00:00:00 2001 From: Devin <168687171+Devin-Apps@users.noreply.github.com> Date: Mon, 24 Jun 2024 22:52:18 +0530 Subject: [PATCH 4/7] chore: replace typography with text component in actionable-message and icon stories (#25228) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** This PR addresses the migration of the `Typography` component to the `Text` component in the `actionable-message.stories.js` and `icon/icon.stories.js` files as per the instructions provided. The changes have been tested and verified in Storybook. Devin Run Link: https://preview.devin.ai/devin/4fd90411cece4582a5f6db41d7c3a980 [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25228?quickstart=1) ## **Related issues** Partially Fixes: https://github.com/MetaMask/metamask-extension/issues/20496 ## **Manual testing steps** 1. Go to the latest build of storybook in this PR 2. Verify that the 'ActionableMessage' and 'Icon' components render correctly with the Text component. ## **Screenshots/Recordings** ### **Before** 1. actionable-message.stories.js ![](https://api.devin.ai/attachments/bdfc1c94-7f49-4256-a2e8-a03cd32995cb/10629bfc-836a-44c7-a888-a007dacb7431.png) 2. icon/icon.stories.js Screenshot 2024-06-12 at 01 27 27 ### **After** 1. actionable-message.stories.js ![](https://api.devin.ai/attachments/0deed3a5-2d93-45f3-9d7b-c670dcb73481/b5c35405-ee5d-47e0-a06a-171ef40ec49c.png) 2. icon/icon.stories.js Screenshot 2024-06-12 at 01 26 41 ## **Pre-merge author checklist** - [X] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [X] I've completed the PR template to the best of my ability - [X] I’ve included tests if applicable - [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [X] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../actionable-message.stories.js | 14 +++------ ui/components/ui/icon/icon.stories.js | 30 ++++++++++--------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/ui/components/ui/actionable-message/actionable-message.stories.js b/ui/components/ui/actionable-message/actionable-message.stories.js index eb0d73824c86..7713b7ba4b1f 100644 --- a/ui/components/ui/actionable-message/actionable-message.stories.js +++ b/ui/components/ui/actionable-message/actionable-message.stories.js @@ -1,7 +1,7 @@ import React from 'react'; import Box from '../box'; -import Typography from '../typography'; +import { Text } from '../../component-library'; import { Color, DISPLAY, @@ -131,19 +131,13 @@ export const OnTopOfContent = (args) => {
- - Lorem ipsum dolor sit amet consectetur adipisicing elit. - + Lorem ipsum dolor sit amet consectetur adipisicing elit. - - Lorem ipsum dolor sit amet consectetur adipisicing elit. - + Lorem ipsum dolor sit amet consectetur adipisicing elit. - - Lorem ipsum dolor sit amet consectetur adipisicing elit. - + Lorem ipsum dolor sit amet consectetur adipisicing elit.
diff --git a/ui/components/ui/icon/icon.stories.js b/ui/components/ui/icon/icon.stories.js index 9a18f70b35d7..e31f52d42951 100644 --- a/ui/components/ui/icon/icon.stories.js +++ b/ui/components/ui/icon/icon.stories.js @@ -4,14 +4,14 @@ import { BackgroundColor, SEVERITIES, TextColor, - TypographyVariant, + TextVariant, + FontWeight, } from '../../../helpers/constants/design-system'; import Card from '../card'; -import Typography from '../typography'; import Box from '../box'; +import { Text } from '../../component-library'; import README from './README.mdx'; - import Approve from './approve-icon.component'; import InfoIcon from './info-icon.component'; import InfoIconInverted from './info-icon-inverted.component'; @@ -86,26 +86,28 @@ IconItem.propTypes = { export const DefaultStory = (args) => (
- DEPRECATED - - - Icons - - + + Icons + + To ensure correct licensing we suggest you use an icon from the @fortawesome/fontawesome-free: ^5.13.0 package. If there is no icon to suit your needs and you need to create a new one. Ensure that it has the correct licensing or has been created in house from scratch. Please use the ./icon-caret-left.js as the template. - +
Date: Mon, 24 Jun 2024 19:26:31 +0200 Subject: [PATCH 5/7] fix: fix large amount display (#25464) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** The goal of this PR is to fix the way we display large token amout [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25464?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to wallet page 2. Import a token with large amount 3. check the way it's displayed ## **Screenshots/Recordings** ### **Before** ![Screenshot 2024-06-21 at 15 30 22](https://github.com/MetaMask/metamask-extension/assets/26223211/2d332ce7-8a6e-45b7-a367-d4214d125bca) ### **After** ![Screenshot 2024-06-21 at 15 29 09](https://github.com/MetaMask/metamask-extension/assets/26223211/1a90e5b7-6eb6-4060-9704-dc0ec3716f0f) ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- .../__snapshots__/token-cell.test.js.snap | 2 +- ui/components/app/token-cell/token-cell.js | 8 +++++++- .../app/token-cell/token-cell.test.js | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ui/components/app/token-cell/__snapshots__/token-cell.test.js.snap b/ui/components/app/token-cell/__snapshots__/token-cell.test.js.snap index 5fd87d103c47..139f516bdc95 100644 --- a/ui/components/app/token-cell/__snapshots__/token-cell.test.js.snap +++ b/ui/components/app/token-cell/__snapshots__/token-cell.test.js.snap @@ -75,7 +75,7 @@ exports[`Token Cell should match snapshot 1`] = ` class="mm-box mm-text mm-text--body-md mm-text--text-align-end mm-box--color-text-alternative" data-testid="multichain-token-list-item-value" > - 5.000 + 5 TEST

diff --git a/ui/components/app/token-cell/token-cell.js b/ui/components/app/token-cell/token-cell.js index 0052096254be..e58fda03918a 100644 --- a/ui/components/app/token-cell/token-cell.js +++ b/ui/components/app/token-cell/token-cell.js @@ -6,6 +6,7 @@ import { useTokenFiatAmount } from '../../../hooks/useTokenFiatAmount'; import { TokenListItem } from '../../multichain'; import { isEqualCaseInsensitive } from '../../../../shared/modules/string-utils'; import { useIsOriginalTokenSymbol } from '../../../hooks/useIsOriginalTokenSymbol'; +import { getIntlLocale } from '../../../ducks/locale/locale'; export default function TokenCell({ address, image, symbol, string, onClick }) { const tokenList = useSelector(getTokenList); @@ -17,6 +18,11 @@ export default function TokenCell({ address, image, symbol, string, onClick }) { const title = tokenData?.name || symbol; const tokenImage = tokenData?.iconUrl || image; const formattedFiat = useTokenFiatAmount(address, string, symbol); + const locale = useSelector(getIntlLocale); + const primary = new Intl.NumberFormat(locale, { + minimumSignificantDigits: 1, + }).format(string.toString()); + const isOriginalTokenSymbol = useIsOriginalTokenSymbol(address, symbol); return ( @@ -24,7 +30,7 @@ export default function TokenCell({ address, image, symbol, string, onClick }) { onClick={onClick ? () => onClick(address) : undefined} tokenSymbol={symbol} tokenImage={tokenImage} - primary={`${string || 0}`} + primary={`${primary || 0}`} secondary={isOriginalTokenSymbol ? formattedFiat : null} title={title} isOriginalTokenSymbol={isOriginalTokenSymbol} diff --git a/ui/components/app/token-cell/token-cell.test.js b/ui/components/app/token-cell/token-cell.test.js index 8312000d3ed2..731361de7df6 100644 --- a/ui/components/app/token-cell/token-cell.test.js +++ b/ui/components/app/token-cell/token-cell.test.js @@ -86,6 +86,13 @@ describe('Token Cell', () => { onClick: jest.fn(), }; + const propsLargeAmount = { + address: '0xAnotherToken', + symbol: 'TEST', + string: '5000000', + currentCurrency: 'usd', + onClick: jest.fn(), + }; useSelector.mockReturnValue(MOCK_GET_TOKEN_LIST); useTokenFiatAmount.mockReturnValue('5.00'); @@ -121,4 +128,16 @@ describe('Token Cell', () => { expect(image).toBeInTheDocument(); expect(image).toHaveAttribute('src', './images/test_image.svg'); }); + + it('should render amount with the correct format', () => { + const { getByTestId } = renderWithProvider( + , + mockStore, + ); + + const amountElement = getByTestId('multichain-token-list-item-value'); + + expect(amountElement).toBeInTheDocument(); + expect(amountElement.textContent).toBe('5,000,000 TEST'); + }); }); From fcb426588560374faf4e1e23acf4aed8b9c90b9a Mon Sep 17 00:00:00 2001 From: seaona <54408225+seaona@users.noreply.github.com> Date: Mon, 24 Jun 2024 20:58:13 +0200 Subject: [PATCH 6/7] fix: flaky test screenshot for `Increase Token Allowance increases token spending cap to allow other accounts to transfer tokens ` (#25324) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** This test fails whenever we try to switch to the MetaMask Dialog. This PR waits until there are 3 window handles and then performs the window switch. Not sure yet which is the cause of the Dialog not appearing, as I cannot reproduce it locally. However, the benefit of this change is that in the case the dialog does not appear, now we'll be able to take a screenshot and check the artifacts for further information and debugging. See ci failure: https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/87524/workflows/aa81e40a-0aa1-40dc-9ddf-dc83b4db83f1/jobs/3205989/parallel-runs/8?filterBy=FAILED [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25324?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Check ci ## **Screenshots/Recordings** ![Screenshot from 2024-06-14 15-30-23](https://github.com/MetaMask/metamask-extension/assets/54408225/41fd0f92-2d50-4550-a43b-04005d7dc912) See how no screenshot was taken due to the failure on the window switch ![Screenshot from 2024-06-14 15-30-39](https://github.com/MetaMask/metamask-extension/assets/54408225/88c7b4f9-7a5f-4bea-86ee-635fb9de41ce) ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: HJetpoluru Co-authored-by: Harika Jetpoluru <153644847+hjetpoluru@users.noreply.github.com> --- test/e2e/tests/tokens/increase-token-allowance.spec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/e2e/tests/tokens/increase-token-allowance.spec.js b/test/e2e/tests/tokens/increase-token-allowance.spec.js index 4fb092906558..52a7d9454e38 100644 --- a/test/e2e/tests/tokens/increase-token-allowance.spec.js +++ b/test/e2e/tests/tokens/increase-token-allowance.spec.js @@ -232,6 +232,8 @@ describe('Increase Token Allowance', function () { }); await driver.delay(2000); + // Windows: MetaMask, Test Dapp and Dialog + await driver.waitUntilXWindowHandles(3); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); let spendingCapElement = await driver.findElement( '[data-testid="custom-spending-cap-input"]', @@ -297,6 +299,8 @@ describe('Increase Token Allowance', function () { } async function confirmTransferFromTokensSuccess(driver) { + // Windows: MetaMask, Test Dapp and Dialog + await driver.waitUntilXWindowHandles(3, 1000, 10000); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await driver.waitForSelector({ text: '1.5 TST', tag: 'h1' }); await driver.clickElement({ text: 'Confirm', tag: 'button' }); From 18ebe12d66130d6ddeb12d211fe973642b4ef7ce Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 24 Jun 2024 16:48:21 -0230 Subject: [PATCH 7/7] test: Simplify Jest config and expand coverage (#25013) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** Our Mocha and Jest configuration has been messy because we're in the middle of a migration from Mocha to Jest. Each file had to be explicitly included in the Jest configuration or ignored in the Mocha configuration. This was inconvenient and error-prone, and resulted in some tests not being run at all. ~Both test configurations have been updated to use a shared list of Mocha test files. There are only a few of these files left, and this list should only get shorter as we migrate more tests to Jest. No further configuration changes will be needed to add Jest tests.~ We have now finished migrating unit tests from Mocha to Jest, so this PR now only affects the Jest configuration. Note that the ESLint configuration has not been updated to use these simpler globs to determine which tests use Mocha and which use Jest. I tried doing that in this PR initially but it raised too many lint errors, so that will come in a later PR. In the meantime, we may still need to update `.eslintrc.js` when adding a new test of either type. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25013?quickstart=1) ## **Related issues** N/A ## **Manual testing steps** Run `yarn test:unit` and verify that it runs correctly (no errors, no missing tests) ## **Screenshots/Recordings** N/A ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- jest.config.js | 51 +++----------------------------------------------- 1 file changed, 3 insertions(+), 48 deletions(-) diff --git a/jest.config.js b/jest.config.js index 1d6f86938950..f52466a9d183 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,26 +1,8 @@ module.exports = { collectCoverageFrom: [ - '/app/scripts/constants/error-utils.js', - '/app/scripts/controllers/app-metadata.ts', - '/app/scripts/controllers/permissions/**/*.js', - '/app/scripts/controllers/sign.ts', - '/app/scripts/controllers/decrypt-message.ts', - '/app/scripts/controllers/encryption-public-key.ts', - '/app/scripts/controllers/transactions/etherscan.ts', - '/app/scripts/controllers/transactions/EtherscanRemoteTransactionSource.ts', - '/app/scripts/controllers/transactions/IncomingTransactionHelper.ts', - '/app/scripts/controllers/preferences.js', - '/app/scripts/flask/**/*.js', - '/app/scripts/lib/**/*.(js|ts)', - '/app/scripts/metamask-controller.js', - '/app/scripts/migrations/*.js', - '/app/scripts/migrations/*.ts', - '!/app/scripts/migrations/*.test.(js|ts)', - '/app/scripts/platforms/*.js', + '/app/scripts/**/*.(js|ts|tsx)', '/shared/**/*.(js|ts|tsx)', '/ui/**/*.(js|ts|tsx)', - '/development/fitness-functions/**/*.test.(js|ts|tsx)', - '/test/e2e/helpers.test.js', ], coverageDirectory: './coverage', coveragePathIgnorePatterns: ['.stories.*', '.snap'], @@ -41,35 +23,8 @@ module.exports = { setupFiles: ['/test/setup.js', '/test/env.js'], setupFilesAfterEnv: ['/test/jest/setup.js'], testMatch: [ - '/app/scripts/constants/error-utils.test.js', - '/app/scripts/controllers/app-metadata.test.ts', - '/app/scripts/controllers/app-state.test.js', - '/app/scripts/controllers/encryption-public-key.test.ts', - '/app/scripts/controllers/transactions/etherscan.test.ts', - '/app/scripts/controllers/transactions/EtherscanRemoteTransactionSource.test.ts', - '/app/scripts/controllers/transactions/IncomingTransactionHelper.test.ts', - '/app/scripts/controllers/onboarding.test.ts', - '/app/scripts/controllers/mmi-controller.test.ts', - '/app/scripts/controllers/permissions/**/*.test.js', - '/app/scripts/controllers/preferences.test.js', - '/app/scripts/controllers/sign.test.ts', - '/app/scripts/controllers/decrypt-message.test.ts', - '/app/scripts/controllers/authentication/**/*.test.ts', - '/app/scripts/controllers/push-platform-notifications/**/*.test.ts', - '/app/scripts/controllers/user-storage/**/*.test.ts', - '/app/scripts/controllers/metamask-notifications/**/*.test.ts', - '/app/scripts/metamask-controller.actions.test.js', - '/app/scripts/detect-multiple-instances.test.js', - '/app/scripts/controllers/swaps.test.js', - '/app/scripts/controllers/metametrics.test.js', - '/app/scripts/flask/**/*.test.js', - '/app/scripts/lib/**/*.test.(js|ts)', - '/app/scripts/lib/createRPCMethodTrackingMiddleware.test.js', - '/app/scripts/metamask-controller.test.js', - '/app/scripts/migrations/*.test.(js|ts)', - '/app/scripts/platforms/*.test.js', - '/app/scripts/translate.test.ts', - '/shared/**/*.test.(js|ts)', + '/app/scripts/**/*.test.(js|ts|tsx)', + '/shared/**/*.test.(js|ts|tsx)', '/ui/**/*.test.(js|ts|tsx)', '/development/fitness-functions/**/*.test.(js|ts|tsx)', '/test/e2e/helpers.test.js',