-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
29 lines (26 loc) · 1.13 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"use strict";
const zlib = require("./index.js");
const randomStrings = new Array(10).fill().map(() => Math.random().toString(36) + Math.random().toString(36));
const methods = [["Deflate", "Inflate"], ["DeflateRaw", "InflateRaw"], ["Gzip", "Gunzip"], ["Gzip", "Unzip"], ["BrotliCompress", "BrotliDecompress"]];
for(const method of methods) {
console.log(`testing ${method.join("/")}`);
const instance = new zlib[method[0]]();
const instance2 = new zlib[method[1]]();
const results = [];
for(const string of randomStrings) {
const compressed = instance.process(string);
results.push(compressed);
}
let returned = [];
for(const data of results) {
const decompressed = instance2.process(data);
returned.push(decompressed.toString());
}
if(returned.join("") !== randomStrings.join("")) { throw new Error(`failed test for ${method.join("/")}`); }
for(const string of randomStrings) {
instance.process(string, zlib.constants.Z_NO_FLUSH);
}
returned = instance2.process(instance.process(""));
if(returned.toString() !== randomStrings.join("")) { throw new Error(`failed test for ${method.join("/")}`); }
}
console.log("all tests passed");