From fe0ff1d4dd9c67196eda0542b853ed727c6ac334 Mon Sep 17 00:00:00 2001 From: Andre Wiggins Date: Thu, 30 Nov 2023 01:32:15 -0800 Subject: [PATCH] Remove old custom hook tests --- .../react-transform/test/node/index.test.tsx | 201 ------------------ 1 file changed, 201 deletions(-) diff --git a/packages/react-transform/test/node/index.test.tsx b/packages/react-transform/test/node/index.test.tsx index 4ffd4ef9c..097ccaa6a 100644 --- a/packages/react-transform/test/node/index.test.tsx +++ b/packages/react-transform/test/node/index.test.tsx @@ -324,208 +324,7 @@ describe("React Signals Babel Transform", () => { }); }); -// TODO: migrate hook tests - describe("React Signals Babel Transform", () => { - describe("auto mode transformations", () => { - it("transforms custom hook arrow functions with return statement", () => { - const inputCode = ` - const useCustomHook = () => { - return signal.value; - }; - `; - - const expectedOutput = ` - import { useSignals as _useSignals } from "@preact/signals-react/runtime"; - const useCustomHook = () => { - _useSignals(); - return signal.value; - }; - `; - - runTest(inputCode, expectedOutput); - }); - - it("transforms custom hook arrow functions with inline return statement", () => { - const inputCode = ` - const useCustomHook = () => name.value; - `; - - const expectedOutput = ` - import { useSignals as _useSignals } from "@preact/signals-react/runtime"; - const useCustomHook = () => { - _useSignals(); - return name.value; - }; - `; - - runTest(inputCode, expectedOutput); - }); - - it("transforms custom hook function declarations", () => { - const inputCode = ` - function useCustomHook() { - return signal.value; - } - `; - - const expectedOutput = ` - import { useSignals as _useSignals } from "@preact/signals-react/runtime"; - function useCustomHook() { - _useSignals(); - return signal.value; - } - `; - - runTest(inputCode, expectedOutput); - }); - - it("transforms custom hook function expressions", () => { - const inputCode = ` - const useCustomHook = function () { - return signal.value; - } - `; - - const expectedOutput = ` - import { useSignals as _useSignals } from "@preact/signals-react/runtime"; - const useCustomHook = function () { - _useSignals(); - return signal.value; - }; - `; - - runTest(inputCode, expectedOutput); - }); - }); - - describe("manual mode opt-in transformations", () => { - it("transforms custom hook arrow function with leading opt-in JSDoc comment before variable declaration", () => { - const inputCode = ` - /** @trackSignals */ - const useCustomHook = () => { - return useState(0); - }; - `; - - const expectedOutput = ` - import { useSignals as _useSignals } from "@preact/signals-react/runtime"; - /** @trackSignals */ - const useCustomHook = () => { - _useSignals(); - return useState(0); - }; - `; - - runTest(inputCode, expectedOutput, { mode: "manual" }); - }); - - it("transforms custom hook exported as default function declaration with leading opt-in JSDoc comment", () => { - const inputCode = ` - /** @trackSignals */ - export default function useCustomHook() { - return useState(0); - } - `; - - const expectedOutput = ` - import { useSignals as _useSignals } from "@preact/signals-react/runtime"; - /** @trackSignals */ - export default function useCustomHook() { - _useSignals(); - return useState(0); - } - `; - - runTest(inputCode, expectedOutput, { mode: "manual" }); - }); - - it("transforms custom hooks exported as named function declaration with leading opt-in JSDoc comment", () => { - const inputCode = ` - /** @trackSignals */ - export function useCustomHook() { - return useState(0); - } - `; - - const expectedOutput = ` - import { useSignals as _useSignals } from "@preact/signals-react/runtime"; - /** @trackSignals */ - export function useCustomHook() { - _useSignals(); - return useState(0); - } - `; - - runTest(inputCode, expectedOutput, { mode: "manual" }); - }); - }); - - describe("auto mode opt-out transformations", () => { - it("skips transforming custom hook arrow function with leading opt-out JSDoc comment before variable declaration", () => { - const inputCode = ` - /** @noTrackSignals */ - const useCustomHook = () => { - return useState(0); - }; - `; - - const expectedOutput = inputCode; - - runTest(inputCode, expectedOutput, { mode: "auto" }); - }); - - it("skips transforming custom hooks exported as default function declaration with leading opt-out JSDoc comment", () => { - const inputCode = ` - /** @noTrackSignals */ - export default function useCustomHook() { - return useState(0); - } - `; - - const expectedOutput = inputCode; - - runTest(inputCode, expectedOutput, { mode: "auto" }); - }); - - it("skips transforming custom hooks exported as named function declaration with leading opt-out JSDoc comment", () => { - const inputCode = ` - /** @noTrackSignals */ - export function useCustomHook() { - return useState(0); - } - `; - - const expectedOutput = inputCode; - - runTest(inputCode, expectedOutput, { mode: "auto" }); - }); - }); - - describe("auto mode no transformations", () => { - it("skips transforming custom hook function declarations that don't use signals", () => { - const inputCode = ` - function useCustomHook() { - return useState(0); - } - `; - - const expectedOutput = inputCode; - runTest(inputCode, expectedOutput); - }); - - it("skips transforming custom hook function declarations incorrectly named", () => { - const inputCode = ` - function usecustomHook() { - return signal.value; - } - `; - - const expectedOutput = inputCode; - runTest(inputCode, expectedOutput); - }); - }); - // TODO: Figure out what to do with the following describe("all mode transformations", () => {