Error: ENOENT: no such file or directory, open '../test/testFiles/shadab.jpeg' test cases for file upload using chai

Error: ENOENT: no such file or directory, open '../test/testFiles/shadab.jpeg' test cases for file upload using chai

我正在尝试使用 Mocha/Chai 测试我的节点 API。我创建了一个 "test" 文件夹,其中包含 File.js,其中包含此代码,同一个测试文件夹包含一个名为 testFile 的文件夹,其中我有一张图像 "shadad.jpeg"。 test.js 文件包含以下代码

describe("/POST upload", () => {
    it("it should POST a single file upload", done => {
        chai
            .request(server)
            .post("/upload")
            .field("Content-Type", "multipart/form-data")
            .attach(
                "file",
                fs.readFileSync("./testFiles/shadab.jpeg"),
                "shadab.jpeg"
            )
            .end((err, res) => {
                res.should.have.status(200);
                res.body.should.be.a("object");
                res.body.should.have.property("success").eql(true);
                done();
            });
    });
});

但是当我执行命令 npm test 时,出现错误

Error: ENOENT: no such file or directory, open '../test/testFiles/shadab.jpeg'

我正在使用 PostMan 测试我的 api 并从表单数据键作为 "file" 发送,值作为文件 "shadab.jpeg" 发送。并得到这个回应。

{
    "success": true,
    "data": "Added Successfully"
}

我在这里做错了什么?请帮忙。

我发现了这个问题 https://github.com/visionmedia/supertest/issues/259
This comment 解决了我的 issue.Check 给定的 github link 以获取更多详细信息。
通过使用像这样 fs.readFileSync(`${__dirname}/testFiles/shadab.jpeg`) 这样的文件的完整路径,它也可以像 Pimento Web 在评论中提到的那样工作。 相对文件路径在测试文件夹中表现异常。
我已经使用 fs.readFileSync("test/testFiles/shadab.jpeg") 并且它对我有用 now.As 我已经在上面的这个问题中提到 test 文件夹包含 testFiles 文件夹并且 shadab.jpegtestFiles文件夹。