I'm trying to test the usage of an asynchronous generator using the async and await paradigm.
I have a generator function yielding results from a stream:
async function* getChunkOfData(filepath) {
try {
const inputStream = fs.createReadStream(filepath);
const parser = parse();
await pipelineAsync(inputStream, parser);
for await (const line of parser) {
yield line;
}
} catch (err) {
throw new Error("error while reading csv file: " + err.message);
}
}
I'm getting line by line in my test and using it as input for an asynchronous function. From the test, I'm getting a timeout error and only the first iteration of the for loop is executed. Here my test code:
describe("My test suite", function () {
it("My test", async function () {
try {
const iterator = getChunkOfData("example.csv");
for await (const row of iterator) {
await asyncCall(row);
// some expect logic using chai
}
} catch (err) {
console.log(await err);
assert.throw(err);
}
});
});
Please note, that I've already tried to increase the test timeout, without any better results also because the asyncCall is executed quite fastly.