zlib.test.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const test = require('tap').test;
  2. const zlibA = require('zlib');
  3. const zlibB = require('..');
  4. const crypto = require('crypto');
  5. test('zlibA.deflate -> zlibB.inflate', function (t) {
  6. const expect = crypto.randomBytes(1024);
  7. zlibA.deflate(expect, function (err, cmpA) {
  8. zlibB.inflate(cmpA, function (err, result) {
  9. t.same(result, expect, 'should match');
  10. t.end();
  11. });
  12. });
  13. });
  14. test('zlibB.deflate -> zlibA.inflate', function (t) {
  15. const expect = crypto.randomBytes(1024);
  16. zlibB.deflate(expect, function (err, cmpA) {
  17. zlibA.inflate(cmpA, function (err, result) {
  18. t.same(result, expect, 'should match');
  19. t.end();
  20. });
  21. });
  22. });
  23. test('zlibB.deflate -> zlibA.inflate (string)', function (t) {
  24. const expect = 'ohaihihihihihihihihihihihihihihihi';
  25. zlibB.deflate(expect, function (err, cmpA) {
  26. zlibA.inflate(cmpA, function (err, result) {
  27. t.same(result.toString(), expect, 'should match');
  28. t.end();
  29. });
  30. });
  31. });
  32. test('zlibA.gzip -> zlibB.gunzip', function (t) {
  33. const expect = crypto.randomBytes(1024);
  34. zlibA.gzip(expect, function (err, cmpA) {
  35. zlibB.gunzip(cmpA, function (err, result) {
  36. t.same(result, expect, 'should match');
  37. t.end();
  38. });
  39. });
  40. });
  41. test('zlibB.gzip -> zlibA.gunzip', function (t) {
  42. const expect = crypto.randomBytes(1024);
  43. zlibB.gzip(expect, function (err, cmpA) {
  44. zlibA.gunzip(cmpA, function (err, result) {
  45. t.same(result, expect, 'should match');
  46. t.end();
  47. });
  48. });
  49. });
  50. test('zlibB.gzip -> zlibA.gunzip', function (t) {
  51. const expect = 'lololololoollolololoololololololololololololololololololololol';
  52. zlibB.gzip(expect, function (err, cmpA) {
  53. zlibA.gunzip(cmpA, function (err, result) {
  54. t.same(result.toString(), expect, 'should match');
  55. t.end();
  56. });
  57. });
  58. });