Skip to content

Commit

Permalink
Add comment to serveResource test
Browse files Browse the repository at this point in the history
The resource is drained because it is piped in the serveResources
middleware. Therefore the getStream and pipe functionality is stubbed.
Such that its content can be compared in the test.
  • Loading branch information
tobiasso85 committed Jul 29, 2019
1 parent e902004 commit e0d424f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions test/lib/server/middleware/serveResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const writeResource = function(writer, path, size, stringContent) {
}
};
const resource = resourceFactory.createResource({path, buffer: Buffer.from(stringContent, "latin1"), statInfo});
// stub resource native functionality to make serveResources (middleware) run to the end
// stub resource functionality in order to be able to get the Resource's content. Otherwise it would be drained.
sinon.stub(resource, "getStream").returns({
pipe: function() {
}
Expand All @@ -28,6 +28,11 @@ const fakeResponse = {
setHeader: function(string, header) {}
};

test.afterEach.always((t) => {
sinon.restore();
});


test.serial("Check if properties file is served properly", (t) => {
t.plan(4);

Expand All @@ -48,7 +53,7 @@ test.serial("Check if properties file is served properly", (t) => {
}
});

const response = Object.assign({}, fakeResponse);
const response = fakeResponse;

const setHeaderSpy = sinon.spy(response, "setHeader");
const req = {
Expand Down Expand Up @@ -90,7 +95,7 @@ test.serial("Check if properties file is served properly with UTF-8", (t) => {
}
});

const response = Object.assign({}, fakeResponse);
const response = fakeResponse;

const setHeaderSpy = sinon.spy(response, "setHeader");
const req = {
Expand Down Expand Up @@ -125,15 +130,15 @@ test.serial("Check if properties file is served properly without property settin
}
});

const response = Object.assign({}, fakeResponse);
const response = fakeResponse;

const setHeaderSpy = sinon.spy(response, "setHeader");
const req = {
url: "/myFile3.properties",
headers: {}
};
const next = function(err) {
throw new Error(`Next callback called with error: ${err.message}`);
throw new Error(`Next callback called with error: ${err.stack}`);
};
return middleware(req, response, next).then((o) => {
return resource.getString();
Expand Down

0 comments on commit e0d424f

Please sign in to comment.