LinkedInAttic / sepia

Sepia is a VCR-like module for node.js that records HTTP interactions, then plays them back exactly like the first time they were invoked
Apache License 2.0
279 stars 32 forks source link

Possibility to disable sepia for certain tests #14

Open satazor opened 8 years ago

satazor commented 8 years ago

I'm developing a complex set of test suites and I want to disable sepia for some of them. Besides the filter feature, is there any way to accomplish this, e.g.: sepia.disable()/enable()?

Thanks

satazor commented 8 years ago

After analyzing sepia, it seems there's no such feature. Would you guys be interested in adding it?

satazor commented 8 years ago

I've made a workaround:

// tests/util/sepia.js

'use strict';

const http = require('http');
const https = require('https');

const originalRequests = { http: http.request, https: https.request };
const sepia = require('sepia');
const sepiaRequests = { http: http.request, https: https.request };

/**
 * Turns sepia on.
 */
function enable() {
    http.request = sepiaRequests.http;
    https.request = sepiaRequests.https;
}

/**
 * Turns sepia off.
 */
function disable() {
    http.request = originalRequests.http;
    https.request = originalRequests.https;
}

disable();

sepia.enable = enable;
sepia.disable = disable;

module.exports = sepia;
paulwalker commented 8 years ago

Thanks, I needed this as it seems to break supertest requests to my app. I'm not sure if anyone else experienced that and has a better workaround?

aneilbaboo commented 7 years ago

I had the same issue. This would be a great addition.