Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jestjs 原因/Bucklescript+;bs jest:如何在_tests__.文件夹外使用*.test.re模式编译文件?_Jestjs_Reason_Bucklescript_Bs Jest - Fatal编程技术网

Jestjs 原因/Bucklescript+;bs jest:如何在_tests__.文件夹外使用*.test.re模式编译文件?

Jestjs 原因/Bucklescript+;bs jest:如何在_tests__.文件夹外使用*.test.re模式编译文件?,jestjs,reason,bucklescript,bs-jest,Jestjs,Reason,Bucklescript,Bs Jest,背景: 我目前正在使用bs jest进行单元测试。此外,我正在使用bsb init项目,这意味着我首先使用Reason/Bucklescript+编译文件,然后使用Webpack运行编译后的文件 默认情况下Jest将拾取包含单词test的文件,例如component.test.js,默认情况下Jest将拾取该文件 默认情况下,Bs jest将工作,文件将放在\uuuu tests\uuu目录中。但是,遵循*.test.re模式的规范文件,放在我的组件文件夹中,即放在\uuuuuu tests\u

背景:

我目前正在使用bs jest进行单元测试。此外,我正在使用bsb init项目,这意味着我首先使用Reason/Bucklescript+编译文件,然后使用Webpack运行编译后的文件

默认情况下Jest将拾取包含单词test的文件,例如component.test.js,默认情况下Jest将拾取该文件

默认情况下,Bs jest将工作,文件将放在
\uuuu tests\uuu
目录中。但是,遵循
*.test.re
模式的规范文件,放在我的组件文件夹中,即放在
\uuuuuu tests\uuuuuu
以外的文件夹中,将不会编译为相应的
*test.js
文件

目标:

汇编:

├── Components
|   ├── toolbar
|   |   └── toolbar.re
|   |   └── toolbar.test.re
致:

然后让Jest运行并按默认情况下当前的方式工作


任何帮助都不胜感激。多谢各位

这与以下事实有关:在bsconfig.json中,您的包被标记为dev。这意味着它将无法在非dev源(如src文件夹)中获取。通过将其移动到常规依赖项,它将按预期工作


这就是说,现在您可以理解体系结构,因为编译的原因,它为什么会在自己的文件夹中

我在两个项目中使用了bs jest,其中测试不在根级别
\uuuu tests\uuu
目录中,因为我更喜欢使用
src/test
。为了运行测试和收集覆盖率,您需要调整jest的运行方式。通常,您只需要添加
--env=jsdom
并指定目录,例如:

“test”:“jest--env=jsdom--testMatch='**/test/*test.{js,re}'--watch”


您可以自定义
package.json中的testfiles路径,例如:

  ...

  "scripts": {
    "test": "jest",
    "watch:test": "jest --watchAll",
  },

  ...

  "jest": {
    "verbose": true,
    "testEnvironment": "jsdom",
    "testMatch": [
      "**/tests_jest/*.{js,re}",
      "**/tests_jest_blablabla/*.{js,re}"
    ]
  }

如果您的意思是bs jest,那么您不希望将jest作为非开发依赖项。您的应用程序不需要jest来运行,因此它永远不应该是运行时依赖项。
  ...

  "scripts": {
    "test": "jest",
    "watch:test": "jest --watchAll",
  },

  ...

  "jest": {
    "verbose": true,
    "testEnvironment": "jsdom",
    "testMatch": [
      "**/tests_jest/*.{js,re}",
      "**/tests_jest_blablabla/*.{js,re}"
    ]
  }