@ discord/ jest- 处理器- discord- intl
一个处理器插件,用于 Jest 处理 intl 信件定义和翻译 @discord/intl。 。 。 .
在您的 Jest 配置中, 将此添加为消息文件模式的变压器 :
module.exports = {
transform: {
// Order matters here! Even though this is an Object, Jest still processes these first to
// last (object insertion order). These patterns can overlap, so we want to put all of the
// special handling first.
[INTL_MESSAGES_FILE_PATTERN]: require.resolve('@discord/jest-processor-discord-intl'),
// ...other transforms, like `*.tsx?` and more.
},
};
您还需要使用 bayl 插件来转换消费代码, 如普通的捆绑 :
// In a custom processor or wherever you configure Babel for Jest:
babel.transform({
// ...
plugins: [
[
require.resolve('@discord/babel-plugin-transform-discord-intl'),
{
// Jest does _not_ resolve these to absolute paths, so tell the plugin to use the
// original import paths instead of resolving them like it does for Metro.
preserveImportSource: true,
extraImports: {
'@app/intl': ['t', 'untranslated', 'international'],
},
},
],
],
});