@@ -4,8 +4,7 @@ import { join, resolve } from 'node:path';
4
4
import { fileURLToPath } from 'node:url' ;
5
5
6
6
import prettier from 'prettier' ;
7
- import { test } from 'uvu' ;
8
- import * as assert from 'uvu/assert' ;
7
+ import { test , expect } from 'vitest' ;
9
8
10
9
import { build , watch } from '../src/index.js' ;
11
10
import { load_config } from '../src/config.js' ;
@@ -40,13 +39,13 @@ async function test_make_package(path, options) {
40
39
const expected_files = walk ( ewd , true ) ;
41
40
const actual_files = walk ( output , true ) ;
42
41
43
- assert . equal ( actual_files , expected_files ) ;
42
+ expect ( actual_files ) . toEqual ( expected_files ) ;
44
43
45
44
const extensions = [ '.json' , '.svelte' , '.ts' , 'js' , '.map' ] ;
46
45
for ( const file of actual_files ) {
47
46
const pathname = join ( output , file ) ;
48
47
if ( fs . statSync ( pathname ) . isDirectory ( ) ) continue ;
49
- assert . ok ( expected_files . includes ( file ) , `Did not expect ${ file } in ${ path } ` ) ;
48
+ expect ( expected_files . includes ( file ) , `Did not expect ${ file } in ${ path } ` ) . toBeTruthy ( ) ;
50
49
51
50
const expected = fs . readFileSync ( join ( ewd , file ) ) ;
52
51
const actual = fs . readFileSync ( join ( output , file ) ) ;
@@ -55,9 +54,9 @@ async function test_make_package(path, options) {
55
54
if ( extensions . some ( ( ext ) => pathname . endsWith ( ext ) ) ) {
56
55
const expected_content = await format ( file , expected . toString ( 'utf-8' ) ) ;
57
56
const actual_content = await format ( file , actual . toString ( 'utf-8' ) ) ;
58
- assert . fixture ( actual_content , expected_content , err_msg ) ;
57
+ expect ( actual_content , err_msg ) . toBe ( expected_content ) ;
59
58
} else {
60
- assert . ok ( expected . equals ( actual ) , err_msg ) ;
59
+ expect ( expected . equals ( actual ) ) . toBeTruthy ( ) ;
61
60
}
62
61
}
63
62
}
@@ -95,26 +94,24 @@ for (const dir of fs.readdirSync(join(__dirname, 'errors'))) {
95
94
96
95
try {
97
96
await build ( { cwd, input, output, types : true , config } ) ;
98
- assert . unreachable ( 'Must not pass build' ) ;
97
+ throw new Error ( 'Must not pass build' ) ;
99
98
} catch ( /** @type {any } */ error ) {
100
- assert . instance ( error , Error ) ;
99
+ expect ( error ) . toBeInstanceOf ( Error ) ;
101
100
switch ( dir ) {
102
101
case 'no-lib-folder' :
103
- assert . match (
104
- error . message . replace ( / \\ / g, '/' ) ,
102
+ expect ( error . message . replace ( / \\ / g, '/' ) ) . toMatch (
105
103
'test/errors/no-lib-folder/src/lib does not exist'
106
104
) ;
107
105
break ;
108
106
// TODO: non-existent tsconfig passes without error
109
107
// it detects tsconfig in packages/kit instead and creates package folder
110
108
// in packages/kit/package, not sure how to handle and test this yet
111
109
// case 'no-tsconfig':
112
- // assert.match (error.message, 'Failed to locate tsconfig or jsconfig');
110
+ // expect (error.message).toMatch( 'Failed to locate tsconfig or jsconfig');
113
111
// break;
114
112
115
113
default :
116
- assert . unreachable ( 'All error test must be handled' ) ;
117
- break ;
114
+ throw new Error ( 'All error test must be handled' ) ;
118
115
}
119
116
} finally {
120
117
rimraf ( output ) ;
@@ -191,7 +188,7 @@ if (!process.env.CI) {
191
188
192
189
/** @param {string } file */
193
190
function compare ( file ) {
194
- assert . equal ( read ( `package/${ file } ` ) , read ( `expected/${ file } ` ) ) ;
191
+ expect ( read ( `package/${ file } ` ) ) . toEqual ( read ( `expected/${ file } ` ) ) ;
195
192
}
196
193
197
194
/** @param {string } file */
@@ -253,19 +250,18 @@ if (!process.env.CI) {
253
250
remove ( 'src/lib/b.ts' ) ;
254
251
remove ( 'src/lib/post-error.svelte' ) ;
255
252
}
256
- } ) ;
253
+ } , 30_000 ) ;
257
254
}
258
255
259
256
/**
260
257
* @param {string[] } actual
261
258
* @param {string[] } expected
262
259
*/
263
260
function has_warnings ( actual , expected ) {
264
- assert . equal ( actual . length , expected . length ) ;
265
- assert . equal (
266
- actual . filter ( ( warning ) => expected . some ( ( str ) => warning . startsWith ( str ) ) ) . length ,
267
- expected . length
268
- ) ;
261
+ expect ( actual . length ) . toEqual ( expected . length ) ;
262
+ expect (
263
+ actual . filter ( ( warning ) => expected . some ( ( str ) => warning . startsWith ( str ) ) ) . length
264
+ ) . toEqual ( expected . length ) ;
269
265
}
270
266
271
267
test ( 'validates package (1)' , ( ) => {
@@ -320,7 +316,7 @@ test('validates package (all ok 1)', () => {
320
316
peerDependencies : { svelte : '^3.55.0' }
321
317
} ) ;
322
318
323
- assert . equal ( warnings . length , 0 ) ;
319
+ expect ( warnings . length ) . toEqual ( 0 ) ;
324
320
} ) ;
325
321
326
322
test ( 'validates package (all ok 2)' , ( ) => {
@@ -338,7 +334,5 @@ test('validates package (all ok 2)', () => {
338
334
svelte : './dist/C.svelte'
339
335
} ) ;
340
336
341
- assert . equal ( warnings . length , 0 ) ;
337
+ expect ( warnings . length ) . toEqual ( 0 ) ;
342
338
} ) ;
343
-
344
- test . run ( ) ;
0 commit comments