Skip to content

Commit

Permalink
test: don't hang, don't leak resources
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik authored and gr2m committed Aug 25, 2021
1 parent 74e30de commit 37f115c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_reply_with_file.js
Expand Up @@ -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('..')
Expand Down Expand Up @@ -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', {
Expand Down

0 comments on commit 37f115c

Please sign in to comment.