利用create-react-app,在CI管道中运行测试时,如果不满足代码覆盖率阈值,我希望控制台返回非零响应。
package.json
iris %>%
ggplot(aes(x = Species,y = Sepal.Length, fill = factor(group))) +
geom_boxplot(position = position_dodge(width = 1)) +
geom_text(aes(label = outlier), position = position_dodge(width = 1))
在运行"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test:coverage": "npm run test -- --coverage --watchAll=false",
},
"jest": {
"collectCoverageFrom": [
"src/components/**/*.js",
"src/state/**/*.js",
"src/templates/**/*.js",
"src/routes/**/*.js"
],
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
}
时,控制台报告未达到阈值,但仍返回0。据Jest文档了解,当未达到覆盖率阈值时应返回错误。
https://jestjs.io/docs/en/configuration#coveragethreshold-object
特别是...
test:coverage
有人知道这个问题吗?我经历过Jest和CRA github问题,结果不一,大多数发现都与过时的版本有关。
答案 0 :(得分:2)
要在命令失败时停止进一步执行:
import torch
from scipy.signal import convolve
a = torch.tensor([.1, .2, .3, .4, .5])
b = torch.tensor([.0, .1, .0])
a1 = a.view(1, 1, -1)
b1 = torch.flip(b, (0,)).view(1, 1, -1)
print(torch.nn.functional.conv1d(a1, b1).view(-1))
# >>> tensor([0.0200, 0.0300, 0.0400])
print(convolve(a, b))
# >>> [0. 0.01 0.02 0.03 0.04 0.05 0. ]
command || exit 0
答案 1 :(得分:0)
在未满足覆盖阈值时,在 packjage.json
文件中定义配置不会使 jest 命令失败。但是当我通过 jest.config.js
文件定义它时它起作用了!