Skip to content

Commit 0e2f613

Browse files
committed
chore: remove mocha/sinon/chai/karma
1 parent 4cbba2d commit 0e2f613

File tree

13 files changed

+94
-1313
lines changed

13 files changed

+94
-1313
lines changed

karma.conf.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ function createEsbuildPlugin(filteredPkgList) {
226226
}
227227

228228
const pkgList = {
229-
"react/utils": "@preact/signals-react/utils",
230229
"react/runtime": "@preact/signals-react/runtime",
231-
"react-transform": "@preact/signals-react-transform",
232230
};
233231

234232
module.exports = function (config) {

package.json

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,11 @@
2222
"lint:oxlint": "oxlint 'packages/**/*.{ts,tsx,js,jsx}'",
2323
"lint:tsc": "tsc -p tsconfig.json --noEmit",
2424
"lint-staged": "lint-staged",
25-
"test": "pnpm test:karma && pnpm test:mocha && pnpm test:vitest",
26-
"test:minify": "pnpm test:karma:minify && pnpm test:mocha",
27-
"test:prod": "pnpm test:karma:prod && pnpm test:mocha:prod",
28-
"test:karma": "cross-env COVERAGE=true karma start karma.conf.js --single-run",
29-
"test:karma:minify": "cross-env COVERAGE=true MINIFY=true karma start karma.conf.js --single-run",
30-
"test:karma:watch": "karma start karma.conf.js --no-single-run",
31-
"test:karma:prod": "cross-env MINIFY=true NODE_ENV=production karma start karma.conf.js --single-run",
32-
"test:karma:prod:watch": "cross-env NODE_ENV=production karma start karma.conf.js --no-single-run",
33-
"test:mocha": "cross-env COVERAGE=true mocha --require test/node/setup.js --recursive packages/*/test/node/**.test.tsx --ignore \"packages/{preact/utils,preact,core,react}\"",
34-
"test:mocha:prod": "cross-env COVERAGE=true NODE_ENV=production mocha --require test/node/setup.js --recursive packages/*/test/node/**.test.tsx --ignore \"packages/{preact/utils,preact,core,react}\"",
25+
"test": "pnpm test:vitest",
26+
"test:minify": "pnpm test:vitest:prod",
27+
"test:prod": "pnpm test:vitest:prod",
3528
"test:vitest": "cross-env COVERAGE=true vitest run",
29+
"test:vitest:prod": "cross-env COVERAGE=true MINIFY=true vitest run",
3630
"docs:start": "cd docs && pnpm start",
3731
"docs:build": "cd docs && pnpm build",
3832
"docs:preview": "cd docs && pnpm preview",
@@ -62,39 +56,23 @@
6256
"@changesets/cli": "^2.27.1",
6357
"@preact/signals-react-transform": "workspace:*",
6458
"@types/babel__traverse": "^7.18.5",
65-
"@types/chai": "^4.3.3",
66-
"@types/mocha": "^9.1.1",
6759
"@types/node": "^18.19.103",
68-
"@types/sinon": "^10.0.13",
69-
"@types/sinon-chai": "^3.2.8",
7060
"@vitest/browser": "^3.2.4",
7161
"@vitest/coverage-v8": "^3.2.4",
7262
"babel-plugin-istanbul": "^6.1.1",
7363
"babel-plugin-transform-rename-properties": "^0.1.0",
7464
"buffer": "^6.0.3",
75-
"chai": "^4.3.6",
7665
"cross-env": "^7.0.3",
7766
"errorstacks": "^2.4.0",
7867
"esbuild": "^0.14.54",
7968
"husky": "^8.0.1",
80-
"karma": "6.4.2",
81-
"karma-chai-sinon": "^0.1.5",
82-
"karma-chrome-launcher": "^3.1.1",
83-
"karma-coverage": "^2.2.0",
84-
"karma-esbuild": "^2.2.5",
85-
"karma-mocha": "^2.0.1",
86-
"karma-mocha-reporter": "^2.2.5",
87-
"karma-sinon": "^1.0.5",
8869
"kolorist": "^1.5.1",
8970
"lint-staged": "^14.0.1",
9071
"microbundle": "^0.15.1",
91-
"mocha": "^10.0.0",
9272
"oxlint": "^1.3.0",
9373
"playwright": "^1.53.1",
9474
"prettier": "^3.6.2",
9575
"shx": "^0.3.4",
96-
"sinon": "^14.0.0",
97-
"sinon-chai": "^3.7.0",
9876
"typescript": "~5.8.3",
9977
"vitest": "^3.2.4",
10078
"vite": "^6.3.5"

packages/react/runtime/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"@preact/signals-core": "workspace:^1.3.0",
2222
"use-sync-external-store": "^1.2.0"
2323
},
24+
"devDependencies": {
25+
"@preact/signals-react": "workspace:*"
26+
},
2427
"peerDependencies": {
2528
"react": "^16.14.0 || 17.x || 18.x"
2629
}

