Frage

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?

War es hilfreich?

Lösung

I found a Solution in https://github.com/baywet/spfx-devops-vsts

  1. Install karma-junit-reporter with npm i karma-junit-reporter -D
  2. Add to gulpfile.js

    // Extending Karma
    const karmaTask = build.karma;
    if (karmaTask) {
      karmaTask.taskConfig.configPath = './config/karma.config.js';
    }
    
  3. 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);
    };
    
  4. In VSTS gulp test Task enable Publish to TFS/Team Services in the JUnit Test Results section and change to Test Results Files to **/test-*.xml VSTS gulp test settings
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top