Skip to content

Commit e9ccb89

Browse files
committed
chore: migrate node:test tests to vitest
1 parent d72d152 commit e9ccb89

15 files changed

Lines changed: 876 additions & 1027 deletions

‎.github/actions/draft-segment-schema-pr/gate.test.mjs‎

Lines changed: 49 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import assert from 'node:assert/strict';
21
import { readFileSync } from 'node:fs';
32
import { dirname, join } from 'node:path';
4-
import { describe, it } from 'node:test';
53
import { fileURLToPath } from 'node:url';
4+
import { describe, expect, it } from 'vitest';
65

76
import {
87
AGREEMENT_PHRASE,
@@ -55,32 +54,28 @@ function input(overrides = {}) {
5554

5655
describe('eventSkipReason', () => {
5756
it('skips propose on issue_comment and close unless the PR closed', () => {
58-
assert.equal(
59-
eventSkipReason('propose', 'issue_comment', 'created'),
57+
expect(eventSkipReason('propose', 'issue_comment', 'created')).toBe(
6058
'wrong-event',
6159
);
62-
assert.equal(
63-
eventSkipReason('propose', 'pull_request', 'closed'),
60+
expect(eventSkipReason('propose', 'pull_request', 'closed')).toBe(
6461
'wrong-event',
6562
);
66-
assert.equal(
67-
eventSkipReason('close', 'pull_request', 'synchronize'),
63+
expect(eventSkipReason('close', 'pull_request', 'synchronize')).toBe(
6864
'wrong-event',
6965
);
70-
assert.equal(eventSkipReason('create', 'issue_comment', 'created'), '');
71-
assert.equal(eventSkipReason('propose', 'pull_request', 'synchronize'), '');
72-
assert.equal(eventSkipReason('close', 'pull_request', 'closed'), '');
66+
expect(eventSkipReason('create', 'issue_comment', 'created')).toBe('');
67+
expect(eventSkipReason('propose', 'pull_request', 'synchronize')).toBe('');
68+
expect(eventSkipReason('close', 'pull_request', 'closed')).toBe('');
7369
});
7470
});
7571

7672
describe('isAgreementComment', () => {
7773
it('treats trailing whitespace on the agreement sentence as a match', () => {
78-
assert.equal(
74+
expect(
7975
isAgreementComment(`${AGREEMENT_PHRASE} \nThanks`, 'alice', 'alice'),
80-
true,
81-
);
82-
assert.equal(isAgreementComment(AGREEMENT_PHRASE, 'bob', 'alice'), false);
83-
assert.equal(isAgreementComment('please open it', 'alice', 'alice'), false);
76+
).toBe(true);
77+
expect(isAgreementComment(AGREEMENT_PHRASE, 'bob', 'alice')).toBe(false);
78+
expect(isAgreementComment('please open it', 'alice', 'alice')).toBe(false);
8479
});
8580
});
8681

@@ -94,9 +89,9 @@ describe('collectTsDiff and hasAnalyticsDiff', () => {
9489
{ filename: 'README.md', patch: '+docs' },
9590
{ filename: 'app/foo.test.ts', patch: '+createEventBuilder(x)' },
9691
]);
97-
assert.deepEqual(diff.files, ['app/Home.ts']);
98-
assert.equal(diff.mentionsAnalytics, true);
99-
assert.equal(hasAnalyticsDiff(diff, 'mobile'), true);
92+
expect(diff.files).toStrictEqual(['app/Home.ts']);
93+
expect(diff.mentionsAnalytics).toBe(true);
94+
expect(hasAnalyticsDiff(diff, 'mobile')).toBe(true);
10095
});
10196

10297
it('treats a catalog-only change as an analytics hit', () => {
@@ -106,16 +101,16 @@ describe('collectTsDiff and hasAnalyticsDiff', () => {
106101
patch: "+NEW_EVENT = 'New Event'",
107102
},
108103
]);
109-
assert.equal(diff.mentionsAnalytics, false);
110-
assert.equal(hasAnalyticsDiff(diff, 'mobile'), true);
104+
expect(diff.mentionsAnalytics).toBe(false);
105+
expect(hasAnalyticsDiff(diff, 'mobile')).toBe(true);
111106
});
112107

113108
it('does not treat unrelated TypeScript patches as analytics hits', () => {
114109
const diff = collectTsDiff([
115110
{ filename: 'app/Home.ts', patch: '+const x = 1;\n' },
116111
]);
117-
assert.equal(diff.mentionsAnalytics, false);
118-
assert.equal(hasAnalyticsDiff(diff, 'mobile'), false);
112+
expect(diff.mentionsAnalytics).toBe(false);
113+
expect(hasAnalyticsDiff(diff, 'mobile')).toBe(false);
119114
});
120115

121116
it('treats addSensitiveProperties as an analytics hit', () => {
@@ -125,7 +120,7 @@ describe('collectTsDiff and hasAnalyticsDiff', () => {
125120
patch: '+.addSensitiveProperties({ secret: true })',
126121
},
127122
]);
128-
assert.equal(diff.mentionsAnalytics, true);
123+
expect(diff.mentionsAnalytics).toBe(true);
129124
});
130125

131126
it('counts a renamed TypeScript file once', () => {
@@ -136,32 +131,30 @@ describe('collectTsDiff and hasAnalyticsDiff', () => {
136131
patch: '+const x = 1;\n',
137132
},
138133
]);
139-
assert.deepEqual(diff.files, ['app/next.ts', 'app/prev.ts']);
140-
assert.equal(diff.recordCount, 1);
134+
expect(diff.files).toStrictEqual(['app/next.ts', 'app/prev.ts']);
135+
expect(diff.recordCount).toBe(1);
141136
});
142137
});
143138

