disable-fetch.js 726 B

12345678910111213141516171819202122232425262728293031323334353637
  1. var Buffer = require('buffer').Buffer
  2. var test = require('tape')
  3. var http = require('../..')
  4. test('disable fetch', function (t) {
  5. var originalFetch
  6. if (typeof fetch === 'function') {
  7. originalFetch = fetch
  8. }
  9. var fetchCalled = false
  10. fetch = function (input, options) {
  11. fetchCalled = true
  12. if (originalFetch) {
  13. return originalFetch(input, options)
  14. }
  15. }
  16. http.get({
  17. path: '/browserify.png',
  18. mode: 'disable-fetch'
  19. }, function (res) {
  20. t.ok(!fetchCalled, 'fetch was not called')
  21. if (originalFetch) {
  22. fetch = originalFetch
  23. }
  24. res.on('end', function () {
  25. t.ok(res.headers['content-type'] === 'image/png', 'content-type was set correctly')
  26. t.end()
  27. })
  28. res.on('data', function () {})
  29. })
  30. })