当我直接使用 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从这里复制:learn.microsoft.com: Add a build or release task
最佳答案
遇到了同样的问题,通过向 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)
关于node.js - Azure Pipelines 生成任务测试失败,错误为 : "Must initialize",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54709591/