-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[WIP] feat(locale): createMockWrapper #2227
Conversation
👍 We may need a |
Pull Request Test Coverage Report for Build 3672
💛 - Coveralls |
@yutingzhao1991 基本 ok 了,抽空帮忙 review 一下 🤓 |
It's a good idea, I'll take some time to try 🧐 |
some conflicts. |
@@ -1,5 +1,7 @@ | |||
/* eslint-disable no-undef, prefer-rest-params */ | |||
const ReactIntl = require('react-intl'); | |||
const { getLocaleFileList } = require('./index'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该不能这样,locale.js 这个文件是在浏览器端执行的,index.js 是在 node 端执行的,这样会导致一些 node 的模块被引用到浏览器中。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createMockWrapper 和 getLocaleFileList 怎么用?
import { createMockWrapper, getLocaleFileList } from 'umi-plugin-locale'
?
在 jest 中执行的时候会去读 package.json 里面的 browser 吗?
感觉似乎下面这样会更好一点:
import { createMockWrapper, getLocaleFileList } from 'umi-plugin-locale/test';
用于测试的单独暴露出来,避免打包到最终的构建产物中。
cc @sorrycc 这个你也看看,未来可能别的插件也有类似的需求,不知道社区流行的做法是什么样的?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对,那我把这个函数移到 mock.js 里
可不可以把功能继承在 umi-test ,类似: // config file
export default {
plugins: [
'umi-plugin-dva', { enableTestWrapper: true },
'umi-plugin-locale', { enableTestWrapper: { configHere: 'xxx' } },
],
}
// test file
import { createWrapper } from 'umi-test';
// createWrapper 默认使用 config 中各个 plugin 的 enableTestWrapper 配置项,也可以在测试文件中修改
const Wrapper = createWrapper({ dva: false, locale: { configHere: 'xxx' } }); umi-test 中的 |
有冲突了。 |
@sorrycc 测试这个方案看看,有没有什么想法。感觉这个要统一考虑。 |
mock 这个可以在 https://github.com/umijs/rfcs 这里起一个 RFC 来设计个通用的方案。 |
Checklist
npm test
passesDescription of change