cypress - Cypress 和 React ts/tsx 代码覆盖没有返回结果。总是 100% 因为没有测试任何东西。仪器代码问题可能
问题描述
目前在使用 React 17.0.2 时根本没有收到任何代码覆盖率。
注意:不使用 react 脚本,因此无法利用 instrument-cra 插件。
我原以为通过@cypress/browserify-preprocessor
typescript 选项会完成仪器代码步骤,但赛普拉斯仍然抱怨。有什么想法吗?
要复制问题:
添加简单的ts函数:(add.ts)
export const add = (a: number, b: number) => {
return a + b;
};
对其进行测试:(add.spec.ts)
import { add } from './add';
it('adds numbers', () => {
expect(add(2, 3)).to.equal(5);
});
内support/index.js
import '@cypress/code-coverage/support'
内plugins/index.js
const webpack = require('@cypress/webpack-preprocessor')
module.exports = (on, config) => {
const options = {
webpackOptions: require('../../webpack.config.coverage.js'),
};
on('file:preprocessor', webpack(options))
// cypress coverage
require('@cypress/code-coverage/task')(on, config);
const browserify = require('@cypress/browserify-preprocessor')
const optionsBrowserify = browserify.defaultOptions
optionsBrowserify.browserifyOptions.transform[1][1].babelrc = true
optionsBrowserify.typescript = require.resolve('typescript')
module.exports = browserify(optionsBrowserify)
return config;
};
里面babelrc.json
:
{
"plugins": [
"istanbul"
],
}
里面webpack.config.coverage
:
module: {
rules: [
{
// when bundling application's own source code
// transpile using Babel which uses .babelrc file
// and instruments code using babel-plugin-istanbul
test: /\.(tsx|ts)$/,
include: path.resolve(__dirname, '../src'),
exclude: /(node_modules|bower_components)/,
use: [
{
loader: 'babel-loader'
}
]
}
]
},
然后运行测试npm or npx cypress open
输出:
错误
通过查看窗口覆盖对象,无法在您的应用程序中找到任何覆盖信息。您是否忘记检测您的应用程序?请参阅代码覆盖率#instrument-your-application [@cypress/code-coverage]
转到上面的链接,没有解决方案按照文档中的建议工作。
解决方案
推荐阅读
- reactjs - 反应:当我得到结果时如何停止 BarcodeScannerComponent
- php - 简单的php脚本,无法返回json
- haskell - wxHaskell 暂时无法使用吗?
- google-apps-script - 如何在任何 G 表格单元格中激活一个宏,该宏将在下一个单元格中复制和粘贴值?
- terraform - Terraform Azure 数据工厂标识
- ruby-on-rails - 从 rails(后端)获取方法的响应到 Vue 模块
- fabricjs - Fabricjs 的对象组未显示且行为不正确
- azure - Azure Functions Core Tools 无法安装绑定所需的扩展,在 Ubuntu 服务器中出现 SSL 错误
- autofac - Autofac 是否支持在 Blazor WebAssembly 延迟加载程序集中注册服务
- javascript - Selenium 问题当在网站上以 DIV 形式提供表格数据时,在 DIV 内我每行都有一个 div