用玩笑测试两个环境 [英] Testing two environments with jest

查看:16
本文介绍了用玩笑测试两个环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置两个不同的环境,并且能够在监视模式下运行.

I'd like to set two different environments and be able to run both in watch mode.

|-- /server
|     |-- index.js  <-  Node
|-- /client
|     |-- index.js  <-  jsdom
|-- package.json

实际上我为每个环境运行两次 jest,为每个环境提供不同的配置文件:

Actually I run jest twice for each environment, providing a different config file for each:

$ yarn test -- --config=server.config.json
$ yarn test -- --config=client.config.json 

但这并不能让我同时运行两者.

But this doesn't let me run both at the same time.

推荐答案

编辑(2018 年 1 月):

现在可以这样做(自 Jest v20 起),该选项称为 projects.阅读有关文档的更多信息.

It is now possible to do so (since Jest v20), and the option is called projects. Read more about it the docs.

基本上你可以定义一个你希望 Jest 在其中运行的项目数组:

Basically you can define an array of your projects you want Jest to be run within:

{
  "projects": ["<rootDir>/client", "<rootDir>/server", "<rootDir>/some-glob/*"]
}

请记住,每个项目都需要有自己的配置.如果您希望自动获取配置,请将其放在 jest.config.js 文件中或通常放在 package.json 中.

Just remember every project needs to have its own config. If you want the config to be picked up automatically, put it inside jest.config.js file or like usually in package.json.

如果您更喜欢将配置放在其他地方(例如在 configs/jest.js 中),您需要指向配置文件的路径(使用 rootDir选项设置正确):

If you prefer placing your config somewhere else (e.g. in configs/jest.js), you'll need to point to the path of the config file (with the rootDir option set properly):

{
  "projects": ["<rootDir>/client/configs/jest.js", "<rootDir>/server/configs/jest.js"]
}

原始答案:

目前这是不可能的,但这种情况有一个问题:https://github.com/facebook/jest/issues/1206.

Currently this is not possible, but there's an issue for that case: https://github.com/facebook/jest/issues/1206.

随时加入并发表评论!

这篇关于用玩笑测试两个环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