Skip to content

Commit e02003c

Browse files
chore: switch to vitest
1 parent 3dd80bc commit e02003c

16 files changed

+1981
-943
lines changed

package-lock.json

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

package.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@
4747
"transpile:stream-node": "microbundle src/stream-node.js -o dist/stream/node/index.js -f es,cjs,umd --target node",
4848
"transpile:jsx": "microbundle src/jsx.js -o dist/jsx/index.js -f es,cjs,umd && microbundle dist/jsx/index.js -o dist/jsx/index.js -f cjs",
4949
"copy-typescript-definition": "copyfiles -f src/*.d.ts dist",
50-
"test": "eslint src test && tsc && npm run test:mocha && npm run test:mocha:compat && npm run test:mocha:debug && npm run bench",
51-
"test:mocha": "BABEL_ENV=test mocha -r @babel/register -r test/setup.js test/*.test.jsx",
52-
"test:mocha:compat": "BABEL_ENV=test mocha -r @babel/register -r test/setup.js 'test/compat/*.test.js' 'test/compat/*.test.jsx'",
53-
"test:mocha:debug": "BABEL_ENV=test mocha -r @babel/register -r test/setup.js 'test/debug/*.test.jsx'",
50+
"test": "eslint src/**/* test/**/* && tsc && npm run test:vitest:run && npm run bench",
51+
"test:vitest": "vitest",
52+
"test:vitest:run": "vitest run",
5453
"format": "prettier src/**/*.{d.ts,js} test/**/*.js --write",
5554
"prepublishOnly": "npm run build",
5655
"release": "npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
@@ -135,21 +134,18 @@
135134
"@changesets/cli": "^2.18.0",
136135
"baseline-rts": "npm:preact-render-to-string@latest",
137136
"benchmarkjs-pretty": "^2.0.1",
138-
"chai": "^4.2.0",
139137
"check-export-map": "^1.3.1",
140138
"copyfiles": "^2.4.1",
141139
"eslint": "^7.16.0",
142140
"eslint-config-developit": "^1.2.0",
143141
"husky": "^4.3.6",
144142
"lint-staged": "^10.5.3",
145143
"microbundle": "^0.15.1",
146-
"mocha": "^8.2.1",
147144
"preact": "^10.24.0",
148145
"prettier": "^2.2.1",
149146
"pretty-format": "^3.8.0",
150-
"sinon": "^9.2.2",
151-
"sinon-chai": "^3.5.0",
152147
"typescript": "^5.0.0",
148+
"vitest": "^3.2.4",
153149
"web-streams-polyfill": "^3.2.1"
154150
},
155151
"prettier": {
@@ -171,4 +167,4 @@
171167
"publishConfig": {
172168
"provenance": true
173169
}
174-
}
170+
}

test/compat/async.test.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { renderToStringAsync } from '../../src/index.js';
22
import { h, Fragment } from 'preact';
33
import { Suspense, useId, lazy, createContext } from 'preact/compat';
4-
import { expect } from 'chai';
4+
import { expect, describe, it } from 'vitest';
55
import { createSuspender } from '../utils.jsx';
66
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
77

