diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json index 8bd32b60b15..505dd1f643d 100644 --- a/oxlint-suppressions.json +++ b/oxlint-suppressions.json @@ -5507,9 +5507,9 @@ "count": 11 } }, - "packages/sample-controllers/jest.config.cjs": { - "import/unambiguous": { - "count": 1 + "packages/sample-controllers/src/sample-gas-prices-controller.test.ts": { + "vitest/no-conditional-in-test": { + "count": 6 } }, "packages/sample-controllers/src/sample-gas-prices-controller.ts": { diff --git a/packages/sample-controllers/jest.config.cjs b/packages/sample-controllers/jest.config.cjs deleted file mode 100644 index 6456e074bb0..00000000000 --- a/packages/sample-controllers/jest.config.cjs +++ /dev/null @@ -1,26 +0,0 @@ -/* - * For a detailed explanation regarding each configuration property and type check, visit: - * https://jestjs.io/docs/configuration - */ - -const merge = require('deepmerge'); -const path = require('path'); - -const baseConfig = require('../../jest.config.packages.cjs'); - -const displayName = path.basename(__dirname); - -module.exports = merge(baseConfig, { - // The display name when running multiple projects - displayName, - - // An object that configures minimum threshold enforcement for coverage results - coverageThreshold: { - global: { - branches: 100, - functions: 100, - lines: 100, - statements: 100, - }, - }, -}); diff --git a/packages/sample-controllers/package.json b/packages/sample-controllers/package.json index f10c7be0204..94ab3c06c3b 100644 --- a/packages/sample-controllers/package.json +++ b/packages/sample-controllers/package.json @@ -44,10 +44,10 @@ "messenger-action-types:check": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check", "messenger-action-types:generate": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate", "since-latest-release": "../../scripts/since-latest-release.sh", - "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter", - "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache", - "test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose", - "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch" + "test": "vitest", + "test:clean": "vitest --clearCache", + "test:verbose": "vitest --reporter=verbose", + "test:watch": "vitest --watch" }, "dependencies": { "@metamask/base-controller": "^10.1.0", @@ -61,16 +61,13 @@ "devDependencies": { "@metamask/auto-changelog": "^6.2.1", "@metamask/controller-utils": "^13.0.0", - "@types/jest": "^30.0.0", "@typescript/native": "npm:typescript@^7.0.2", - "deepmerge": "^4.3.1", - "jest": "^30.5.2", "nock": "^13.5.6", "rimraf": "^6.1.3", - "ts-jest": "^29.4.14", "typedoc": "^0.28.20", "typedoc-plugin-missing-exports": "^4.1.4", - "typescript": "npm:@typescript/typescript6@^6.0.2" + "typescript": "npm:@typescript/typescript6@^6.0.2", + "vitest": "^5.0.0" }, "engines": { "node": "^22.14.0 || ^24" diff --git a/packages/sample-controllers/src/sample-gas-prices-controller.test.ts b/packages/sample-controllers/src/sample-gas-prices-controller.test.ts index d0d345a034e..c75dbee122c 100644 --- a/packages/sample-controllers/src/sample-gas-prices-controller.test.ts +++ b/packages/sample-controllers/src/sample-gas-prices-controller.test.ts @@ -7,8 +7,9 @@ import type { } from '@metamask/messenger'; import { SampleGasPricesController } from '@metamask/sample-controllers'; import type { SampleGasPricesControllerMessenger } from '@metamask/sample-controllers'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { flushPromises } from '../../../tests/helpers.js'; +import { flushPromises } from '../../../tests/vitest/helpers.js'; import { buildMockGetNetworkClientById } from '../../network-controller/tests/helpers.js'; describe('SampleGasPricesController', () => { @@ -46,11 +47,11 @@ describe('SampleGasPricesController', () => { describe('on NetworkController:stateChange', () => { beforeEach(() => { - jest.useFakeTimers().setSystemTime(new Date('2024-01-02')); + vi.useFakeTimers().setSystemTime(new Date('2024-01-02')); }); afterEach(() => { - jest.useRealTimers(); + vi.useRealTimers(); }); it('fetches and updates gas prices for the newly selected chain ID, if it has changed', async () => { @@ -106,9 +107,9 @@ describe('SampleGasPricesController', () => { const chainId = '0x42'; let i = 0; const delays = [5000, 1000]; - const fetchGasPrices = jest.fn(async (givenChainId) => { + const fetchGasPrices = vi.fn(async (givenChainId) => { if (givenChainId === chainId) { - jest.advanceTimersByTime(delays[i]); + vi.advanceTimersByTime(delays[i]); i += 1; return { low: 5, @@ -149,7 +150,7 @@ describe('SampleGasPricesController', () => { { selectedNetworkClientId: 'BBBB-BBBB-BBBB-BBBB' }, [], ); - jest.runAllTimers(); + vi.runAllTimers(); await flushPromises(); expect(fetchGasPrices).toHaveBeenCalledTimes(1); @@ -159,7 +160,7 @@ describe('SampleGasPricesController', () => { it('does not fetch gas prices for the selected chain ID again if it has not changed', async () => { await withController(async ({ rootMessenger }) => { const chainId = '0x42'; - const fetchGasPrices = jest.fn(async (givenChainId) => { + const fetchGasPrices = vi.fn(async (givenChainId) => { if (givenChainId === chainId) { return { low: 5, @@ -206,7 +207,7 @@ describe('SampleGasPricesController', () => { await withController(async ({ rootMessenger }) => { const chainId = '0x42'; - const fetchGasPrices = jest.fn(async (givenChainId) => { + const fetchGasPrices = vi.fn(async (givenChainId) => { if (givenChainId === chainId) { throw new Error('Failed to fetch gas prices'); } @@ -214,7 +215,7 @@ describe('SampleGasPricesController', () => { throw new Error(`Unrecognized chain ID '${givenChainId}'`); }); - const captureException = jest.spyOn(rootMessenger, 'captureException'); + const captureException = vi.spyOn(rootMessenger, 'captureException'); rootMessenger.registerActionHandler( 'SampleGasPricesService:fetchGasPrices', fetchGasPrices, @@ -251,11 +252,11 @@ describe('SampleGasPricesController', () => { describe('SampleGasPricesController:updateGasPrices', () => { beforeEach(() => { - jest.useFakeTimers().setSystemTime(new Date('2024-01-02')); + vi.useFakeTimers().setSystemTime(new Date('2024-01-02')); }); afterEach(() => { - jest.useRealTimers(); + vi.useRealTimers(); }); it('fetches and persists gas prices for the current chain through the service object', async () => { @@ -296,11 +297,11 @@ describe('SampleGasPricesController', () => { describe('updateGasPrices', () => { beforeEach(() => { - jest.useFakeTimers().setSystemTime(new Date('2024-01-02')); + vi.useFakeTimers().setSystemTime(new Date('2024-01-02')); }); afterEach(() => { - jest.useRealTimers(); + vi.useRealTimers(); }); it('does the same thing as the messenger action', async () => { @@ -435,7 +436,7 @@ type WithControllerOptions = { function getRootMessenger(): RootMessenger { return new Messenger({ namespace: MOCK_ANY_NAMESPACE, - captureException: jest.fn(), + captureException: vi.fn(), }); } diff --git a/packages/sample-controllers/src/sample-gas-prices-service/sample-gas-prices-service.test.ts b/packages/sample-controllers/src/sample-gas-prices-service/sample-gas-prices-service.test.ts index 54e394e8b77..33d8444c6b0 100644 --- a/packages/sample-controllers/src/sample-gas-prices-service/sample-gas-prices-service.test.ts +++ b/packages/sample-controllers/src/sample-gas-prices-service/sample-gas-prices-service.test.ts @@ -6,6 +6,7 @@ import type { MessengerEvents, } from '@metamask/messenger'; import nock from 'nock'; +import { describe, expect, it } from 'vitest'; import type { SampleGasPricesServiceMessenger } from './sample-gas-prices-service.js'; import { SampleGasPricesService } from './sample-gas-prices-service.js'; diff --git a/packages/sample-controllers/src/sample-petnames-controller.test.ts b/packages/sample-controllers/src/sample-petnames-controller.test.ts index 68a4217779c..243e3a84f74 100644 --- a/packages/sample-controllers/src/sample-petnames-controller.test.ts +++ b/packages/sample-controllers/src/sample-petnames-controller.test.ts @@ -5,6 +5,7 @@ import type { MessengerActions, MessengerEvents, } from '@metamask/messenger'; +import { describe, expect, it } from 'vitest'; import { PROTOTYPE_POLLUTION_BLOCKLIST } from '../../controller-utils/src/util.js'; import type { SamplePetnamesControllerMessenger } from './sample-petnames-controller.js'; diff --git a/packages/sample-controllers/tsconfig.json b/packages/sample-controllers/tsconfig.json index e42af723be1..5feece8d600 100644 --- a/packages/sample-controllers/tsconfig.json +++ b/packages/sample-controllers/tsconfig.json @@ -1,8 +1,5 @@ { "extends": "../../tsconfig.packages.json", - "compilerOptions": { - "types": ["jest"] - }, "references": [ { "path": "../base-controller" diff --git a/packages/sample-controllers/vitest.config.js b/packages/sample-controllers/vitest.config.js new file mode 100644 index 00000000000..a07dec83436 --- /dev/null +++ b/packages/sample-controllers/vitest.config.js @@ -0,0 +1,20 @@ +import { basename, dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { mergeConfig } from 'vitest/config'; + +import baseConfig from '../../vitest.config.packages.js'; + +export default mergeConfig(baseConfig, { + test: { + name: basename(dirname(fileURLToPath(import.meta.url))), + + coverage: { + thresholds: { + branches: 100, + functions: 100, + lines: 100, + statements: 100, + }, + }, + }, +}); diff --git a/test-runner-package-map.cjs b/test-runner-package-map.cjs index 183d3eb53fe..27f011631a6 100644 --- a/test-runner-package-map.cjs +++ b/test-runner-package-map.cjs @@ -87,7 +87,6 @@ const PACKAGES_ON_JEST = new Set([ '@metamask/rate-limit-controller', '@metamask/react-data-query', '@metamask/remote-feature-flag-controller', - '@metamask/sample-controllers', '@metamask/seedless-onboarding-controller', '@metamask/selected-network-controller', '@metamask/sentinel-api-service', diff --git a/yarn.lock b/yarn.lock index a6ad730f3c0..0c297eb2d65 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8749,16 +8749,13 @@ __metadata: "@metamask/superstruct": "npm:^3.4.1" "@metamask/utils": "npm:^12.0.0" "@tanstack/query-core": "npm:^5.103.2" - "@types/jest": "npm:^30.0.0" "@typescript/native": "npm:typescript@^7.0.2" - deepmerge: "npm:^4.3.1" - jest: "npm:^30.5.2" nock: "npm:^13.5.6" rimraf: "npm:^6.1.3" - ts-jest: "npm:^29.4.14" typedoc: "npm:^0.28.20" typedoc-plugin-missing-exports: "npm:^4.1.4" typescript: "npm:@typescript/typescript6@^6.0.2" + vitest: "npm:^5.0.0" languageName: unknown linkType: soft