我正在使用vue-cli 3.0,并创建了具有手动功能的项目,选择了单元测试(mocha + chai)。默认文件匹配为:tests/unit
中以.spec.(ts|js)
结尾的任何文件。有什么方法可以更改目标目录和文件模式?
我要将目标目录从tests/unit
更改为package.json文件所在的root directory
。但是我找不到如何更改目标目录。
然后我尝试过更改文件模式。但这不起作用。
"scripts": {
"test:unit": "vue-cli-service test:unit --glob '*.test.js'"
}
我也读过这篇文章:https://github.com/vuejs/vue-cli/issues/1245。我需要@iamceege
确切说的话。我应该在没有默认设置的情况下自行设置测试环境吗?
答案 0 :(得分:1)
package.json
"scripts": {
...,
"test": "vue-cli-service test:unit --watch --recursive 'src/**/*_test.ts'",
...
},
官方文档
答案 1 :(得分:0)
尝试不使用双引号引起来
"scripts": {
"test:unit": "vue-cli-service test:unit --glob *.test.js"
}
答案 2 :(得分:0)
在您的 jest.config.js
文件中,您可以定义一个 testMatch
变量。完整选项here。
既然你想要根目录,你可以试试这样的:
// inside jest.config.js
testMatch: [
'*.test.js']
请注意,您可以在数组中链接多个选择器。