Skip to content

Commit

Permalink
chore: switch from uvu to vitest (#9899)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored May 13, 2023
1 parent 336d8ae commit 9f5642d
Show file tree
Hide file tree
Showing 54 changed files with 639 additions and 410 deletions.
4 changes: 2 additions & 2 deletions packages/adapter-netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"scripts": {
"dev": "rimraf files && rollup -cw",
"build": "rimraf files && rollup -c && cp src/edge.js files/edge.js",
"test": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
"test": "vitest run",
"check": "tsc",
"lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
"format": "pnpm lint --write",
Expand All @@ -48,7 +48,7 @@
"rimraf": "^5.0.0",
"rollup": "^3.7.0",
"typescript": "^4.9.4",
"uvu": "^0.5.6"
"vitest": "^0.31.0"
},
"peerDependencies": {
"@sveltejs/kit": "^1.5.0"
Expand Down
11 changes: 4 additions & 7 deletions packages/adapter-netlify/src/headers.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { expect, test } from 'vitest';
import './shims.js';
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { split_headers } from './headers.js';

test('empty headers', () => {
const headers = new Headers();

const result = split_headers(headers);

assert.equal(result, {
expect(result).toEqual({
headers: {},
multiValueHeaders: {}
});
Expand All @@ -21,7 +20,7 @@ test('single-value headers', () => {

const result = split_headers(headers);

assert.equal(result, {
expect(result).toEqual({
headers: {
// Note: becomes lowercase even if specified as uppercase
location: '/apple',
Expand All @@ -43,12 +42,10 @@ test('multi-value headers', () => {
const result = split_headers(headers);

// it splits at actual cookie boundaries, not the commas in the dates
assert.equal(result, {
expect(result).toEqual({
headers: {},
multiValueHeaders: {
'set-cookie': [`flavor=sugar; Expires=${wednesday}`, `diameter=6cm; Expires=${thursday}`]
}
});
});

test.run();
4 changes: 2 additions & 2 deletions packages/adapter-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"scripts": {
"dev": "rimraf files && rollup -cw",
"build": "rimraf files && rollup -c",
"test": "echo \"tests temporarily disabled\" # c8 uvu tests",
"test": "echo \"tests temporarily disabled\" # c8 vitest run",
"check": "tsc",
"lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
"format": "pnpm lint --write",
Expand All @@ -41,7 +41,7 @@
"rimraf": "^5.0.0",
"sirv": "^2.0.3",
"typescript": "^4.9.4",
"uvu": "^0.5.6"
"vitest": "^0.31.0"
},
"dependencies": {
"@rollup/plugin-commonjs": "^25.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { test } from 'uvu';
import { assert, test } from 'vitest';
import { create_kit_middleware } from '../src/handler.js';
import * as assert from 'uvu/assert';
import fetch from 'node-fetch';
import polka from 'polka';

Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
"format": "pnpm lint --write",
"check": "tsc",
"test": "uvu test .spec.js"
"test": "vitest run"
},
"dependencies": {
"@vercel/nft": "^0.22.6",
Expand All @@ -38,7 +38,7 @@
"@sveltejs/kit": "workspace:^",
"@types/node": "^16.18.6",
"typescript": "^4.9.4",
"uvu": "^0.5.6"
"vitest": "^0.31.0"
},
"peerDependencies": {
"@sveltejs/kit": "^1.5.0"
Expand Down
5 changes: 1 addition & 4 deletions packages/adapter-vercel/test/utils.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { assert, test } from 'vitest';
import { get_pathname } from '../utils.js';

/**
Expand Down Expand Up @@ -34,5 +33,3 @@ test('get_pathname for route with parameters within segment', () => {
'foo-$1/$2-buz'
);
});

test.run();
18 changes: 18 additions & 0 deletions packages/kit/kit.vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'vitest/config';

// this file needs a custom name so that the numerous test subprojects don't all pick it up
export default defineConfig({
test: {
// shave a couple seconds off the tests
isolate: false,
singleThread: true,
include: ['src/**/*.spec.js'],
exclude: [
'**/node_modules/**',
'**/.svelte-kit/**',
'**/.{idea,git,cache,output,temp}/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*'
],
watchExclude: ['**/node_modules/**', '**/.svelte-kit/**']
}
});
6 changes: 3 additions & 3 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"svelte": "^3.56.0",
"svelte-preprocess": "^5.0.3",
"typescript": "^4.9.4",
"uvu": "^0.5.6",
"vite": "^4.3.0"
"vite": "^4.3.0",
"vitest": "^0.31.0"
},
"peerDependencies": {
"svelte": "^3.54.0",
Expand All @@ -66,7 +66,7 @@
"test:integration": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test",
"test:cross-platform:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:dev",
"test:cross-platform:build": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:build",
"test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
"test:unit": "vitest --config kit.vitest.config.js run",
"postinstall": "node postinstall.js"
},
"exports": {
Expand Down
17 changes: 5 additions & 12 deletions packages/kit/src/core/adapt/builder.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { rmSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { expect, test } from 'vitest';
import glob from 'tiny-glob/sync.js';
import { create_builder } from './builder.js';
import { posixify } from '../../utils/filesystem.js';
Expand Down Expand Up @@ -47,29 +46,23 @@ test('copy files', () => {

rmSync(dest, { recursive: true, force: true });

assert.equal(
builder.writeClient(dest),
expect(builder.writeClient(dest)).toEqual(
glob('**', { cwd: dest, dot: true, filesOnly: true }).map(posixify)
);

assert.equal(
glob('**', { cwd: `${outDir}/output/client`, dot: true }),
expect(glob('**', { cwd: `${outDir}/output/client`, dot: true })).toEqual(
glob('**', { cwd: dest, dot: true })
);

rmSync(dest, { recursive: true, force: true });

assert.equal(
builder.writeServer(dest),
expect(builder.writeServer(dest)).toEqual(
glob('**', { cwd: dest, dot: true, filesOnly: true }).map(posixify)
);

assert.equal(
glob('**', { cwd: `${outDir}/output/server`, dot: true }),
expect(glob('**', { cwd: `${outDir}/output/server`, dot: true })).toEqual(
glob('**', { cwd: dest, dot: true })
);

rmSync(dest, { force: true, recursive: true });
});

test.run();
20 changes: 8 additions & 12 deletions packages/kit/src/core/config/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { assert, expect, test } from 'vitest';
import { validate_config, load_config } from './index.js';

const __filename = fileURLToPath(import.meta.url);
Expand Down Expand Up @@ -124,7 +123,7 @@ test('fills in defaults', () => {
const defaults = get_defaults();
defaults.kit.version.name = validated.kit.version.name;

assert.equal(validated, defaults);
expect(validated).toEqual(defaults);
});

test('errors on invalid values', () => {
Expand Down Expand Up @@ -152,7 +151,7 @@ test('errors on invalid nested values', () => {
});

test('does not error on invalid top-level values', () => {
assert.not.throws(() => {
assert.doesNotThrow(() => {
validate_config({
onwarn: () => {}
});
Expand Down Expand Up @@ -187,7 +186,7 @@ test('fills in partial blanks', () => {
config.kit.files.assets = 'public';
config.kit.version.name = '0';

assert.equal(validated, config);
expect(validated).toEqual(config);
});

test('fails if kit.appDir is blank', () => {
Expand Down Expand Up @@ -300,14 +299,13 @@ test('fails if prerender.entries are invalid', () => {
*/
function validate_paths(name, input, output) {
test(name, () => {
assert.equal(
expect(
validate_config({
kit: {
paths: input
}
}).kit.paths,
output
);
}).kit.paths
).toEqual(output);
});
}

Expand Down Expand Up @@ -357,7 +355,7 @@ test('load default config (esm)', async () => {
const defaults = get_defaults(cwd + '/');
defaults.kit.version.name = config.kit.version.name;

assert.equal(config, defaults);
expect(config).toEqual(defaults);
});

test('errors on loading config with incorrect default export', async () => {
Expand All @@ -375,5 +373,3 @@ test('errors on loading config with incorrect default export', async () => {
'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs/configuration'
);
});

test.run();
7 changes: 2 additions & 5 deletions packages/kit/src/core/postbuild/crawl.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { expect, test } from 'vitest';
import { crawl } from './crawl.js';

const fixtures = fileURLToPath(new URL('./fixtures', import.meta.url));
Expand All @@ -18,8 +17,6 @@ for (const fixture of fs.readdirSync(fixtures)) {
// uncomment to see how long it took
// console.error(fixture, Date.now() - start);

assert.equal(output, expected);
expect(output).toEqual(expected);
});
}

test.run();
15 changes: 6 additions & 9 deletions packages/kit/src/core/postbuild/entities.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { assert, test } from 'vitest';
import { decode } from './entities.js';

/*
Expand Down Expand Up @@ -37,24 +36,22 @@ const tests = [

for (const { input, output } of tests) {
test(input, () => {
assert.is(decode(input), output);
assert.equal(decode(input), output);
});
}

test('should HTML decode partial legacy entity', () => {
assert.is(decode('&timesbar'), '×bar');
assert.equal(decode('&timesbar'), '×bar');
});

test('should HTML decode legacy entities according to spec', () => {
assert.is(decode('?&image_uri=1&ℑ=2&image=3'), '?&image_uri=1&ℑ=2&image=3');
assert.equal(decode('?&image_uri=1&ℑ=2&image=3'), '?&image_uri=1&ℑ=2&image=3');
});

test('should back out of legacy entities', () => {
assert.is(decode('&ampa'), '&a');
assert.equal(decode('&ampa'), '&a');
});

test('should parse &nbsp followed by < (#852)', () => {
assert.is(decode('&nbsp<'), '\u00a0<');
assert.equal(decode('&nbsp<'), '\u00a0<');
});

test.run();
19 changes: 8 additions & 11 deletions packages/kit/src/core/postbuild/queue.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { assert, expect, test } from 'vitest';
import { queue } from './queue.js';

/** @param {number} ms */
Expand Down Expand Up @@ -53,26 +52,26 @@ test('starts tasks in sequence', async () => {
});
}

assert.equal(started, [true, true, false, false]);
assert.equal(finished, [false, false, false, false]);
expect(started).toEqual([true, true, false, false]);
expect(finished).toEqual([false, false, false, false]);

fulfils[0]();
await promises[0];

assert.equal(started, [true, true, true, false]);
assert.equal(finished, [true, false, false, false]);
expect(started).toEqual([true, true, true, false]);
expect(finished).toEqual([true, false, false, false]);

fulfils[1]();
await promises[1];

assert.equal(started, [true, true, true, true]);
assert.equal(finished, [true, true, false, false]);
expect(started).toEqual([true, true, true, true]);
expect(finished).toEqual([true, true, false, false]);

fulfils[2]();
fulfils[3]();
await q.done();

assert.equal(finished, [true, true, true, true]);
expect(finished).toEqual([true, true, true, true]);
});

test('q.add fails if queue is already finished', async () => {
Expand Down Expand Up @@ -110,5 +109,3 @@ test('q.done() rejects if task rejects', async () => {
assert.equal(/** @type {Error} */ (e).message, 'nope');
}
});

test.run();
Loading

0 comments on commit 9f5642d

Please sign in to comment.