packages/react/runtime/test/browser/mounts.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
createRoot,
1010
type Root,
1111
} from "../../../test/shared/utils.js";
12+
import { describe, beforeEach, afterEach } from "vitest";
1213

1314
describe("@preact/signals-react/runtime", () => {
1415
describe("mounting", () => {
@@ -25,7 +26,7 @@ describe("@preact/signals-react/runtime", () => {
2526
beforeEach(async () => {
2627
scratch = document.createElement("div");
2728
document.body.appendChild(scratch);
28-
getConsoleErrorSpy().resetHistory();
29+
getConsoleErrorSpy().mockClear();
2930

3031
root = await createRoot(scratch);
3132
});

packages/react/runtime/test/browser/suspense.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
checkHangingAct,
1616
getConsoleErrorSpy,
1717
} from "../../../test/shared/utils";
18+
import { beforeEach, afterEach, describe, it, expect } from "vitest";
1819

1920
describe("Suspense", () => {
2021
let scratch: HTMLDivElement;
@@ -28,7 +29,7 @@ describe("Suspense", () => {
2829
scratch = document.createElement("div");
2930
document.body.appendChild(scratch);
3031
root = await createRoot(scratch);
31-
getConsoleErrorSpy().resetHistory();
32+
getConsoleErrorSpy().mockClear();
3233
});
3334

3435
afterEach(async () => {

packages/react/runtime/test/browser/updates.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
33

44
import { updateSignalsTests } from "../../../test/shared/updates";
5+
import { describe } from "vitest";
56

67
describe("@preact/signals-react/runtime", () => {
78
describe("updating", () => {

packages/react/runtime/test/browser/useSignals.test.tsx

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
checkHangingAct,
99
getConsoleErrorSpy,
1010
} from "../../../test/shared/utils";
11+
import { describe, expect, beforeEach, afterEach, vi, it } from "vitest";
1112

1213
const MANAGED_COMPONENT = 1;
1314
const MANAGED_HOOK = 2;
@@ -52,7 +53,7 @@ describe("useSignals", () => {
5253
scratch = document.createElement("div");
5354
document.body.appendChild(scratch);
5455
root = await createRoot(scratch);
55-
getConsoleErrorSpy().resetHistory();
56+
getConsoleErrorSpy().mockClear();
5657
});
5758

5859
afterEach(async () => {
@@ -142,23 +143,23 @@ describe("useSignals", () => {
142143
});
143144

144145
it("should not rerender components when signals they use do not change", async () => {
145-
const child1Spy = sinon.spy();
146+
const child1Spy = vi.fn();
146147
const signal1 = signal(0);
147148
function Child1() {
148149
child1Spy();
149150
useSignals();
150151
return <p>{signal1.value}</p>;
151152
}
152153

153-
const child2Spy = sinon.spy();
154+
const child2Spy = vi.fn();
154155
const signal2 = signal(0);
155156
function Child2() {
156157
child2Spy();
157158
useSignals();
158159
return <p>{signal2.value}</p>;
159160
}
160161

161-
const parentSpy = sinon.spy();
162+
const parentSpy = vi.fn();
162163
function Parent() {
163164
parentSpy();
164165
return (
@@ -170,39 +171,39 @@ describe("useSignals", () => {
170171
}
171172

172173
function resetSpies() {
173-
child1Spy.resetHistory();
174-
child2Spy.resetHistory();
175-
parentSpy.resetHistory();
174+
child1Spy.mockClear();
175+
child2Spy.mockClear();
176+
parentSpy.mockClear();
176177
}
177178

178179
resetSpies();
179180
await render(<Parent />);
180181
expect(scratch.innerHTML).to.equal("<p>0</p><p>0</p>");
181-
expect(child1Spy).to.have.been.calledOnce;
182-
expect(child2Spy).to.have.been.calledOnce;
183-
expect(parentSpy).to.have.been.calledOnce;
182+
expect(child1Spy).toHaveBeenCalledOnce();
183+
expect(child2Spy).toHaveBeenCalledOnce();
184+
expect(parentSpy).toHaveBeenCalledOnce();
184185

185186
resetSpies();
186187
await act(() => {
187188
signal1.value += 1;
188189
});
189190
expect(scratch.innerHTML).to.equal("<p>1</p><p>0</p>");
190-
expect(child1Spy).to.have.been.calledOnce;
191-
expect(child2Spy).to.not.have.been.called;
192-
expect(parentSpy).to.not.have.been.called;
191+
expect(child1Spy).toHaveBeenCalledOnce();
192+
expect(child2Spy).not.toHaveBeenCalled();
193+
expect(parentSpy).not.toHaveBeenCalled();
193194

194195
resetSpies();
195196
await act(() => {
196197
signal2.value += 1;
197198
});
198199
expect(scratch.innerHTML).to.equal("<p>1</p><p>1</p>");
199-
expect(child1Spy).to.not.have.been.called;
200-
expect(child2Spy).to.have.been.calledOnce;
201-
expect(parentSpy).to.not.have.been.called;
200+
expect(child1Spy).not.toHaveBeenCalled();
201+
expect(child2Spy).toHaveBeenCalledOnce();
202+
expect(parentSpy).not.toHaveBeenCalled();
202203
});
203204

204205
it("should not rerender components when signals they use change but they are not mounted", async () => {
205-
const child1Spy = sinon.spy();
206+
const child1Spy = vi.fn();
206207
const signal1 = signal(0);
207208
function Child() {
208209
child1Spy();
@@ -231,11 +232,11 @@ describe("useSignals", () => {
231232
await act(() => {
232233
signal1.value += 1;
233234
});
234-
expect(child1Spy).to.have.been.calledTwice;
235+
expect(child1Spy).toHaveBeenCalledTimes(2);
235236
});
236237

237238
it("should not rerender components that only update signals in event handlers", async () => {
238-
const buttonSpy = sinon.spy();
239+
const buttonSpy = vi.fn();
239240
function AddOneButton({ num }: { num: Signal<number> }) {
240241
useSignals();
241242
buttonSpy();
@@ -250,7 +251,7 @@ describe("useSignals", () => {
250251
);
251252
}
252253

253-
const displaySpy = sinon.spy();
254+
const displaySpy = vi.fn();
254255
function DisplayNumber({ num }: { num: Signal<number> }) {
255256
useSignals();
256257
displaySpy();
@@ -269,20 +270,20 @@ describe("useSignals", () => {
269270

270271
await render(<App />);
271272
expect(scratch.innerHTML).to.equal("<button>Add One</button><p>0</p>");
272-
expect(buttonSpy).to.have.been.calledOnce;
273-
expect(displaySpy).to.have.been.calledOnce;
273+
expect(buttonSpy).toHaveBeenCalledOnce();
274+
expect(displaySpy).toHaveBeenCalledOnce();
274275

275276
await act(() => {
276277
scratch.querySelector("button")!.click();
277278
});
278279

279280
expect(scratch.innerHTML).to.equal("<button>Add One</button><p>1</p>");
280-
expect(buttonSpy).to.have.been.calledOnce;
281-
expect(displaySpy).to.have.been.calledTwice;
281+
expect(buttonSpy).toHaveBeenCalledOnce();
282+
expect(displaySpy).toHaveBeenCalledTimes(2);
282283
});
283284

284285
it("should not rerender components that only read signals in event handlers", async () => {
285-
const buttonSpy = sinon.spy();
286+
const buttonSpy = vi.fn();
286287
function AddOneButton({ num }: { num: Signal<number> }) {
287288
useSignals();
288289
buttonSpy();
@@ -297,7 +298,7 @@ describe("useSignals", () => {
297298
);
298299
}
299300

300-
const displaySpy = sinon.spy();
301+
const displaySpy = vi.fn();
301302
function DisplayNumber({ num }: { num: Signal<number> }) {
302303
useSignals();
303304
displaySpy();
@@ -316,42 +317,42 @@ describe("useSignals", () => {
316317
}
317318

318319
function resetSpies() {
319-
buttonSpy.resetHistory();
320-
displaySpy.resetHistory();
320+
buttonSpy.mockClear();
321+
displaySpy.mockClear();
321322
}
322323

323324
resetSpies();
324325
await render(<App />);
325326
expect(scratch.innerHTML).to.equal("<button>Add One</button><p>0</p>");
326-
expect(buttonSpy).to.have.been.calledOnce;
327-
expect(displaySpy).to.have.been.calledOnce;
327+
expect(buttonSpy).toHaveBeenCalledOnce();
328+
expect(displaySpy).toHaveBeenCalledOnce();
328329

329330
resetSpies();
330331
await act(() => {
331332
scratch.querySelector("button")!.click();
332333
});
333334

334335
expect(scratch.innerHTML).to.equal("<button>Add One</button><p>2</p>");
335-
expect(buttonSpy).to.not.have.been.called;
336-
expect(displaySpy).to.have.been.calledOnce;
336+
expect(buttonSpy).not.toHaveBeenCalled();
337+
expect(displaySpy).toHaveBeenCalledOnce();
337338

338339
resetSpies();
339340
await act(() => {
340341
adder.value += 1;
341342
});
342343

343344
expect(scratch.innerHTML).to.equal("<button>Add One</button><p>2</p>");
344-
expect(buttonSpy).to.not.have.been.called;
345-
expect(displaySpy).to.not.have.been.called;
345+
expect(buttonSpy).not.toHaveBeenCalled();
346+
expect(displaySpy).not.toHaveBeenCalled();
346347

347348
resetSpies();
348349
await act(() => {
349350
scratch.querySelector("button")!.click();
350351
});
351352

352353
expect(scratch.innerHTML).to.equal("<button>Add One</button><p>5</p>");
353-
expect(buttonSpy).to.not.have.been.called;
354-
expect(displaySpy).to.have.been.calledOnce;
354+
expect(buttonSpy).not.toHaveBeenCalled();
355+
expect(displaySpy).toHaveBeenCalledOnce();
355356
});
356357

357358
it("should properly rerender components that use custom hooks", async () => {

packages/react/runtime/test/node/renderToStaticMarkup.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { signal, useSignalEffect } from "@preact/signals-react";
22
import { createElement } from "react";
33
import { renderToStaticMarkup } from "react-dom/server";
44
import { mountSignalsTests } from "../../../test/shared/mounting";
5+
import { describe, it, expect, vi } from "vitest";
56

67
describe("@preact/signals-react/runtime", () => {
78
describe("renderToStaticMarkup", () => {
89
mountSignalsTests(el => Promise.resolve(renderToStaticMarkup(el)));
910

1011
it("should not invoke useSignalEffect", async () => {
11-
const spy = sinon.spy();
12+
const spy = vi.fn();
1213
const sig = signal("foo");
1314

1415
function App() {
@@ -18,7 +19,7 @@ describe("@preact/signals-react/runtime", () => {
1819

1920
const html = await renderToStaticMarkup(<App />);
2021
expect(html).to.equal("<p>foo</p>");
21-
expect(spy.called).to.be.false;
22+
expect(spy).not.toHaveBeenCalled();
2223
});
2324
});
2425
});

packages/react/utils/test/browser/index.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "../../../test/shared/utils";
88
import { signal } from "@preact/signals-react";
99
import { createElement } from "react";
10+
import { describe, beforeEach, afterEach, it, expect } from "vitest";
1011

1112
describe("@preact/signals-react-utils", () => {
1213
let scratch: HTMLDivElement;

0 commit comments

Comments
 (0)