Passthrough or Intercept 'blob:' urls in PollyJS

Some background (this was all new to me until this morning):

You can create a blob in javascript:

let b = new Blob(['a bunch of text'], {type: 'text/plain'})

You can create a blob url for that blob in javascript:

let url = URL.createObjectURL()

You can then fetch or xhr request that blob url (or put it as an href):

fetch(url)
  .then(r => r.text())
  .then(console.log) // prints out "a bunch of text"

PollyJS is a library that allows you to run tests (or development) with a client side server or a request replay mechanism with saved real requests, it's pretty slick, and maintained by Netflix. If you configure Polly it with it's fetch and xhr adapters it will expect intercepts or replays to be available for EVERY call that gets made through them. No Bueno. From the docs, it wasn't intuitive that you can filter on ANY part of the url in your route handlers. Here's how you would do that for blob:

let server = ... // configure you a PollyJS.

// Polly should ignore blobs urls.
server.get('blob:*').passthrough()

Comments