Skip to content

Commit

Permalink
Remove old custom hook tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewiggins committed Nov 30, 2023
1 parent 50997a7 commit fe0ff1d
Showing 1 changed file with 0 additions and 201 deletions.
201 changes: 0 additions & 201 deletions packages/react-transform/test/node/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit fe0ff1d

Please sign in to comment.