Getting spfx test result into VSTS
-
07-01-2021 - |
题
I try to get my Unit Test from the spfx test into VSTS. A gulp test
creates in the temp
folder a result.json
. But I found no documentation which file format is this file has?
Trying JUnit format did not work for me. Can I get spfx to produce a test result file that VSTS understands or VSTS to read the format spfx produces?
解决方案
I found a Solution in https://github.com/baywet/spfx-devops-vsts
- Install
karma-junit-reporter
withnpm i karma-junit-reporter -D
Add to
gulpfile.js
// Extending Karma const karmaTask = build.karma; if (karmaTask) { karmaTask.taskConfig.configPath = './config/karma.config.js'; }
Create a
./conig/karma.config.js
with"use strict"; var existingKarmaConfig = require('@microsoft/sp-build-web/lib/karma/karma.config'); var junitReporter = require('karma-junit-reporter'); // based on https://github.com/baywet/spfx-devops-vsts/blob/master/config/karma.config.js module.exports = function (config) { existingKarmaConfig(config); config.reporters.push('junit'); config.junitReporter = { outputDir: 'temp/', // results will be saved as $outputDir/$browserName.xml outputFile: 'test-results.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile suite: 'karma', // suite will become the package name attribute in xml testsuite element useBrowserName: true, // add browser name to report and classes names }; config.plugins.push(junitReporter); };
- In VSTS gulp test Task enable
Publish to TFS/Team Services
in theJUnit Test Results
section and change toTest Results Files
to**/test-*.xml