Skip to content

Commit

Permalink
[INTERNAL] Resource: getStream for empty string
Browse files Browse the repository at this point in the history
Improve documentation and variable naming
  • Loading branch information
tobiasso85 committed Jun 17, 2020
1 parent 1b9160f commit 914922c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/lib/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@ function createBasicResource(fileName = "index.html") {
return resource;
}

/**
* Reads a readable stream and resolves with its content
*
* @param {stream.Readable} readableStream readable stream
* @returns {Promise<string>} resolves with the read string
*/
const readStream = (readableStream) => {
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
let streamedResult = "";
readableStream.on("data", (chunk) => {
streamedResult += chunk;
});
readableStream.on("end", () => {
resolve(streamedResult);
});
readableStream.on("error", (err) => {
reject(err);
});
});
};

Expand Down Expand Up @@ -178,8 +187,8 @@ test("Resource: clone resource with stream", (t) => {

test("getStream for empty file: correctly retrieved", async (t) => {
const resource = createBasicResource("empty.js");
const string = await readStream(resource.getStream());
t.is(string, "", "empty content");
const result = await readStream(resource.getStream());
t.is(result, "", "empty content");
});

test("getStream with createStream callback content: Subsequent content requests should throw error due " +
Expand Down

0 comments on commit 914922c

Please sign in to comment.