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

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

问题描述

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

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

实际上,我在每种环境下都开玩笑两次,为每种环境提供了不同的配置文件:

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天全站免登陆