Skip to content

Commit 97caa82

Browse files
committed
chore: migrate node:test tests to vitest
1 parent b29d4bf commit 97caa82

15 files changed

Lines changed: 864 additions & 1040 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,7 +1,6 @@
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';
3+
import { describe, expect, it } from 'vitest';
54
import { fileURLToPath } from 'node:url';
65

76
import {
@@ -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: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { describe, it } from 'node:test';
2-
import assert from 'node:assert/strict';
3-
import {
1+
import { describe, expect, it } from 'vitest';import {
42
allocateBucketSlots,
53
formatWatchHistory,
64
partitionSummary,
@@ -51,10 +49,10 @@ describe('summarizeTestHealth', () => {
5149
]);
5250

5351
const test = summary[0];
54-
assert.equal(test.latestClassification, 'passed');
55-
assert.equal(test.historicalBrokenCount, 1);
56-
assert.equal(test.historicalFlakyCount, 1);
57-
assert.equal(test.totalRuns, 3);
52+
expect(test.latestClassification).toBe('passed');
53+
expect(test.historicalBrokenCount).toBe(1);
54+
expect(test.historicalFlakyCount).toBe(1);
55+
expect(test.totalRuns).toBe(3);
5856
});
5957
});
6058

@@ -72,19 +70,19 @@ describe('partitionSummary', () => {
7270
},
7371
]);
7472

75-
assert.equal(watchItems.length, 1);
76-
assert.equal(flakyItems.length, 0);
77-
assert.equal(brokenItems.length, 0);
73+
expect(watchItems.length).toBe(1);
74+
expect(flakyItems.length).toBe(0);
75+
expect(brokenItems.length).toBe(0);
7876
});
7977
});
8078

8179
describe('allocateBucketSlots', () => {
8280
it('gives spare capacity to watch when nothing is currently broken', () => {
8381
const slots = allocateBucketSlots(15, { broken: 0, flaky: 0, watch: 13, infra: 0 });
8482

85-
assert.equal(slots.maxBroken, 0);
86-
assert.equal(slots.maxWatch, 13);
87-
assert.equal(slots.maxBroken + slots.maxFlaky + slots.maxWatch + slots.maxInfra, 13);
83+
expect(slots.maxBroken).toBe(0);
84+
expect(slots.maxWatch).toBe(13);
85+
expect(slots.maxBroken + slots.maxFlaky + slots.maxWatch + slots.maxInfra).toBe(13);
8886
});
8987
});
9088

@@ -96,50 +94,38 @@ describe('formatWatchHistory', () => {
9694
totalRuns: 8,
9795
});
9896

99-
assert.match(text, /failed 2\/8 runs/);
100-
assert.match(text, /flaky 3\/8 runs/);
97+
expect(text).toMatch(/failed 2\/8 runs/);
98+
expect(text).toMatch(/flaky 3\/8 runs/);
10199
});
102100
});
103101

104102
describe('normalizeRepoFilePath', () => {
105103
it('prefixes testDir-relative paths', () => {
106-
assert.equal(
107-
normalizeRepoFilePath('accounts/account-syncing-settings-toggle.spec.ts', {
104+
expect(normalizeRepoFilePath('accounts/account-syncing-settings-toggle.spec.ts', {
108105
prefix: 'tests/smoke-appium',
109-
}),
110-
'tests/smoke-appium/accounts/account-syncing-settings-toggle.spec.ts',
111-
);
106+
})).toBe('tests/smoke-appium/accounts/account-syncing-settings-toggle.spec.ts');
112107
});
113108

114109
it('strips CI absolute checkout paths to repo-relative', () => {
115-
assert.equal(
116-
normalizeRepoFilePath(
110+
expect(normalizeRepoFilePath(
117111
'/Users/runner/work/metamask-mobile/metamask-mobile/tests/framework/config/global.setup.ts',
118-
),
119-
'tests/framework/config/global.setup.ts',
120-
);
112+
)).toBe('tests/framework/config/global.setup.ts');
121113
});
122114

123115
it('leaves paths already under tests/ unchanged when prefix is set', () => {
124-
assert.equal(
125-
normalizeRepoFilePath('tests/smoke-appium/accounts/foo.spec.ts', {
116+
expect(normalizeRepoFilePath('tests/smoke-appium/accounts/foo.spec.ts', {
126117
prefix: 'tests/smoke-appium',
127-
}),
128-
'tests/smoke-appium/accounts/foo.spec.ts',
129-
);
118+
})).toBe('tests/smoke-appium/accounts/foo.spec.ts');
130119
});
131120

132121
it('does not double-apply an identical prefix', () => {
133-
assert.equal(
134-
normalizeRepoFilePath('tests/smoke-appium/accounts/foo.spec.ts', {
122+
expect(normalizeRepoFilePath('tests/smoke-appium/accounts/foo.spec.ts', {
135123
prefix: 'tests/smoke-appium',
136-
}),
137-
'tests/smoke-appium/accounts/foo.spec.ts',
138-
);
124+
})).toBe('tests/smoke-appium/accounts/foo.spec.ts');
139125
});
140126

141127
it('returns relative paths unchanged when no prefix is set', () => {
142-
assert.equal(normalizeRepoFilePath('accounts/foo.spec.ts'), 'accounts/foo.spec.ts');
128+
expect(normalizeRepoFilePath('accounts/foo.spec.ts')).toBe('accounts/foo.spec.ts');
143129
});
144130
});
145131

@@ -184,9 +170,6 @@ describe('createSlackBlocks path links', () => {
184170
.flatMap(element => element.elements || [])
185171
.find(element => element.type === 'link' && element.text === 'toggles sync');
186172

187-
assert.equal(
188-
link?.url,
189-
'https://github.com/MetaMask/metamask-mobile/blob/main/tests/smoke-appium/accounts/account-syncing-settings-toggle.spec.ts',
190-
);
173+
expect(link?.url).toBe('https://github.com/MetaMask/metamask-mobile/blob/main/tests/smoke-appium/accounts/account-syncing-settings-toggle.spec.ts');
191174
});
192175
});

0 commit comments

Comments
 (0)