Skip to content

Commit af67350

Browse files
committed
test: migrate react-transform to vitest
1 parent 8088b5e commit af67350

File tree

7 files changed

+25
-7
lines changed

7 files changed

+25
-7
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"@babel/standalone": "^7.27.7",
6161
"@changesets/changelog-github": "^0.5.0",
6262
"@changesets/cli": "^2.27.1",
63+
"@preact/signals-react-transform": "workspace:*",
6364
"@types/babel__traverse": "^7.18.5",
6465
"@types/chai": "^4.3.3",
6566
"@types/mocha": "^9.1.1",

packages/react-transform/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
},
5858
"devDependencies": {
5959
"@babel/core": "^7.22.8",
60+
"@preact/signals-core": "workspace:*",
6061
"@types/babel__core": "^7.20.1",
6162
"@types/babel__helper-module-imports": "^7.18.0",
6263
"@types/babel__helper-plugin-utils": "^7.10.0",

packages/react-transform/test/browser/e2e.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
createRoot,
1414
getConsoleErrorSpy,
1515
} from "../../../react/test/shared/utils";
16+
import { describe, beforeEach, afterEach, expect, it } from "vitest";
17+
import "../../../../test/browser/babel.js";
1618

1719
const customSource = "useSignals-custom-source";
1820
const modules: Record<string, any> = {
@@ -32,8 +34,6 @@ function testRequire(name: string) {
3234
}
3335

3436
async function createComponent(code: string, options?: PluginOptions) {
35-
// `transformSignalCode` is a global helper function added to the global
36-
// namespace by a test helper we've included in the Karma config.
3737
const cjsCode = transformSignalCode(code, options);
3838
// console.log(cjsCode); // Useful when debugging tests.
3939

@@ -55,7 +55,7 @@ describe("React Signals babel transfrom - browser E2E tests", () => {
5555
scratch = document.createElement("div");
5656
document.body.appendChild(scratch);
5757
root = await createRoot(scratch);
58-
getConsoleErrorSpy().resetHistory();
58+
getConsoleErrorSpy().mockClear();
5959
});
6060

6161
afterEach(async () => {

packages/react-transform/test/node/index.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
objMethodComp,
2020
variableHooks,
2121
} from "./helpers";
22+
import { it, describe, expect } from "vitest";
2223

2324
// To help interactively debug a specific test case, add the test ids of the
2425
// test cases you want to debug to the `debugTestIds` array, e.g. (["258",

packages/react/test/shared/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { vi, type MockInstance } from "vitest";
2+
import { vi, expect, type MockInstance } from "vitest";
33
import { act as realAct } from "react-dom/test-utils";
44

55
export interface Root {

pnpm-lock.yaml

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

vitest.config.mjs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ export default defineConfig({
3333
plugins: [
3434
manglePlugin
3535
],
36+
// TODO (43081j): stop faking node globals and sort out the transform
37+
// tests. Either run them in node, or somehow run babel in node but the
38+
// tests in browser
39+
define: {
40+
IS_REACT_ACT_ENVIRONMENT: true,
41+
process: {
42+
env: {}
43+
}
44+
},
3645
test: {
3746
coverage: {
3847
enabled: COVERAGE,
@@ -49,15 +58,15 @@ export default defineConfig({
4958
extends: true,
5059
test: {
5160
include: [
52-
'./packages/{,preact/utils,preact,react}/test/**/*.test.tsx',
53-
'!./packages/{,preact/utils,preact,react}/test/browser/**/*.test.tsx'
61+
'./packages/{,preact/utils,preact,react,react-transform}/test/**/*.test.tsx',
62+
'!./packages/{,preact/utils,preact,react,react-transform}/test/browser/**/*.test.tsx'
5463
],
5564
}
5665
},
5766
{
5867
extends: true,
5968
test: {
60-
include: ['./packages/{,preact/utils,preact,react}/test/browser/**/*.test.tsx'],
69+
include: ['./packages/{,preact/utils,preact,react,react-transform}/test/browser/**/*.test.tsx'],
6170
browser: {
6271
provider: 'playwright',
6372
enabled: true,

0 commit comments

Comments
 (0)