@@ -286,8 +286,12 @@ describe('Async renderToString', () => {
286286

287287
const expected = `<ul><!--$s--><li>one</li><!--/$s--><!--$s--><li>two</li><!--/$s--><!--$s--><li>three</li><!--/$s--></ul>`;
288288

289-
suspendedOne.promise.then(() => { void suspendedTwo.resolve();});
290-
suspendedTwo.promise.then(() => { void suspendedThree.resolve();});
289+
suspendedOne.promise.then(() => {
290+
void suspendedTwo.resolve();
291+
});
292+
suspendedTwo.promise.then(() => {
293+
void suspendedThree.resolve();
294+
});
291295

292296
suspendedOne.resolve();
293297

test/compat/index.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import render from '../../src/index.js';
22
import { createElement as h, Component } from 'preact/compat';
3-
import { expect } from 'chai';
3+
import { expect, describe, it } from 'vitest';
44

55
describe('compat', () => {
66
it('should not duplicate class attribute when className is empty', async () => {

test/compat/render-chunked.test.js renamed to test/compat/render-chunked.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { h } from 'preact';
2-
import { expect } from 'chai';
2+
import { expect, describe, it } from 'vitest';
33
import { Suspense } from 'preact/compat';
44
import { useId } from 'preact/hooks';
55
import { renderToChunks } from '../../src/lib/chunked';
@@ -14,7 +14,7 @@ describe('renderToChunks', () => {
1414
onWrite: (s) => result.push(s)
1515
});
1616

17-
expect(result).to.deep.equal(['<div class="foo">bar</div>']);
17+
expect(result).toEqual(['<div class="foo">bar</div>']);
1818
});
1919

2020
it('should render fallback + attach loaded subtree on suspend', async () => {
@@ -181,7 +181,7 @@ describe('renderToChunks', () => {
181181
suspended2.resolve();
182182
await promise;
183183

184-
expect(result).to.deep.equal([
184+
expect(result).toEqual([
185185
'<div><p>id: P0-0</p><!--preact-island:33-->loading...<!--/preact-island:33--><!--preact-island:36-->loading...<!--/preact-island:36--></div>',
186186
'<div hidden>',
187187
createInitScript(1),

test/compat/stream-node.test.js renamed to test/compat/stream-node.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PassThrough } from 'node:stream';
22
import { h } from 'preact';
3-
import { expect } from 'chai';
3+
import { expect, describe, it } from 'vitest';
44
import { Suspense } from 'preact/compat';
55
import { createSubtree, createInitScript } from '../../src/lib/client';
66
import { renderToPipeableStream } from '../../src/stream-node';
@@ -66,10 +66,10 @@ describe('renderToPipeableStream', () => {
6666
const result = await sink.promise;
6767

6868
expect(result).to.deep.equal([
69-
'<div><!--preact-island:47-->loading...<!--/preact-island:47--></div>',
69+
'<div><!--preact-island:5-->loading...<!--/preact-island:5--></div>',
7070
'<div hidden>',
7171
createInitScript(),
72-
createSubtree('47', '<p>it works</p>'),
72+
createSubtree('5', '<p>it works</p>'),
7373
'</div>'
7474
]);
7575
});

test/compat/stream.test.js renamed to test/compat/stream.test.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*global globalThis*/
22
import { h } from 'preact';
3-
import { expect } from 'chai';
3+
import { expect, beforeAll, describe, it } from 'vitest';
44
import { Suspense } from 'preact/compat';
55
import { createSubtree, createInitScript } from '../../src/lib/client';
66
import { renderToReadableStream } from '../../src/stream';
@@ -42,7 +42,7 @@ function createSink(input) {
4242
}
4343

4444
describe('renderToReadableStream', () => {
45-
before(async () => {
45+
beforeAll(async () => {
4646
// attempt to use native web streams in Node 18, otherwise fall back to a polyfill:
4747
let streams;
4848
try {
@@ -81,11 +81,11 @@ describe('renderToReadableStream', () => {
8181

8282
const result = await sink.promise;
8383

84-
expect(result).to.deep.equal([
85-
'<div><!--preact-island:56-->loading...<!--/preact-island:56--></div>',
84+
expect(result).toEqual([
85+
'<div><!--preact-island:5-->loading...<!--/preact-island:5--></div>',
8686
'<div hidden>',
8787
createInitScript(),
88-
createSubtree('56', '<p>it works</p>'),
88+
createSubtree('5', '<p>it works</p>'),
8989
'</div>'
9090
]);
9191
});

test/context.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import render from '../src/jsx.js';
22
import { h, createContext, Component } from 'preact';
3-
import { expect } from 'chai';
3+
import { expect, describe, it } from 'vitest';
44
import { dedent } from './utils.jsx';
55

66
describe('context', () => {

test/debug/index.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'preact/debug';
22
import render from '../../src/index.js';
33
import { h } from 'preact';
4-
import { expect } from 'chai';
4+
import { expect, describe, it } from 'vitest';
55

66
describe('debug', () => {
77
it('should not throw "Objects are not valid as a child" error', () => {

test/index.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import renderToString from '../src/index.js';
22
import { default as renderToStringPretty, shallowRender } from '../src/jsx.js';
3-
import { expect } from 'chai';
3+
import { expect, describe, it } from 'vitest';
44

55
describe('render-to-string', () => {
66
describe('exports', () => {

0 commit comments

Comments
 (0)