You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

data.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * Module dependencies.
  3. */
  4. var getUri = require('../');
  5. var assert = require('assert');
  6. var streamToArray = require('stream-to-array');
  7. describe('get-uri', function () {
  8. describe('"data:" protocol', function () {
  9. var cache;
  10. it('should work for URL-encoded data', function (done) {
  11. getUri('data:,Hello%2C%20World!', function (err, rs) {
  12. if (err) return done(err);
  13. cache = rs;
  14. streamToArray(rs, function (err, array) {
  15. if (err) return done(err);
  16. var buf = Buffer.concat(array);
  17. assert.equal('Hello, World!', buf.toString());
  18. done();
  19. });
  20. });
  21. });
  22. it('should work for base64-encoded data', function (done) {
  23. getUri('data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D', function (err, rs) {
  24. if (err) return done(err);
  25. streamToArray(rs, function (err, array) {
  26. if (err) return done(err);
  27. var buf = Buffer.concat(array);
  28. assert.equal('Hello, World!', buf.toString());
  29. done();
  30. });
  31. });
  32. });
  33. it('should return ENOTMODIFIED for the same URI with `cache`', function (done) {
  34. getUri('data:,Hello%2C%20World!', { cache: cache }, function (err, rs) {
  35. assert(err);
  36. assert.equal('ENOTMODIFIED', err.code);
  37. done();
  38. });
  39. });
  40. });
  41. });