1- import test from 'node:test' ;
2- import assert from 'node:assert/strict' ;
31import http from 'node:http' ;
42import { app } from './index.js' ;
53
64let server ;
75let port ;
86
9- test . before ( async ( ) => {
7+ beforeAll ( async ( ) => {
108 server = http . createServer ( app ) ;
119 await new Promise ( ( resolve ) => server . listen ( 0 , resolve ) ) ;
1210 port = server . address ( ) . port ;
1311} ) ;
1412
15- test . after ( async ( ) => {
13+ afterAll ( async ( ) => {
1614 if ( ! server ) {
1715 return ;
1816 }
@@ -30,10 +28,10 @@ test('/v1/generate/fromschema defaults to rows response', async () => {
3028 body : 'iata\nairline.airline.iataCode' ,
3129 } ) ;
3230
33- assert . equal ( response . status , 200 ) ;
31+ expect ( response . status ) . toBe ( 200 ) ;
3432 const body = await response . json ( ) ;
35- assert . ok ( Array . isArray ( body . headers ) ) ;
36- assert . ok ( Array . isArray ( body . rows ) ) ;
33+ expect ( Array . isArray ( body . headers ) ) . toBeTruthy ( ) ;
34+ expect ( Array . isArray ( body . rows ) ) . toBeTruthy ( ) ;
3735} ) ;
3836
3937test ( '/v1/generate/fromschema supports responseFormat=rendered' , async ( ) => {
@@ -43,9 +41,9 @@ test('/v1/generate/fromschema supports responseFormat=rendered', async () => {
4341 body : 'iata\nairline.airline.iataCode' ,
4442 } ) ;
4543
46- assert . equal ( response . status , 200 ) ;
44+ expect ( response . status ) . toBe ( 200 ) ;
4745 const body = await response . json ( ) ;
48- assert . equal ( typeof body . rendered , 'string' ) ;
46+ expect ( typeof body . rendered ) . toBe ( 'string' ) ;
4947} ) ;
5048
5149test ( '/v1/generate/fromschema supports responseFormat=all' , async ( ) => {
@@ -55,10 +53,10 @@ test('/v1/generate/fromschema supports responseFormat=all', async () => {
5553 body : 'iata\nairline.airline.iataCode' ,
5654 } ) ;
5755
58- assert . equal ( response . status , 200 ) ;
56+ expect ( response . status ) . toBe ( 200 ) ;
5957 const body = await response . json ( ) ;
60- assert . ok ( Array . isArray ( body . rows ) ) ;
61- assert . equal ( typeof body . rendered , 'string' ) ;
58+ expect ( Array . isArray ( body . rows ) ) . toBeTruthy ( ) ;
59+ expect ( typeof body . rendered ) . toBe ( 'string' ) ;
6260} ) ;
6361
6462test ( '/v1/generate/fromschema supports responseFormat=raw' , async ( ) => {
@@ -68,8 +66,8 @@ test('/v1/generate/fromschema supports responseFormat=raw', async () => {
6866 body : 'iata\nairline.airline.iataCode' ,
6967 } ) ;
7068
71- assert . equal ( response . status , 200 ) ;
72- assert . match ( response . headers . get ( 'content-type' ) || '' , / t e x t \/ c s v / i) ;
69+ expect ( response . status ) . toBe ( 200 ) ;
70+ expect ( response . headers . get ( 'content-type' ) || '' ) . toMatch ( / t e x t \/ c s v / i) ;
7371} ) ;
7472
7573test ( '/v1/generate/fromschema rejects missing rowCount' , async ( ) => {
@@ -79,7 +77,7 @@ test('/v1/generate/fromschema rejects missing rowCount', async () => {
7977 body : 'iata\nairline.airline.iataCode' ,
8078 } ) ;
8179
82- assert . equal ( response . status , 400 ) ;
80+ expect ( response . status ) . toBe ( 400 ) ;
8381} ) ;
8482
8583test ( '/v1/generate/fromschema rejects invalid responseFormat' , async ( ) => {
@@ -89,7 +87,7 @@ test('/v1/generate/fromschema rejects invalid responseFormat', async () => {
8987 body : 'iata\nairline.airline.iataCode' ,
9088 } ) ;
9189
92- assert . equal ( response . status , 400 ) ;
90+ expect ( response . status ) . toBe ( 400 ) ;
9391} ) ;
9492
9593test ( '/v1/generate/fromschema rejects invalid outputFormat' , async ( ) => {
@@ -99,7 +97,7 @@ test('/v1/generate/fromschema rejects invalid outputFormat', async () => {
9997 body : 'iata\nairline.airline.iataCode' ,
10098 } ) ;
10199
102- assert . equal ( response . status , 400 ) ;
100+ expect ( response . status ) . toBe ( 400 ) ;
103101} ) ;
104102
105103test ( '/v1/generate/fromschema accepts seed from query string and produces deterministic faker output' , async ( ) => {
@@ -110,12 +108,12 @@ test('/v1/generate/fromschema accepts seed from query string and produces determ
110108 const responseA = await fetch ( url ( path ) , { method : 'POST' , headers, body } ) ;
111109 const responseB = await fetch ( url ( path ) , { method : 'POST' , headers, body } ) ;
112110
113- assert . equal ( responseA . status , 200 ) ;
114- assert . equal ( responseB . status , 200 ) ;
111+ expect ( responseA . status ) . toBe ( 200 ) ;
112+ expect ( responseB . status ) . toBe ( 200 ) ;
115113
116114 const payloadA = await responseA . json ( ) ;
117115 const payloadB = await responseB . json ( ) ;
118- assert . deepEqual ( payloadA . rows , payloadB . rows ) ;
116+ expect ( payloadA . rows ) . toEqual ( payloadB . rows ) ;
119117} ) ;
120118
121119test ( '/v1/generate/fromschema rejects invalid seed query value' , async ( ) => {
@@ -125,9 +123,9 @@ test('/v1/generate/fromschema rejects invalid seed query value', async () => {
125123 body : 'iata\nairline.airline.iataCode' ,
126124 } ) ;
127125
128- assert . equal ( response . status , 400 ) ;
126+ expect ( response . status ) . toBe ( 400 ) ;
129127 const payload = await response . json ( ) ;
130- assert . match ( payload . errors ?. [ 0 ] || '' , / s e e d m u s t b e a f i n i t e n u m b e r / i) ;
128+ expect ( payload . errors ?. [ 0 ] || '' ) . toMatch ( / s e e d m u s t b e a f i n i t e n u m b e r / i) ;
131129} ) ;
132130
133131test ( '/v1/generate/fromschema applies unit-test defaults for includeSetup' , async ( ) => {
@@ -137,24 +135,24 @@ test('/v1/generate/fromschema applies unit-test defaults for includeSetup', asyn
137135 headers : { 'content-type' : 'application/json' } ,
138136 body : JSON . stringify ( { options : { includeSetup : true } } ) ,
139137 } ) ;
140- assert . equal ( setDefaults . status , 200 ) ;
138+ expect ( setDefaults . status ) . toBe ( 200 ) ;
141139
142140 const response = await fetch ( url ( '/v1/generate/fromschema?rowCount=1&outputFormat=jest&responseFormat=rendered' ) , {
143141 method : 'POST' ,
144142 headers : { 'content-type' : 'text/plain' } ,
145143 body : 'Name\nBob' ,
146144 } ) ;
147145
148- assert . equal ( response . status , 200 ) ;
146+ expect ( response . status ) . toBe ( 200 ) ;
149147 const body = await response . json ( ) ;
150- assert . match ( body . rendered , / b e f o r e E a c h / ) ;
151- assert . match ( body . rendered , / e x p e c t \( / ) ;
148+ expect ( body . rendered ) . toMatch ( / b e f o r e E a c h / ) ;
149+ expect ( body . rendered ) . toMatch ( / e x p e c t \( / ) ;
152150 } finally {
153151 const resetDefaults = await fetch ( url ( '/v1/generate/options/jest/default' ) , {
154152 method : 'POST' ,
155153 headers : { 'content-type' : 'application/json' } ,
156154 body : JSON . stringify ( { } ) ,
157155 } ) ;
158- assert . equal ( resetDefaults . status , 200 ) ;
156+ expect ( resetDefaults . status ) . toBe ( 200 ) ;
159157 }
160158} ) ;
0 commit comments