144139
describe('shouldPushSchema', () => {
145140
it('pushes on create when open, and on propose only after a schema PR exists', () => {
146-
assert.equal(shouldPushSchema('create', false, true, true), true);
147-
assert.equal(shouldPushSchema('propose', false, true, true), false);
148-
assert.equal(shouldPushSchema('propose', true, true, true), true);
149-
assert.equal(shouldPushSchema('close', true, false, true), false);
150-
assert.equal(shouldPushSchema('create', false, true, false), false);
141+
expect(shouldPushSchema('create', false, true, true)).toBe(true);
142+
expect(shouldPushSchema('propose', false, true, true)).toBe(false);
143+
expect(shouldPushSchema('propose', true, true, true)).toBe(true);
144+
expect(shouldPushSchema('close', true, false, true)).toBe(false);
145+
expect(shouldPushSchema('create', false, true, false)).toBe(false);
151146
});
152147
});
153148

154149
describe('decideGate', () => {
155150
it('skips forks, opt-out, closed PRs, and non-agreement comments', () => {
156-
assert.equal(
157-
decideGate(input({ pr: { ...PR, isFork: true } })).skipReason,
151+
expect(decideGate(input({ pr: { ...PR, isFork: true } })).skipReason).toBe(
158152
'fork',
159153
);
160-
assert.equal(
154+
expect(
161155
decideGate(input({ pr: { ...PR, hasOptOutLabel: true } })).skipReason,
162-
'opt-out',
163-
);
164-
assert.equal(
156+
).toBe('opt-out');
157+
expect(
165158
decideGate(
166159
input({
167160
mode: 'create',
@@ -172,18 +165,16 @@ describe('decideGate', () => {
172165
commenterLogin: 'alice',
173166
}),
174167
).skipReason,
175-
'client-pr-closed',
176-
);
177-
assert.equal(
168+
).toBe('client-pr-closed');
169+
expect(
178170
decideGate(
179171
input({
180172
mode: 'create',
181173
eventName: 'issue_comment',
182174
eventAction: 'created',
183175
}),
184176
).skipReason,
185-
'agreement-mismatch',
186-
);
177+
).toBe('agreement-mismatch');
187178
});
188179

189180
it('skips close when no schema PR exists', () => {
@@ -194,8 +185,8 @@ describe('decideGate', () => {
194185
schemaPrExists: false,
195186
}),
196187
);
197-
assert.equal(result.skip, true);
198-
assert.equal(result.skipReason, 'no-schema-pr');
188+
expect(result.skip).toBe(true);
189+
expect(result.skipReason).toBe('no-schema-pr');
199190
});
200191

201192
it('skips propose when there is no analytics diff, schema PR, or sticky comment', () => {
@@ -204,7 +195,7 @@ describe('decideGate', () => {
204195
pullFiles: [{ filename: 'app/Home.ts', patch: '+const x = 1;\n' }],
205196
}),
206197
);
207-
assert.equal(result.skipReason, 'no-analytics-diff');
198+
expect(result.skipReason).toBe('no-analytics-diff');
208199
});
209200

210201
it('continues propose so publish can edit a sticky comment when analytics drop off', () => {
@@ -214,9 +205,9 @@ describe('decideGate', () => {
214205
hasProposalComment: true,
215206
}),
216207
);
217-
assert.equal(result.skip, false);
218-
assert.equal(result.hasAnalyticsDiff, false);
219-
assert.equal(result.shouldPush, false);
208+
expect(result.skip).toBe(false);
209+
expect(result.hasAnalyticsDiff).toBe(false);
210+
expect(result.shouldPush).toBe(false);
220211
});
221212

222213
it('sets tooManyFiles and does not push when the TS file list exceeds the cap', () => {
@@ -228,9 +219,9 @@ describe('decideGate', () => {
228219
}),
229220
);
230221
const result = decideGate(input({ pullFiles, schemaPrExists: true }));
231-
assert.equal(result.skip, false);
232-
assert.equal(result.tooManyFiles, true);
233-
assert.equal(result.shouldPush, false);
222+
expect(result.skip).toBe(false);
223+
expect(result.tooManyFiles).toBe(true);
224+
expect(result.shouldPush).toBe(false);
234225
});
235226

236227
it('does not treat 76 renamed TypeScript files as over the cap', () => {
@@ -240,7 +231,7 @@ describe('decideGate', () => {
240231
patch: '+createEventBuilder(MetaMetricsEvents.APP_OPENED)',
241232
}));
242233
const result = decideGate(input({ pullFiles }));
243-
assert.equal(result.tooManyFiles, false);
234+
expect(result.tooManyFiles).toBe(false);
244235
});
245236

