Skip to content

Commit f45d721

Browse files
authored
chore: convert from uvu to vitest (#14145)
1 parent 0548b15 commit f45d721

File tree

7 files changed

+27
-54
lines changed

7 files changed

+27
-54
lines changed

packages/package/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"svelte": "^5.35.5",
3535
"svelte-preprocess": "^6.0.0",
3636
"typescript": "^5.3.3",
37-
"uvu": "^0.5.6"
37+
"vitest": "catalog:"
3838
},
3939
"peerDependencies": {
4040
"svelte": "^3.44.0 || ^4.0.0 || ^5.0.0-next.1"
@@ -50,7 +50,7 @@
5050
"check": "tsc",
5151
"check:all": "tsc && pnpm -r --filter=\"./**\" check",
5252
"format": "pnpm lint --write",
53-
"test": "uvu test \"^index.js$\""
53+
"test": "vitest run"
5454
},
5555
"exports": {
5656
"./package.json": "./package.json"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};

packages/package/test/index.js renamed to packages/package/test/index.spec.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { join, resolve } from 'node:path';
44
import { fileURLToPath } from 'node:url';
55

66
import prettier from 'prettier';
7-
import { test } from 'uvu';
8-
import * as assert from 'uvu/assert';
7+
import { test, expect } from 'vitest';
98

109
import { build, watch } from '../src/index.js';
1110
import { load_config } from '../src/config.js';
@@ -40,13 +39,13 @@ async function test_make_package(path, options) {
4039
const expected_files = walk(ewd, true);
4140
const actual_files = walk(output, true);
4241

43-
assert.equal(actual_files, expected_files);
42+
expect(actual_files).toEqual(expected_files);
4443

4544
const extensions = ['.json', '.svelte', '.ts', 'js', '.map'];
4645
for (const file of actual_files) {
4746
const pathname = join(output, file);
4847
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();
5049

5150
const expected = fs.readFileSync(join(ewd, file));
5251
const actual = fs.readFileSync(join(output, file));
@@ -55,9 +54,9 @@ async function test_make_package(path, options) {
5554
if (extensions.some((ext) => pathname.endsWith(ext))) {
5655
const expected_content = await format(file, expected.toString('utf-8'));
5756
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);
5958
} else {
60-
assert.ok(expected.equals(actual), err_msg);
59+
expect(expected.equals(actual)).toBeTruthy();
6160
}
6261
}
6362
}
@@ -95,26 +94,24 @@ for (const dir of fs.readdirSync(join(__dirname, 'errors'))) {
9594

9695
try {
9796
await build({ cwd, input, output, types: true, config });
98-
assert.unreachable('Must not pass build');
97+
throw new Error('Must not pass build');
9998
} catch (/** @type {any} */ error) {
100-
assert.instance(error, Error);
99+
expect(error).toBeInstanceOf(Error);
101100
switch (dir) {
102101
case 'no-lib-folder':
103-
assert.match(
104-
error.message.replace(/\\/g, '/'),
102+
expect(error.message.replace(/\\/g, '/')).toMatch(
105103
'test/errors/no-lib-folder/src/lib does not exist'
106104
);
107105
break;
108106
// TODO: non-existent tsconfig passes without error
109107
// it detects tsconfig in packages/kit instead and creates package folder
110108
// in packages/kit/package, not sure how to handle and test this yet
111109
// 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');
113111
// break;
114112

115113
default:
116-
assert.unreachable('All error test must be handled');
117-
break;
114+
throw new Error('All error test must be handled');
118115
}
119116
} finally {
120117
rimraf(output);
@@ -191,7 +188,7 @@ if (!process.env.CI) {
191188

192189
/** @param {string} file */
193190
function compare(file) {
194-
assert.equal(read(`package/${file}`), read(`expected/${file}`));
191+
expect(read(`package/${file}`)).toEqual(read(`expected/${file}`));
195192
}
196193

197194
/** @param {string} file */
@@ -253,19 +250,18 @@ if (!process.env.CI) {
253250
remove('src/lib/b.ts');
254251
remove('src/lib/post-error.svelte');
255252
}
256-
});
253+
}, 30_000);
257254
}
258255

259256
/**
260257
* @param {string[]} actual
261258
* @param {string[]} expected
262259
*/
263260
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);
269265
}
270266

271267
test('validates package (1)', () => {
@@ -320,7 +316,7 @@ test('validates package (all ok 1)', () => {
320316
peerDependencies: { svelte: '^3.55.0' }
321317
});
322318

323-
assert.equal(warnings.length, 0);
319+
expect(warnings.length).toEqual(0);
324320
});
325321

326322
test('validates package (all ok 2)', () => {
@@ -338,7 +334,5 @@ test('validates package (all ok 2)', () => {
338334
svelte: './dist/C.svelte'
339335
});
340336

341-
assert.equal(warnings.length, 0);
337+
expect(warnings.length).toEqual(0);
342338
});
343-
344-
test.run();

packages/package/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"moduleResolution": "node16",
1010
"allowSyntheticDefaultImports": true
1111
},
12-
"include": ["*.js", "src/**/*", "test/index.js"]
12+
"include": ["*.js", "src/**/*", "test/index.spec.js"]
1313
}

pnpm-lock.yaml

Lines changed: 3 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)