Skip to content

Commit

Permalink
test: Simplify Jest config and expand coverage (#25013)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **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.
  • Loading branch information
Gudahtt authored Jun 24, 2024
1 parent fcb4265 commit 18ebe12
Showing 1 changed file with 3 additions and 48 deletions.
51 changes: 3 additions & 48 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
module.exports = {
collectCoverageFrom: [
'<rootDir>/app/scripts/constants/error-utils.js',
'<rootDir>/app/scripts/controllers/app-metadata.ts',
'<rootDir>/app/scripts/controllers/permissions/**/*.js',
'<rootDir>/app/scripts/controllers/sign.ts',
'<rootDir>/app/scripts/controllers/decrypt-message.ts',
'<rootDir>/app/scripts/controllers/encryption-public-key.ts',
'<rootDir>/app/scripts/controllers/transactions/etherscan.ts',
'<rootDir>/app/scripts/controllers/transactions/EtherscanRemoteTransactionSource.ts',
'<rootDir>/app/scripts/controllers/transactions/IncomingTransactionHelper.ts',
'<rootDir>/app/scripts/controllers/preferences.js',
'<rootDir>/app/scripts/flask/**/*.js',
'<rootDir>/app/scripts/lib/**/*.(js|ts)',
'<rootDir>/app/scripts/metamask-controller.js',
'<rootDir>/app/scripts/migrations/*.js',
'<rootDir>/app/scripts/migrations/*.ts',
'!<rootDir>/app/scripts/migrations/*.test.(js|ts)',
'<rootDir>/app/scripts/platforms/*.js',
'<rootDir>/app/scripts/**/*.(js|ts|tsx)',
'<rootDir>/shared/**/*.(js|ts|tsx)',
'<rootDir>/ui/**/*.(js|ts|tsx)',
'<rootDir>/development/fitness-functions/**/*.test.(js|ts|tsx)',
'<rootDir>/test/e2e/helpers.test.js',
],
coverageDirectory: './coverage',
coveragePathIgnorePatterns: ['.stories.*', '.snap'],
Expand All @@ -41,35 +23,8 @@ module.exports = {
setupFiles: ['<rootDir>/test/setup.js', '<rootDir>/test/env.js'],
setupFilesAfterEnv: ['<rootDir>/test/jest/setup.js'],
testMatch: [
'<rootDir>/app/scripts/constants/error-utils.test.js',
'<rootDir>/app/scripts/controllers/app-metadata.test.ts',
'<rootDir>/app/scripts/controllers/app-state.test.js',
'<rootDir>/app/scripts/controllers/encryption-public-key.test.ts',
'<rootDir>/app/scripts/controllers/transactions/etherscan.test.ts',
'<rootDir>/app/scripts/controllers/transactions/EtherscanRemoteTransactionSource.test.ts',
'<rootDir>/app/scripts/controllers/transactions/IncomingTransactionHelper.test.ts',
'<rootDir>/app/scripts/controllers/onboarding.test.ts',
'<rootDir>/app/scripts/controllers/mmi-controller.test.ts',
'<rootDir>/app/scripts/controllers/permissions/**/*.test.js',
'<rootDir>/app/scripts/controllers/preferences.test.js',
'<rootDir>/app/scripts/controllers/sign.test.ts',
'<rootDir>/app/scripts/controllers/decrypt-message.test.ts',
'<rootDir>/app/scripts/controllers/authentication/**/*.test.ts',
'<rootDir>/app/scripts/controllers/push-platform-notifications/**/*.test.ts',
'<rootDir>/app/scripts/controllers/user-storage/**/*.test.ts',
'<rootDir>/app/scripts/controllers/metamask-notifications/**/*.test.ts',
'<rootDir>/app/scripts/metamask-controller.actions.test.js',
'<rootDir>/app/scripts/detect-multiple-instances.test.js',
'<rootDir>/app/scripts/controllers/swaps.test.js',
'<rootDir>/app/scripts/controllers/metametrics.test.js',
'<rootDir>/app/scripts/flask/**/*.test.js',
'<rootDir>/app/scripts/lib/**/*.test.(js|ts)',
'<rootDir>/app/scripts/lib/createRPCMethodTrackingMiddleware.test.js',
'<rootDir>/app/scripts/metamask-controller.test.js',
'<rootDir>/app/scripts/migrations/*.test.(js|ts)',
'<rootDir>/app/scripts/platforms/*.test.js',
'<rootDir>/app/scripts/translate.test.ts',
'<rootDir>/shared/**/*.test.(js|ts)',
'<rootDir>/app/scripts/**/*.test.(js|ts|tsx)',
'<rootDir>/shared/**/*.test.(js|ts|tsx)',
'<rootDir>/ui/**/*.test.(js|ts|tsx)',
'<rootDir>/development/fitness-functions/**/*.test.(js|ts|tsx)',
'<rootDir>/test/e2e/helpers.test.js',
Expand Down

0 comments on commit 18ebe12

Please sign in to comment.