Skip to content

Commit b29d4bf

Browse files
committed
chore: migrate src tests from jest to vitest
1 parent aabd401 commit b29d4bf

18 files changed

Lines changed: 845 additions & 2706 deletions

‎oxlint-suppressions.json‎

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,6 @@
517517
"count": 1
518518
}
519519
},
520-
"src/env-utils.test.ts": {
521-
"no-undef": {
522-
"count": 6
523-
}
524-
},
525520
"src/error-utils.ts": {
526521
"typescript/explicit-function-return-type": {
527522
"count": 1
@@ -562,16 +557,6 @@
562557
"count": 1
563558
}
564559
},
565-
"src/segment-schema-draft-pr/analytics-model.test.ts": {
566-
"no-undef": {
567-
"count": 23
568-
}
569-
},
570-
"src/segment-schema-draft-pr/apply-changes.test.ts": {
571-
"no-undef": {
572-
"count": 42
573-
}
574-
},
575560
"src/segment-schema-draft-pr/apply-changes.ts": {
576561
"import/consistent-type-specifier-style": {
577562
"count": 1
@@ -588,67 +573,24 @@
588573
"count": 1
589574
}
590575
},
591-
"src/segment-schema-draft-pr/client-diff.test.ts": {
592-
"no-undef": {
593-
"count": 33
594-
}
595-
},
596-
"src/segment-schema-draft-pr/config.test.ts": {
597-
"no-undef": {
598-
"count": 7
599-
}
600-
},
601-
"src/segment-schema-draft-pr/diff-models.test.ts": {
602-
"no-undef": {
603-
"count": 15
604-
}
605-
},
606576
"src/segment-schema-draft-pr/diff-models.ts": {
607577
"typescript/no-unsafe-assignment": {
608578
"count": 6
609579
}
610580
},
611581
"src/segment-schema-draft-pr/generate.test.ts": {
612-
"no-undef": {
613-
"count": 8
614-
},
615582
"typescript/return-await": {
616583
"count": 2
617584
}
618585
},
619-
"src/segment-schema-draft-pr/github-api.test.ts": {
620-
"no-undef": {
621-
"count": 45
622-
}
623-
},
624-
"src/segment-schema-draft-pr/github-output.test.ts": {
625-
"no-undef": {
626-
"count": 6
627-
}
628-
},
629586
"src/segment-schema-draft-pr/github-output.ts": {
630587
"node/no-sync": {
631588
"count": 1
632589
}
633590
},
634-
"src/segment-schema-draft-pr/names.test.ts": {
635-
"no-undef": {
636-
"count": 16
637-
}
638-
},
639-
"src/segment-schema-draft-pr/parse-args.test.ts": {
640-
"no-undef": {
641-
"count": 12
642-
}
643-
},
644-
"src/segment-schema-draft-pr/pr-body.test.ts": {
645-
"no-undef": {
646-
"count": 26
647-
}
648-
},
649591
"src/segment-schema-draft-pr/publish.test.ts": {
650-
"no-undef": {
651-
"count": 24
592+
"import/consistent-type-specifier-style": {
593+
"count": 1
652594
},
653595
"typescript/no-unsafe-member-access": {
654596
"count": 1

‎package.json‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"lint:tsc": "tsc",
2222
"segment-schema:draft-pr": "ts-node src/segment-schema-draft-pr/cli.ts",
2323
"slack:release-testing": "node .github/scripts/slack-release-testing.mjs",
24-
"test": "jest && node --test '.github/**/*.test.{mjs,mts}' && jest-it-up",
25-
"test:watch": "jest --watch",
24+
"test": "vitest run --coverage && node --test '.github/**/*.test.{mjs,mts}'",
25+
"test:watch": "vitest --watch",
2626
"update-release-sheet": "node .github/scripts/update-release-sheet.mjs",
2727
"lint:oxlint": "oxlint"
2828
},
@@ -57,21 +57,20 @@
5757
"@metamask/oxlint-config-vitest": "^0.2.0",
5858
"@swc/cli": "^0.1.62",
5959
"@swc/core": "^1.3.80",
60-
"@types/jest": "^28.1.6",
6160
"@types/node": "^22.13.14",
6261
"@types/semver": "^7.8.0",
6362
"@types/unzipper": "^0.10.11",
63+
"@vitest/coverage-v8": "^5.1.0",
6464
"@yarnpkg/types": "^4.0.1",
6565
"depcheck": "^1.4.7",
6666
"eslint-plugin-n": "^18.5.0",
67-
"jest": "^28.1.3",
68-
"jest-it-up": "^2.0.2",
6967
"oxlint": "^1.85.0",
7068
"oxlint-tsgolint": "^7.0.2006",
7169
"prettier": "^3.9.9",
7270
"prettier-plugin-packagejson": "^3.1.0",
73-
"ts-jest": "^28.0.7",
74-
"ts-node": "^10.9.2"
71+
"ts-node": "^10.9.2",
72+
"vite": "^8.3.6",
73+
"vitest": "^5.1.0"
7574
},
7675
"packageManager": "yarn@4.17.1",
7776
"engines": {

‎src/env-utils.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { getProcessEnv, getRequiredEnvironmentVariable } from './env-utils';
24

35
describe('env-utils', () => {

‎src/segment-schema-draft-pr/analytics-model.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { extractAnalyticsModel } from './analytics-model';
24
import { getPlatformConfig } from './config';
35

‎src/segment-schema-draft-pr/apply-changes.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs/promises';
22
import os from 'os';
33
import path from 'path';
4+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
45

56
import { applyChanges } from './apply-changes';
67
import { getPlatformConfig } from './config';

‎src/segment-schema-draft-pr/client-diff.test.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Octokit } from '@octokit/rest';
2+
import { describe, expect, it, vi } from 'vitest';
23

34
import {
45
getFileAtRef,
@@ -14,7 +15,7 @@ const REPO = { owner: 'MetaMask', repo: 'metamask-mobile' };
1415

1516
describe('loadPullRequestTsDiff', () => {
1617
it('keeps non-test TypeScript paths from the PR file list', async () => {
17-
const paginate = jest.fn().mockResolvedValue([
18+
const paginate = vi.fn().mockResolvedValue([
1819
{
1920
filename: 'app/Home.ts',
2021
patch: '+createEventBuilder(MetaMetricsEvents.APP_OPENED)',
@@ -41,7 +42,7 @@ describe('loadPullRequestTsDiff', () => {
4142
});
4243

4344
it('includes previous_filename so a rename is visible at both SHAs', async () => {
44-
const paginate = jest.fn().mockResolvedValue([
45+
const paginate = vi.fn().mockResolvedValue([
4546
{
4647
filename: 'app/track.tsx',
4748
[PREVIOUS_FILENAME]: 'app/old-track.tsx',
@@ -57,7 +58,7 @@ describe('loadPullRequestTsDiff', () => {
5758
});
5859

5960
it('treats an omitted patch on a TypeScript file as an analytics hit', async () => {
60-
const paginate = jest.fn().mockResolvedValue([{ filename: 'app/Home.ts' }]);
61+
const paginate = vi.fn().mockResolvedValue([{ filename: 'app/Home.ts' }]);
6162
const octokit = { paginate } as unknown as Octokit;
6263

6364
const diff = await loadPullRequestTsDiff(octokit, REPO, 12);
@@ -67,7 +68,7 @@ describe('loadPullRequestTsDiff', () => {
6768
});
6869

6970
it('does not treat unrelated TypeScript patches as analytics hits', async () => {
70-
const paginate = jest
71+
const paginate = vi
7172
.fn()
7273
.mockResolvedValue([
7374
{ filename: 'app/Home.ts', patch: '+const x = 1;\n' },
@@ -80,7 +81,7 @@ describe('loadPullRequestTsDiff', () => {
8081
});
8182

8283
it('treats addSensitiveProperties as an analytics hit', async () => {
83-
const paginate = jest.fn().mockResolvedValue([
84+
const paginate = vi.fn().mockResolvedValue([
8485
{
8586
filename: 'app/Home.ts',
8687
patch: '+.addSensitiveProperties({ secret: true })',
@@ -123,7 +124,7 @@ describe('hasAnalyticsDiff', () => {
123124

124125
describe('getFileAtRef', () => {
125126
it('decodes base64 file contents', async () => {
126-
const getContent = jest.fn().mockResolvedValue({
127+
const getContent = vi.fn().mockResolvedValue({
127128
data: {
128129
content: Buffer.from('enum EVENT_NAME {}', 'utf8').toString('base64'),
129130
},
@@ -149,7 +150,7 @@ describe('getFileAtRef', () => {
149150
it('returns null on 404', async () => {
150151
const error = new Error('Not Found') as Error & { status: number };
151152
error.status = 404;
152-
const getContent = jest.fn().mockRejectedValue(error);
153+
const getContent = vi.fn().mockRejectedValue(error);
153154
const octokit = { repos: { getContent } } as unknown as Octokit;
154155

155156
expect(await getFileAtRef(octokit, REPO, 'app/gone.ts', 'abc')).toBeNull();

‎src/segment-schema-draft-pr/config.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { getPlatformConfig, botBranchName } from './config';
24

35
describe('config', () => {

‎src/segment-schema-draft-pr/diff-models.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import {
24
changesetHasContent,
35
changesetHasWritableChanges,

‎src/segment-schema-draft-pr/generate.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Octokit } from '@octokit/rest';
22
import fs from 'fs/promises';
33
import os from 'os';
44
import path from 'path';
5+
import { describe, expect, it, vi } from 'vitest';
56

67
import { generateSchemaDraft } from './generate';
78

@@ -49,7 +50,7 @@ function encodedFile(text: string): { data: { content: string } } {
4950
function mockClientOctokit(
5051
contents: Record<string, Record<string, string>>,
5152
): Octokit {
52-
const paginate = jest.fn().mockResolvedValue([
53+
const paginate = vi.fn().mockResolvedValue([
5354
{
5455
filename: CATALOG,
5556
patch: "+NEW_EVENT = 'New Event'",
@@ -59,7 +60,7 @@ function mockClientOctokit(
5960
patch: '+createEventBuilder(MetaMetricsEvents.NEW_EVENT)',
6061
},
6162
]);
62-
const getContent = jest
63+
const getContent = vi
6364
.fn()
6465
.mockImplementation(
6566
async ({ path: filePath, ref }: { path: string; ref: string }) => {

‎src/segment-schema-draft-pr/github-api.test.ts‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Octokit } from '@octokit/rest';
2+
import { describe, expect, it, vi } from 'vitest';
23

34
import { OPT_OUT_LABEL, PROPOSAL_MARKER } from './constants';
45
import {
@@ -25,7 +26,7 @@ describe('github-api', () => {
2526
});
2627

2728
it('resolves the client PR including fork and opt-out label', async () => {
28-
const pullsGet = jest.fn().mockResolvedValue({
29+
const pullsGet = vi.fn().mockResolvedValue({
2930
data: {
3031
number: 12,
3132
base: { sha: 'base' },
@@ -57,7 +58,7 @@ describe('github-api', () => {
5758
});
5859

5960
it('finds an open schema PR by bot head branch', async () => {
60-
const pullsList = jest.fn().mockResolvedValue({
61+
const pullsList = vi.fn().mockResolvedValue({
6162
data: [
6263
{
6364
number: 9,
@@ -84,7 +85,7 @@ describe('github-api', () => {
8485
});
8586

8687
it('creates a draft schema PR', async () => {
87-
const pullsCreate = jest.fn().mockResolvedValue({
88+
const pullsCreate = vi.fn().mockResolvedValue({
8889
data: {
8990
number: 3,
9091
[HTML_URL]: 'https://github.com/Consensys/segment-schema/pull/3',
@@ -110,15 +111,15 @@ describe('github-api', () => {
110111
});
111112

112113
it('edits the existing proposal comment instead of posting a second one', async () => {
113-
const paginate = jest.fn().mockResolvedValue([
114+
const paginate = vi.fn().mockResolvedValue([
114115
{
115116
id: 77,
116117
body: `${PROPOSAL_MARKER}\nold`,
117118
user: { login: 'github-actions[bot]' },
118119
},
119120
]);
120-
const updateComment = jest.fn().mockResolvedValue({});
121-
const createComment = jest.fn().mockResolvedValue({});
121+
const updateComment = vi.fn().mockResolvedValue({});
122+
const createComment = vi.fn().mockResolvedValue({});
122123
const octokit = {
123124
paginate,
124125
issues: { updateComment, createComment },
@@ -140,15 +141,15 @@ describe('github-api', () => {
140141
});
141142

142143
it('updates an existing proposal comment and skips create', async () => {
143-
const paginate = jest.fn().mockResolvedValue([
144+
const paginate = vi.fn().mockResolvedValue([
144145
{
145146
id: 77,
146147
body: `${PROPOSAL_MARKER}\nold`,
147148
user: { login: 'github-actions[bot]' },
148149
},
149150
]);
150-
const updateComment = jest.fn().mockResolvedValue({});
151-
const createComment = jest.fn().mockResolvedValue({});
151+
const updateComment = vi.fn().mockResolvedValue({});
152+
const createComment = vi.fn().mockResolvedValue({});
152153
const octokit = {
153154
paginate,
154155
issues: { updateComment, createComment },
@@ -171,9 +172,9 @@ describe('github-api', () => {
171172
});
172173

173174
it('no-ops when no proposal comment exists', async () => {
174-
const paginate = jest.fn().mockResolvedValue([]);
175-
const updateComment = jest.fn().mockResolvedValue({});
176-
const createComment = jest.fn().mockResolvedValue({});
175+
const paginate = vi.fn().mockResolvedValue([]);
176+
const updateComment = vi.fn().mockResolvedValue({});
177+
const createComment = vi.fn().mockResolvedValue({});
177178
const octokit = {
178179
paginate,
179180
issues: { updateComment, createComment },
@@ -191,15 +192,15 @@ describe('github-api', () => {
191192
});
192193

193194
it('ignores a proposal marker posted by someone else', async () => {
194-
const paginate = jest.fn().mockResolvedValue([
195+
const paginate = vi.fn().mockResolvedValue([
195196
{
196197
id: 88,
197198
body: `${PROPOSAL_MARKER}\nplanted`,
198199
user: { login: 'alice' },
199200
},
200201
]);
201-
const updateComment = jest.fn().mockResolvedValue({});
202-
const createComment = jest.fn().mockResolvedValue({});
202+
const updateComment = vi.fn().mockResolvedValue({});
203+
const createComment = vi.fn().mockResolvedValue({});
203204
const octokit = {
204205
paginate,
205206
issues: { updateComment, createComment },

0 commit comments

Comments
 (0)