diff --git a/assets/reply_file_1.txt b/tests/assets/reply_file_1.txt similarity index 100% rename from assets/reply_file_1.txt rename to tests/assets/reply_file_1.txt diff --git a/assets/reply_file_2.txt.gz b/tests/assets/reply_file_2.txt.gz similarity index 100% rename from assets/reply_file_2.txt.gz rename to tests/assets/reply_file_2.txt.gz diff --git a/tests/fixtures/goodRequest.json b/tests/fixtures/good_request.json similarity index 100% rename from tests/fixtures/goodRequest.json rename to tests/fixtures/good_request.json diff --git a/tests/fixtures/wrongUri.json b/tests/fixtures/wrong_uri.json similarity index 100% rename from tests/fixtures/wrongUri.json rename to tests/fixtures/wrong_uri.json diff --git a/tests/test_back.js b/tests/test_back.js index f0284af4d..f9acd104e 100644 --- a/tests/test_back.js +++ b/tests/test_back.js @@ -52,7 +52,7 @@ function testNock(t) { function nockBackWithFixture(t, scopesLoaded) { const scopesLength = scopesLoaded ? 1 : 0 - nockBack('goodRequest.json', function(done) { + nockBack('good_request.json', function(done) { t.equal(this.scopes.length, scopesLength) http.get('http://www.example.test/') this.assertScopesFinished() @@ -62,7 +62,7 @@ function nockBackWithFixture(t, scopesLoaded) { } // TODO: This was added as a temporary patch. It's possible that we don't need -// both `goodRequest.json`/`nockBackWithFixture()` on google.com and a second +// both `good_request.json`/`nockBackWithFixture()` on google.com and a second // pair on localhost. Consolidate them if possible. Otherwise remove this // comment. function nockBackWithFixtureLocalhost(t) { @@ -124,7 +124,7 @@ test('nockBack returns a promise when neither options nor nockbackFn are specifi test('nockBack throws an exception when a hook is not a function', t => { nockBack.setMode('dryrun') t.throws( - () => nockBack('goodRequest.json', { before: 'not-a-function-innit' }), + () => nockBack('good_request.json', { before: 'not-a-function-innit' }), { message: 'processing hooks must be a function' } ) t.end() @@ -341,8 +341,7 @@ test('nockBack record tests', nw => { }) nw.test("it shouldn't allow outside calls", t => { - const fixture = 'wrongUri.json' - nockBack(fixture, function(done) { + nockBack('wrong_uri.json', function(done) { http .get('http://other.example.test', res => t.fail('Should not come here!') @@ -359,7 +358,7 @@ test('nockBack record tests', nw => { }) nw.test('it loads your recorded tests', t => { - nockBack('goodRequest.json', function(done) { + nockBack('good_request.json', function(done) { t.true(this.scopes.length > 0) http.get('http://www.example.test/').end() this.assertScopesFinished() @@ -490,7 +489,7 @@ test('nockBack lockdown tests', nw => { test('assertScopesFinished throws exception when Back still has pending scopes', t => { nockBack.setMode('record') - const fixtureName = 'goodRequest.json' + const fixtureName = 'good_request.json' const fixturePath = path.join(nockBack.fixtures, fixtureName) nockBack(fixtureName, function(done) { const expected = `["GET http://www.example.test:80/"] was not used, consider removing ${fixturePath} to rerecord fixture` @@ -505,7 +504,7 @@ test('nockBack dryrun throws the expected exception when fs is not available', t nockBackWithoutFs.setMode('dryrun') nockBackWithoutFs.fixtures = `${__dirname}/fixtures` - t.throws(() => nockBackWithoutFs('goodRequest.json'), { message: 'no fs' }) + t.throws(() => nockBackWithoutFs('good_request.json'), { message: 'no fs' }) t.end() }) @@ -515,6 +514,6 @@ test('nockBack record mode throws the expected exception when fs is not availabl nockBackWithoutFs.setMode('record') nockBackWithoutFs.fixtures = `${__dirname}/fixtures` - t.throws(() => nockBackWithoutFs('goodRequest.json'), { message: 'no fs' }) + t.throws(() => nockBackWithoutFs('good_request.json'), { message: 'no fs' }) t.end() }) diff --git a/tests/test_delay.js b/tests/test_delay.js index b236bd28a..81a85d49f 100644 --- a/tests/test_delay.js +++ b/tests/test_delay.js @@ -12,7 +12,7 @@ const got = require('./got_client') require('./cleanup_after_each')() -const textFile = path.join(__dirname, '..', 'assets', 'reply_file_1.txt') +const textFilePath = path.resolve(__dirname, './assets/reply_file_1.txt') function checkDuration(t, ms) { // Do not write new tests using this function. Write async tests using @@ -164,14 +164,14 @@ test('delayBody works with a stream', async t => { .get('/') .delayBody(100) .reply(200, (uri, requestBody) => - fs.createReadStream(textFile, { encoding: 'utf8' }) + fs.createReadStream(textFilePath, { encoding: 'utf8' }) ) await resolvesInAtLeast( t, async () => { const { body } = await got('http://example.test') - t.equal(body, fs.readFileSync(textFile, { encoding: 'utf8' })) + t.equal(body, fs.readFileSync(textFilePath, { encoding: 'utf8' })) }, 100 ) @@ -185,13 +185,13 @@ test('delayBody works with a stream of binary buffers', async t => { .delayBody(100) // No encoding specified, which causes the file to be streamed using // buffers instead of strings. - .reply(200, (uri, requestBody) => fs.createReadStream(textFile)) + .reply(200, (uri, requestBody) => fs.createReadStream(textFilePath)) await resolvesInAtLeast( t, async () => { const { body } = await got('http://example.test/') - t.equal(body, fs.readFileSync(textFile, { encoding: 'utf8' })) + t.equal(body, fs.readFileSync(textFilePath, { encoding: 'utf8' })) }, 100 ) @@ -212,10 +212,10 @@ test('delayBody works with a delayed stream', async t => { .delayBody(100) .reply(200, (uri, requestBody) => passthrough) - setTimeout(() => fs.createReadStream(textFile).pipe(passthrough), 125) + setTimeout(() => fs.createReadStream(textFilePath).pipe(passthrough), 125) const { body } = await got('http://example.test/') - t.equal(body, fs.readFileSync(textFile, { encoding: 'utf8' })) + t.equal(body, fs.readFileSync(textFilePath, { encoding: 'utf8' })) scope.done() }) @@ -292,7 +292,7 @@ test('delay works with replyWithFile', t => { nock('http://localhost') .get('/') .delay(100) - .replyWithFile(200, `${__dirname}/../assets/reply_file_1.txt`) + .replyWithFile(200, textFilePath) http .request('http://localhost/', function(res) { @@ -325,7 +325,7 @@ test('delay works with when you return a generic stream from the reply callback' .get('/') .delay(100) .reply(200, function(path, reqBody) { - return fs.createReadStream(`${__dirname}/../assets/reply_file_1.txt`) + return fs.createReadStream(textFilePath) }) http @@ -411,7 +411,7 @@ test('delayConnection works with replyWithFile', t => { nock('http://localhost') .get('/') .delayConnection(100) - .replyWithFile(200, `${__dirname}/../assets/reply_file_1.txt`) + .replyWithFile(200, textFilePath) http .request('http://localhost/', function(res) { @@ -444,7 +444,7 @@ test('delayConnection works with when you return a generic stream from the reply .get('/') .delayConnection(100) .reply(200, function(path, reqBody) { - return fs.createReadStream(`${__dirname}/../assets/reply_file_1.txt`) + return fs.createReadStream(textFilePath) }) http diff --git a/tests/test_persist_optionally.js b/tests/test_persist_optionally.js index a50cec4e3..23d0a934d 100644 --- a/tests/test_persist_optionally.js +++ b/tests/test_persist_optionally.js @@ -12,7 +12,7 @@ const got = require('./got_client') require('./setup') -const textFile = path.join(__dirname, '..', 'assets', 'reply_file_1.txt') +const textFilePath = path.resolve(__dirname, './assets/reply_file_1.txt') describe('`optionally()`', () => { it('optional mocks do not appear in `pendingMocks()`', () => { @@ -191,7 +191,7 @@ describe('`persist()`', () => { nock('http://example.test') .persist() .get('/') - .replyWithFile(200, textFile) + .replyWithFile(200, textFilePath) .get('/test') .reply(200, 'Yay!') diff --git a/tests/test_reply_with_file.js b/tests/test_reply_with_file.js index 5906535bb..c10309960 100644 --- a/tests/test_reply_with_file.js +++ b/tests/test_reply_with_file.js @@ -10,14 +10,14 @@ const got = require('./got_client') require('./setup') -const textFile = path.join(__dirname, '..', 'assets', 'reply_file_1.txt') -const binaryFile = path.join(__dirname, '..', 'assets', 'reply_file_2.txt.gz') +const textFilePath = path.resolve(__dirname, './assets/reply_file_1.txt') +const binaryFilePath = path.resolve(__dirname, './assets/reply_file_2.txt.gz') describe('`replyWithFile()`', () => { it('reply with file', async () => { const scope = nock('http://example.test') .get('/') - .replyWithFile(200, textFile) + .replyWithFile(200, textFilePath) const { statusCode, body } = await got('http://example.test/') @@ -30,7 +30,7 @@ describe('`replyWithFile()`', () => { it('reply with file with headers', async () => { const scope = nock('http://example.test') .get('/') - .replyWithFile(200, binaryFile, { + .replyWithFile(200, binaryFilePath, { 'content-encoding': 'gzip', }) @@ -50,7 +50,9 @@ describe('`replyWithFile()`', () => { it('throws the expected error', () => { expect(() => - new Scope('http://example.test').get('/').replyWithFile(200, textFile) + new Scope('http://example.test') + .get('/') + .replyWithFile(200, textFilePath) ).to.throw(Error, 'No fs') }) }) diff --git a/tests/test_scope.js b/tests/test_scope.js index 46ffb94e1..36cb283d6 100644 --- a/tests/test_scope.js +++ b/tests/test_scope.js @@ -12,7 +12,9 @@ const got = require('./got_client') require('./setup') it('scope exposes interceptors', () => { - const scopes = nock.load(path.join(__dirname, 'fixtures', 'goodRequest.json')) + const scopes = nock.load( + path.join(__dirname, 'fixtures', 'good_request.json') + ) expect(scopes).to.be.an.instanceOf(Array) expect(scopes).to.have.lengthOf.at.least(1) diff --git a/tests/test_stream.js b/tests/test_stream.js index a6c3eca7b..02b654644 100644 --- a/tests/test_stream.js +++ b/tests/test_stream.js @@ -12,12 +12,12 @@ const got = require('./got_client') require('./setup') -const textFile = path.join(__dirname, '..', 'assets', 'reply_file_1.txt') +const textFilePath = path.resolve(__dirname, './assets/reply_file_1.txt') it('reply with file and pipe response', done => { const scope = nock('http://example.test') .get('/') - .replyWithFile(200, textFile) + .replyWithFile(200, textFilePath) let text = '' const fakeStream = new stream.Stream()