将结果保存在 Azure DevOps 中 vscode-extension unit-tests 的文件中

Saving result in a file from vscode-extension unit-tests in Azure DevOps

我又遇到问题了...

我尝试根据我在 Azure DevOps 中的持续集成测试制作一份测试报告。我已经编写了如下所述的单元测试:
https://code.visualstudio.com/api/working-with-extensions/testing-extension

我主要按照此处所述编写 yml:
https://code.visualstudio.com/api/working-with-extensions/continuous-integration

现在我想 "publish" 我的测试结果... 我认为要发布它们,我必须以下列格式之一创建一个 XML(或 TRX):JUnit、NUnit 2、NUnit 3、Visual Studio Test (TRX) 和 xUnit 2。 看来我对如何创建 reporter/testrunner 或其他内容很有限...我不明白。

vscode 提供的 API 看起来像:

testRunner.configure({
    ui: "tdd",
    useColors: true
});

module.exports = testRunner;

API 的预期类型是:

 interface MochaSetupOptions {

        //milliseconds to wait before considering a test slow
        slow?: number;

        // timeout in milliseconds
        timeout?: number;

        // ui name "bdd", "tdd", "exports" etc
        ui?: string;

        //array of accepted globals
        globals?: any[];

        // reporter instance (function or string), defaults to `mocha.reporters.Dot`
        reporter?: any;

        // bail on the first test failure
        bail?: boolean;

        // ignore global leaks
        ignoreLeaks?: boolean;

        // grep string or regexp to filter tests with
        grep?: any;

        // colored output from test results
        useColors?: boolean;

        // causes test marked with only to fail the suite
        forbidOnly?: boolean;
    }

我认为我最好的尝试是使用该模块 https://www.npmjs.com/package/mocha-junit-reporter:

testRunner.configure({
    reporter: 'mocha-junit-reporter',
    reporterOptions: {
        mochaFile: './path_to_your/file.xml'
    }
});

我知道它不适合所描述的 API,但是当您查看 vscode-模块的源代码时:

function configure(opts) {
    mocha = new Mocha(opts);
}
exports.configure = configure;

所以它符合 "mocha-junit-reporter" 模块的文档

let a: any = {
    ui: "tdd",
    reporter: "xunit",
    reporterOptions: {
        output: normalize(join(getExtensionRootPath(), "..", "TestResults", "unit-tests", os + ".xml")),
    }        
};

testRunner.configure(a);

除了 Linux 这对我来说是这样的