246237
it('pushes on create when agreement matches and YAML can be written', () => {
@@ -253,9 +244,9 @@ describe('decideGate', () => {
253244
commenterLogin: 'alice',
254245
}),
255246
);
256-
assert.equal(result.skip, false);
257-
assert.equal(result.shouldPush, true);
258-
assert.equal(result.branch, botBranchName('mobile', 12));
247+
expect(result.skip).toBe(false);
248+
expect(result.shouldPush).toBe(true);
249+
expect(result.branch).toBe(botBranchName('mobile', 12));
259250
});
260251
});
261252

@@ -265,8 +256,8 @@ describe('schema pull list client', () => {
265256
join(dirname(fileURLToPath(import.meta.url)), 'action.yml'),
266257
'utf8',
267258
);
268-
assert.match(action, /getOctokit\(process\.env\.SEGMENT_SCHEMA_TOKEN\)/u);
269-
assert.doesNotMatch(action, /const \{\s*getOctokit\s*\}/u);
270-
assert.doesNotMatch(action, /headers:\s*\{\s*authorization:/u);
259+
expect(action).toMatch(/getOctokit\(process\.env\.SEGMENT_SCHEMA_TOKEN\)/u);
260+
expect(action).not.toMatch(/const \{\s*getOctokit\s*\}/u);
261+
expect(action).not.toMatch(/headers:\s*\{\s*authorization:/u);
271262
});
272263
});

‎.github/actions/playwright-test-health-report/lib/report-health.test.mjs‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import assert from 'node:assert/strict';
2-
import { describe, it } from 'node:test';
1+
import { describe, expect, it } from 'vitest';
32

43
import {
54
allocateBucketSlots,
@@ -52,10 +51,10 @@ describe('summarizeTestHealth', () => {
5251
]);
5352

5453
const test = summary[0];
55-
assert.equal(test.latestClassification, 'passed');
56-
assert.equal(test.historicalBrokenCount, 1);
57-
assert.equal(test.historicalFlakyCount, 1);
58-
assert.equal(test.totalRuns, 3);
54+
expect(test.latestClassification).toBe('passed');
55+
expect(test.historicalBrokenCount).toBe(1);
56+
expect(test.historicalFlakyCount).toBe(1);
57+
expect(test.totalRuns).toBe(3);
5958
});
6059
});
6160

