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

Vitest测试基于FormRender的组件失败 #1378

Open
DevanXU opened this issue Aug 29, 2023 · 2 comments
Open

Vitest测试基于FormRender的组件失败 #1378

DevanXU opened this issue Aug 29, 2023 · 2 comments
Assignees

Comments

@DevanXU
Copy link

DevanXU commented Aug 29, 2023

1.依赖仓库的版本(Dependencies versions):

  • react:18.2.15
  • form-render:2.2.14
  • antd:5.8.4
  • vitest: 0.34.3
  • @testing-library/react: 14.0.0

2.问题描述(Bug description)
vitest测试基于FormRender的组件失败

3.出现问题的 schema demo(Reproduction schema demo)

const schema = {
  // schema包含在以下repo源码中
}

4.最小复现 demo(Reproduction demo)https://github.com/DevanXU/form-render-issue

运行 $ yarn test 即可复现

form-render demo https://codesandbox.io/s/unruffled-flower-jl78h
table-render demo https://codesandbox.io/s/sweet-euler-bdoty
fr-generator demo https://codesandbox.io/s/s13sh

@lhbxs
Copy link
Collaborator

lhbxs commented Aug 31, 2023

没有太关注单测这边,单测用列,也没有及时更新,现在卡点问题是什么呢?

@DevanXU
Copy link
Author

DevanXU commented Sep 1, 2023

无法跑单测啊,连带与FormRender无关的组件都可能失败。出现下面这个错误,在我提供的Demo可以复现这个问题的。

FAIL src/ConfigBox.test.tsx [ src/ConfigBox.test.tsx ]
SyntaxError: Cannot use import statement outside a module
❯ Object.compileFunction node:vm:360:18
❯ Object. node_modules/form-render/lib/form-core/index.js:8:1

Module /Users/devan/src/tmp/formrender/node_modules/antd/es/button/style/index.js:1 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "antd" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.

As a temporary workaround you can try to inline the package by updating your config:

// vitest.config.js
export default {
test: {
server: {
deps: {
inline: [
"antd"
]
}
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants