如何在 VSTS 测试中发布 Jest 单元测试结果? [英] How to publish Jest Unit Test Results in VSTS tests?

查看:24
本文介绍了如何在 VSTS 测试中发布 Jest 单元测试结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些 关于 SO 的问题 特定于版本用于 jest 单元测试在 VSTS 构建测试结果选项卡中发布其结果.但是没有找到合适的解决方案.

I've found some questions on SO specific to version for jest unit test to publish its result in VSTS build Test Results tab. But no proper solution is found.

推荐答案

我已经扔了一些 jest npm 包,比如 tap-xunitjest-json-to-tap 但无法弄清楚它的工作原理.以下步骤对我有用,可以在 VSTS 测试 构建.

I've gone throw some jest npm packages like tap-xunit and jest-json-to-tap but couldn't figure out it to work. Following steps worked for me to get the results to review under Test of VSTS build.

  1. 安装jest-trx-results-processor

# NPM
npm install jest-trx-results-processor --save-dev

# Yarn
yarn add -D jest-trx-results-processor

  • 创建具有以下内容的jestTrxProcessor.js文件:

    var builder = require('jest-trx-results-processor');     
    var processor = builder({
        outputFile: 'jestTestresults.trx' 
    });
    module.exports = processor;
    

  • 更新后的 package.json 文件应如下所示:

    "devDependencies": { 
        "jest": "^23.4.1",
        "jest-trx-results-processor": "0.0.7",
        "jsdom": "^11.12.0",
        ...
    },
    "scripts": {
        "test": "jest"
    },
    "jest": {
        ...,
        "testResultsProcessor": "./jestTrxProcessor.js"
    }
    

  • 添加 npm 任务到 VSTS 构建,用于 npm 测试.这将运行 jest 测试并将结果发布到 jestTestresults.trx

  • Add npm task to VSTS build for npm test. This will run jest tests and publish results to jestTestresults.trx

    您将能够看到 JEST 测试以及其他测试.

    You will be able to see JEST tests along with other tests.

    这篇关于如何在 VSTS 测试中发布 Jest 单元测试结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