我想为下面的代码添加模拟响应,我该怎么做?
import { Storage } from "@google-cloud/storage";
const storage = new Storage();
import a from "./a.js"
export function abc(req, res) {
a().then(result ->{
const bucketName = result.bucketName;
const fileName = "Sample.json";
const file = storage.bucket(bucketName).file(result.fileName);
const myfile = file.createReadStream();
let buffer = "";
myfile
.on("data", function(a) {
buffer += a;
})
.on("end", function() {
console.log(buffer);
res.status(200).send(buffer);
});
});
}
从“ ./a.js”导入a是异步函数,我需要使用mocha chai编写单元测试。
为了在Node.js中导出和导入,请遵循以下步骤:
a.js
const a= async () => {
//logic
return result
}
module.exports = { a: a };
云功能
const func = require('./a.js');
//Use the function like following:
func.a()