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

[FR]: Recommended way to refer to a central jest.config.js #107

Open
1 task
lromor opened this issue Feb 27, 2023 · 4 comments
Open
1 task

[FR]: Recommended way to refer to a central jest.config.js #107

lromor opened this issue Feb 27, 2023 · 4 comments
Assignees
Labels
question This issue is a question. Close the loop with documentation?

Comments

@lromor
Copy link

lromor commented Feb 27, 2023

What is the current behavior?

Currently there's no way to refer to a jest configuration situated in parent packages.
The current solution is to copy jest.config.js in each folder.

Describe the feature

Have an argument or a type to refer to the common jest.config.js. Something similar to ts_config?
I suspect I could write a macro and perform a copy_to_bin, but I'm not sure if it's the right approach.

What do you think?

Fund our work

@lromor lromor added the enhancement New feature or request label Feb 27, 2023
@github-actions github-actions bot added the untriaged Requires traige label Feb 27, 2023
@lromor
Copy link
Author

lromor commented Feb 28, 2023

My current solution is to simply create a ts_project:

ts_project(
    name = "jestconfig",
    srcs = ["jest.config.ts"],
    tsconfig = {
        "allowJs": True,
    },
    allow_js = True,
    deps = [
        "//:node_modules/@types/node",
    ]
)

which can now be referenced as a config and is correctly resolved. Maybe I could wrap this into a macro and that should be it. Anyways, thank you aspect-build for making such a solid bazel framework for javascript and alike. Really beautiful work!

@Aghassi
Copy link

Aghassi commented Feb 28, 2023

I was talking to @mattem about this and the pattern I'm considering doing to keep editor support is to just make a config that is exported as a first class NPM package and then referenced like one. This gives you two things:

  1. IDE support and editor support (just use extends in the config and don't worry about the rest)
  2. You get the config for free through the node_modules graph that rules_js provides

At least, that is what we are gonna try and pursue

@gregmagolan
Copy link
Member

gregmagolan commented Mar 6, 2023

Is the problem you're hitting when your jest config is in a parent package that you need a copy_to_bin there so that you can pass it to the jest_test config attribute?

Using a ts_project to transpile your jest.config.ts to a jest.config.js is a fine way to go IMO. If your jest config is already a js file then you could alternately use a js_library instead of a copy_to_bin which is cleaner to read.

@gregmagolan gregmagolan added question This issue is a question. Close the loop with documentation? and removed enhancement New feature or request untriaged Requires traige labels Mar 6, 2023
@gregmagolan gregmagolan self-assigned this Mar 6, 2023
@Aghassi
Copy link

Aghassi commented Jun 29, 2023

I'm chiming in here again because we are crossing this bridge. The solution/pattern I've always used is to make your central config an NPM package and then have other npm packages rely on it via workspace:*. Then those apps have jest.config.js which imports a config normally. Finally, you can have jest_test point the jest_config bit at the local file to the package. Does that make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question This issue is a question. Close the loop with documentation?
Projects
Status: 🏗 In progress
Development

No branches or pull requests

3 participants