Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to use with next/jest? #356

Open
rbong opened this issue Dec 20, 2024 · 1 comment
Open

Question: How to use with next/jest? #356

rbong opened this issue Dec 20, 2024 · 1 comment
Labels
help wanted Extra attention is needed nextjs

Comments

@rbong
Copy link

rbong commented Dec 20, 2024

This works great with Next.js, however it does not work out-of-the-box with next/jest.js.

I am really not sure if this fits in this repo but I thought I would ask since this is the place for Typia/Next.js support currently - is there any proper way around this, and will you support it?

You can check out the source for next/jest here if you want.

The important part is that it sets up a transform for all JS/TS files to the Next.js SWC Jest transformer.

So I guess it uses SWC but it doesn't load webpack plugins (I think?) which makes sense in Jest. (Does unplugin-typia/next force Webpack or use the SWC Webpack loader? Not sure.)

But what is the proper solution? A generic Typia Jest transformer? Would that go here or require a new project?

How I picture it eventually working is maybe something like this:

import nextJest from "next/jest.js";

const createJestConfig = nextJest({
  dir: "./",
});

const config = createJestConfig({
  transform: {
    "^.+\\.(ts|tsx)$": "@ryoppippi/unplugin-typia/next/jest",
  },
  /* Other options go here */
});

export default config;

EDIT: Previously I included a workaround, but it stopped working after I cleared my Jest cache. I'm considering Vitest.

@ryoppippi ryoppippi added help wanted Extra attention is needed nextjs labels Jan 16, 2025
@ryoppippi
Copy link
Owner

ryoppippi commented Jan 25, 2025

Hmm, so jest doesn't use webpack plugin?
idk how to do it, but if you use vitest or bun test you can use this plugin for sure. I recommend to switch to vitest or bun test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed nextjs
Projects
None yet
Development

No branches or pull requests

2 participants