From 37f115c47d9d347c1dd3be39c5ec1c28243526a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kol=C3=A1rik?= Date: Tue, 24 Aug 2021 21:57:06 -0700 Subject: [PATCH] test: don't hang, don't leak resources --- tests/test_reply_with_file.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_reply_with_file.js b/tests/test_reply_with_file.js index 4adbb8cde..639abd688 100644 --- a/tests/test_reply_with_file.js +++ b/tests/test_reply_with_file.js @@ -2,7 +2,9 @@ // Tests for `.replyWithFile()`. +const fs = require('fs') const path = require('path') +const sinon = require('sinon') const { expect } = require('chai') const proxyquire = require('proxyquire').preserveCache() const nock = require('..') @@ -39,6 +41,29 @@ describe('`replyWithFile()`', () => { scope.done() }) + it('reply with file with repeated', async () => { + sinon.spy(fs) + + const scope = nock('http://example.test') + .get('/') + .times(2) + .replyWithFile(200, binaryFilePath, { + 'content-encoding': 'gzip', + }) + + const response1 = await got('http://example.test/') + expect(response1.statusCode).to.equal(200) + expect(response1.body).to.have.lengthOf(20) + + const response2 = await got('http://example.test/') + expect(response2.statusCode).to.equal(200) + expect(response2.body).to.have.lengthOf(20) + + expect(fs.createReadStream.callCount).to.equal(2) + + scope.done() + }) + describe('with no fs', () => { const { Scope } = proxyquire('../lib/scope', { './interceptor': proxyquire('../lib/interceptor', {