Skip to content

Instantly share code, notes, and snippets.

@zedd45
Last active September 10, 2015 20:08
Show Gist options
  • Save zedd45/25f340c7c80355ab983e to your computer and use it in GitHub Desktop.
Save zedd45/25f340c7c80355ab983e to your computer and use it in GitHub Desktop.
Nock Record - Thanks @dbretoi
/**
* For use with Nocking Hapi Requests (with Lab)
* Nock: https://github.com/pgte/nock/
* Hapi: http://hapijs.com/api
* Lab: https://github.com/hapijs/lab
*/
// npm deps
var Nock = require('nock');
var Fs = require('fs');
var Hoek = require('hoek');
// the following lines go inside the `it` or `test`
var fileName = Hoek.reach(this, 'process.domain.title', { default: 'nock-mock' }) + '.js'; // lab
fileName = fileName.replace(/\s+/g, '_');
var appendLogToFile = function(content) {
console.log('writing to ' + fileName);
Fs.appendFile(fileName, content);
};
Nock.recorder.rec({
logging: appendLogToFile,
use_separator: false
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment