问题描述
我正在尝试为我的Next.js项目设置测试.我想使用基于磁带的RITEway对其进行测试.我想要一个 test
命令,该命令可以在我的 src/
文件夹中找到所有以 .test.js
结尾的文件.
I'm trying to set up testing for my Next.js project. I want to test it with RITEway which is based on tape. I want a test
command that finds all files in my src/
folder that end with .test.js
.
这是我提出的建议:
"test": "NODE_ENV=test node -r @babel/register src/**/*.test.js",
我得到了错误:
Error: Cannot find module '/path/to/project/src/**/*.test.js'
如何告诉节点在我的 src/
文件夹中找到所有以 .test.js
结尾的文件?
How can I tell node to find all files ending in .test.js
in my src/
folder?
附加上下文:
我的测试文件位于 src/features/< feature>/< feature.test.js>
中,例如:
My testing files live in src/features/<feature>/<feature.test.js>
, e.g.:
"test": "NODE_ENV=test node -r @babel/register src/features/home/home-page-component.test.js",
找到一个文件并运行它.
Works to find a single file and run it.
"test": "NODE_ENV=test node -r @babel/register src/**/**/*.test.js",
可以找到功能中的所有文件夹,但会忽略我也想运行的文件,例如 src/< file> .test.js
.
Works to find all folders in features, but ignores files like src/<file>.test.js
, which I also want to run.
我必须为节点安装 @ babel/register
和 @ babel/core
,以处理绝对导入和更新的语法.
I had to install @babel/register
and @babel/core
for Node to process absolute imports and newer syntax.
我的 .babelrc
是:
{
"env": {
"test": {
"plugins": [
[
"module-resolver",
{
"root": [
"."
],
"alias": {
"features": "./src/features"
}
}
]
]
}
},
"presets": [
[
"next/babel"
]
],
"plugins": []
}
推荐答案
正如乔恩·夏普(Jon Sharpe)所说,您必须将正则表达式输入 riteway
.
As Jon Sharpe said, you have to feed the regex into riteway
.
"test": "NODE_ENV=test riteway -r @babel/register 'src/**/*.test.js'",
这篇关于找不到带有**/*.test.js的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!