1- import assert from 'node:assert/strict' ;
21import { readFileSync } from 'node:fs' ;
32import { dirname , join } from 'node:path' ;
4- import { describe , it } from 'node:test ' ;
3+ import { describe , expect , it } from 'vitest ' ;
54import { fileURLToPath } from 'node:url' ;
65
76import {
@@ -55,32 +54,28 @@ function input(overrides = {}) {
5554
5655describe ( '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
7672describe ( '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
144139describe ( '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
154149describe ( '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 , / g e t O c t o k i t \( p r o c e s s \. e n v \. S E G M E N T _ S C H E M A _ T O K E N \) / u) ;
269- assert . doesNotMatch ( action , / c o n s t \{ \s * g e t O c t o k i t \s * \} / u) ;
270- assert . doesNotMatch ( action , / h e a d e r s : \s * \{ \s * a u t h o r i z a t i o n : / u) ;
259+ expect ( action ) . toMatch ( / g e t O c t o k i t \( p r o c e s s \. e n v \. S E G M E N T _ S C H E M A _ T O K E N \) / u) ;
260+ expect ( action ) . not . toMatch ( / c o n s t \{ \s * g e t O c t o k i t \s * \} / u) ;
261+ expect ( action ) . not . toMatch ( / h e a d e r s : \s * \{ \s * a u t h o r i z a t i o n : / u) ;
271262 } ) ;
272263} ) ;
0 commit comments