@@ -73,9 +72,9 @@ describe('partitionSummary', () => {
7372
},
7473
]);
7574

76-
assert.equal(watchItems.length, 1);
77-
assert.equal(flakyItems.length, 0);
78-
assert.equal(brokenItems.length, 0);
75+
expect(watchItems.length).toBe(1);
76+
expect(flakyItems.length).toBe(0);
77+
expect(brokenItems.length).toBe(0);
7978
});
8079
});
8180

@@ -88,12 +87,11 @@ describe('allocateBucketSlots', () => {
8887
infra: 0,
8988
});
9089

91-
assert.equal(slots.maxBroken, 0);
92-
assert.equal(slots.maxWatch, 13);
93-
assert.equal(
90+
expect(slots.maxBroken).toBe(0);
91+
expect(slots.maxWatch).toBe(13);
92+
expect(
9493
slots.maxBroken + slots.maxFlaky + slots.maxWatch + slots.maxInfra,
95-
13,
96-
);
94+
).toBe(13);
9795
});
9896
});
9997

@@ -105,54 +103,51 @@ describe('formatWatchHistory', () => {
105103
totalRuns: 8,
106104
});
107105

108-
assert.match(text, /failed 2\/8 runs/);
109-
assert.match(text, /flaky 3\/8 runs/);
106+
expect(text).toMatch(/failed 2\/8 runs/);
107+
expect(text).toMatch(/flaky 3\/8 runs/);
110108
});
111109
});
112110

113111
describe('normalizeRepoFilePath', () => {
114112
it('prefixes testDir-relative paths', () => {
115-
assert.equal(
113+
expect(
116114
normalizeRepoFilePath(
117115
'accounts/account-syncing-settings-toggle.spec.ts',
118116
{
119117
prefix: 'tests/smoke-appium',
120118
},
121119
),
120+
).toBe(
122121
'tests/smoke-appium/accounts/account-syncing-settings-toggle.spec.ts',
123122
);
124123
});
125124

126125
it('strips CI absolute checkout paths to repo-relative', () => {
127-
assert.equal(
126+
expect(
128127
normalizeRepoFilePath(
129128
'/Users/runner/work/metamask-mobile/metamask-mobile/tests/framework/config/global.setup.ts',
130129
),
131-
'tests/framework/config/global.setup.ts',
132-
);
130+
).toBe('tests/framework/config/global.setup.ts');
133131
});
134132

135133
it('leaves paths already under tests/ unchanged when prefix is set', () => {
136-
assert.equal(
134+
expect(
137135
normalizeRepoFilePath('tests/smoke-appium/accounts/foo.spec.ts', {
138136
prefix: 'tests/smoke-appium',
139137
}),
140-
'tests/smoke-appium/accounts/foo.spec.ts',
141-
);
138+
).toBe('tests/smoke-appium/accounts/foo.spec.ts');
142139
});
143140

144141
it('does not double-apply an identical prefix', () => {
145-
assert.equal(
142+
expect(
146143
normalizeRepoFilePath('tests/smoke-appium/accounts/foo.spec.ts', {
147144
prefix: 'tests/smoke-appium',
148145
}),
149-
'tests/smoke-appium/accounts/foo.spec.ts',
150-
);
146+
).toBe('tests/smoke-appium/accounts/foo.spec.ts');
151147
});
152148

153149
it('returns relative paths unchanged when no prefix is set', () => {
154-
assert.equal(
155-
normalizeRepoFilePath('accounts/foo.spec.ts'),
150+
expect(normalizeRepoFilePath('accounts/foo.spec.ts')).toBe(
156151
'accounts/foo.spec.ts',
157152
);
158153
});
@@ -202,8 +197,7 @@ describe('createSlackBlocks path links', () => {
202197
(element) => element.type === 'link' && element.text === 'toggles sync',
203198
);
204199

205-
assert.equal(
206-
link?.url,
200+
expect(link?.url).toBe(
207201
'https://github.com/MetaMask/metamask-mobile/blob/main/tests/smoke-appium/accounts/account-syncing-settings-toggle.spec.ts',
208202
);
209203
});

0 commit comments

Comments
 (0)