poetic / nock-vcr-recorder

A test framework agnostic vcr implementation that uses nock.
9 stars 11 forks source link

Playback with requests that have a timestamp. #3

Open DanielOchoa opened 9 years ago

DanielOchoa commented 9 years ago

See nock recording. Nock allows pre-processing of the json body of recordings in order to replace strings such as timestamps. This feature is a necessity.

awashbrook commented 9 years ago

Agreed, another common use case is replacing a session id.

Cannot do this with vcr, can do with nock back before/after options, where we can filter request bodies on the scope.

var before = function (scope) {
    scope.filteringRequestBody = function(body) {
      if(typeof(body) !== 'string') {
        return body;
      }

      return body.replace(/(timestamp):([0-9]+)/g, function(match, key, value) {
        return key + ':timestampCapturedDuringRecording'
      });

    }
  }

  nockBack('someFixture.json', {before: before}, function (nockDone) {
…

As nock back also automates fixture file record and playback, this is my favoured solution for now.

DanielOchoa commented 9 years ago

I will look into adding this feature sometime over the weekend.