Closed webDnA2022 closed 10 months ago
In your babel-jest.config.json
try to actually require the packages otherwise jest will try to resolve it from the wrong location.
Also, since these plugins are only used in the babel config file, check if bit recognized these as dependencies of your env.
you can check it with bit show <env-id>
if not, you need to manually set them by bit deps set <env-id> <babel-plugin>
Thanks for the tips! So do I need to convert my json to a js-file to apply require? This example indicates that I can use the config as usual https://bit.dev/reference/babel/babel-config#installing-presets-and-plugins, doesn't it?
I have now added the preset and plugins to the env with bit deps set
as you have described and they are listed when running bit show
.
I have installed, compiled, tagged and exported the component with the updated env and use bit import --merge
to merge it with my local component changes in my other project. But I still receive the error regarding @testing-library/jest-dom
in my tsconfig.json
when running bit build
. It seems that tsconfig.json
does not have access to the type:
✖ env: webdna.react-library/envs/custom-react-env@0.0.9, task "teambit.compilation/compiler:TypescriptCompile" threw an error
error TS2688: Cannot find type definition file for '@testing-library/jest-dom'.
The file is in the program because:
Entry point of type library '@testing-library/jest-dom' specified in compilerOptions
/Users/duc/Library/Caches/Bit/capsules/42500ebf15ac7ef9689ae43af59e721ff218902d/webdna.react-library_library_ui_button@0.0.10/tsconfig.json:22:7
22 "@testing-library/jest-dom"
~~~~~~~~~~~~~~~~~~~~~~~~~~~
File is entry point of type library specified here.
Do you have any other ideas?
I could resolved the part with the macro error. My mistake was that I set macro
as dependency instead of babel-plugin-macros
.
I have also checked on the type for @testing-library/jest-dom
and have replaced it with @types/testing-library__jest-dom
but still the same error message
I could resolved the part with the macro error. My mistake was that I set
macro
as dependency instead ofbabel-plugin-macros
.I have also checked on the type for
@testing-library/jest-dom
and have replaced it with@types/testing-library__jest-dom
but still the same error message
If I remove @types/testing-library__jest-dom
and implement @testing-library/jest-dom
as instructed by its creators like:
// In tsconfig.json
"include": [
...
"./jest-setup.ts"
],
// In your own jest-setup.js (or any other name)
import '@testing-library/jest-dom'
it does not recognized the extended test methods
The following errors were found while running the build pipeline
Failed task 1: "teambit.compilation/compiler:TypescriptCompile" of env "webdna.react-library/envs/custom-react-env@0.0.13"
component: webdna.react-library/library/ui/button@0.0.14
/Users/duc/Library/Caches/Bit/capsules/42500ebf15ac7ef9689ae43af59e721ff218902d/webdna.react-library_library_ui_button@0.0.14/button.spec.tsx:29:40 - error TS2339: Property 'toBeDisabled' does not exist on type 'JestMatchers<HTMLElement>'.
29 expect(screen.getByRole('button')).toBeDisabled();
~~~~~~~~~~~~
Found 1 errors in 1 components
✖ Total 10 tasks. 1 succeeded. 1 failed. 8 skipped. Total errors: 1.
@GiladShoham I was able to resolve the issue. I needed to add the following in the env.jsonc of my custom environment in addition to set the dependency with bit deps set <my-env> @types/testing-library__jest-dom
:
{
"name": "@types/testing-library__jest-dom",
"version": "^5.14.6",
"hidden": true,
"force": true
},
The issue is resolved for now but it left me with open questions.
@types/testing-library__jest-dom
as env dependency to make it available for the components which uses the custom env?env.jsonc
is required when I do not import that specific package in my component but still want to provide it and set force: true
. In the case of @types/testing-library__jest-dom
it provided it to each component which eventually made it work. Is my understanding correct?env.jsonc
from the terminal or do I need to add in manually in the file?Thanks in advance for your effort and time
I'm not available for a few days but I'll try to write you an answer on Sunday
env templates solved to fix this issue. this ticket is stale anyway. closing.
Just to actually respond to the questions left open here:
Description
I have created a react library with a custom environment consisting of jest.config, jest.setup, tsconfig, etc.. Everything works fine, I can push my components to bit.cloud. I can also install and import components from bit.dev.
But when I changed one of the imported component (from bit.cloud) and run
bit build
I receive the following error:Specifications
Context and additional information
The error refers to the tsconfig.json using @testing-library/jest-dom in types. Does the environment do not have access to the node_modules? Below is my tsconfig.json
When I run
bit test
I receive the following error message:Some other configs that I am using:
How can I solve this issue? I am happy for any hints.
Thank you! Duc