assaf / node-replay

When API testing slows you down: record and replay HTTP responses like a boss
http://documentup.com/assaf/node-replay
MIT License
522 stars 107 forks source link

Allow regex in passThrough #124

Open delijati opened 7 years ago

delijati commented 7 years ago

I would like to record a 'request' call in my app which is a 'localhost' service:

app.js:

'use strict';

const express = require('express');
const request = require('superagent');

var app = express();

app.get('/hammer/version', function(req, res) {
    request
        .get('http://localhost:7777/geturl')
        .end(function(err, response) {
            console.log(response.body);
            res.status(200).json({
                version: '0.1.0',
                url: response.body.url
            });
        });
});

module.exports = app;

test.js:

/* global describe, it */
'use strict';

const request = require('supertest');
const app = require('./app.js');

var path = require('path');
const Replay = require('replay');

Replay.fixtures = __dirname + '/fixtures/replay';
// -> All localhost request are ignored :/ RegEx would work
Replay.passThrough('/hammer/*');

describe('Version test', function() {
    this.timeout(0);

    it('test version', function(done) {
        request(app)
            .get('/hammer/version')
            .expect(200, {
                url: "http://www.foobar.org",
                version: '0.1.0'
            })
            .end(function(err, res) {
                if (err) return done(err);
                done();
            });
    });
});