代码之家  ›  专栏  ›  技术社区  ›  Liero

Azure管道生成任务测试失败,错误为:“必须初始化”

  •  0
  • Liero  · 技术社区  · 6 年前

    当我直接使用node调用index.js时,它可以工作,但是当我运行mocha测试时,任务失败,并显示“必须初始化”错误消息。

    我的任务index.ts如下所示:

    import * as path from "path";
    import tl = require('azure-pipelines-task-lib/task');
    import trm = require('azure-pipelines-task-lib/toolrunner');
    import os = require('os');
    
    async function run() {
        try {
            const libmanJson = tl.getPathInput('libmanjson', true, true); //this throws
        }
        catch (err) {
            console.log(err.message);
            tl.setResult(tl.TaskResult.Failed, err.message);
        }
    }
    

    mocha tests 从这里复制: docs.microsoft.com: Add a build or release task

    0 回复  |  直到 6 年前
        1
  •  0
  •   Scott    6 年前

    遇到同样的问题,通过向TaskMockRunner提供答案来解决

    let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
        "which": {
            "echo": "/mocked/tools/echo"
        },
        "exec": {
            "/mocked/tools/echo Hello, from task!": {
                "code": 0,
                "stdout": "atool output here",
                "stderr": "atool with this stderr output"            
            }
        }
    };
    tmr.setAnswers(a)
    
    推荐文章