From 62dd62fd1f94ca2df95bd1d95e394645324b4772 Mon Sep 17 00:00:00 2001 From: Tobias Sorn Date: Mon, 29 Jul 2019 13:20:40 +0200 Subject: [PATCH] Add comment to serveResource test 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. --- test/lib/server/middleware/serveResources.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/lib/server/middleware/serveResources.js b/test/lib/server/middleware/serveResources.js index 7133869f..542aacc8 100644 --- a/test/lib/server/middleware/serveResources.js +++ b/test/lib/server/middleware/serveResources.js @@ -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() { } @@ -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); @@ -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 = { @@ -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 = { @@ -125,7 +130,7 @@ 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 = { @@ -133,7 +138,7 @@ test.serial("Check if properties file is served properly without property settin 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();