Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions oxlint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm curious why this didn't get flagged before 🤔 But it is definitely a rule that's checked in @metamask/eslint-config-vitest, so this makes sense.

"count": 6
}
},
"packages/sample-controllers/src/sample-gas-prices-controller.ts": {
Expand Down
26 changes: 0 additions & 26 deletions packages/sample-controllers/jest.config.cjs

This file was deleted.

15 changes: 6 additions & 9 deletions packages/sample-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -149,7 +150,7 @@ describe('SampleGasPricesController', () => {
{ selectedNetworkClientId: 'BBBB-BBBB-BBBB-BBBB' },
[],
);
jest.runAllTimers();
vi.runAllTimers();
await flushPromises();

expect(fetchGasPrices).toHaveBeenCalledTimes(1);
Expand All @@ -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,
Expand Down Expand Up @@ -206,15 +207,15 @@ 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');
}

throw new Error(`Unrecognized chain ID '${givenChainId}'`);
});

const captureException = jest.spyOn(rootMessenger, 'captureException');
const captureException = vi.spyOn(rootMessenger, 'captureException');
rootMessenger.registerActionHandler(
'SampleGasPricesService:fetchGasPrices',
fetchGasPrices,
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -435,7 +436,7 @@ type WithControllerOptions = {
function getRootMessenger(): RootMessenger {
return new Messenger({
namespace: MOCK_ANY_NAMESPACE,
captureException: jest.fn(),
captureException: vi.fn(),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 0 additions & 3 deletions packages/sample-controllers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"extends": "../../tsconfig.packages.json",
"compilerOptions": {
"types": ["jest"]
},
"references": [
{
"path": "../base-controller"
Expand Down
20 changes: 20 additions & 0 deletions packages/sample-controllers/vitest.config.js

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like these files can end in .ts instead of .js. It's a minor thing but it would help other teams verify that they've passed the right options if they modify these files.

Maybe something to consider for a future PR?

Original file line number Diff line number Diff line change
@@ -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,
},
},
},
});
1 change: 0 additions & 1 deletion test-runner-package-map.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 1 addition & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading