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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
const fs = require('fs');
const test = require('tape');
const pEvent = require('p-event');
const gzipSize = require('.');
const fixture = fs.readFileSync('test.js', 'utf8');
test('get the gzipped size', async t => {
t.true(await gzipSize(fixture) < fixture.length);
t.end();
});
test('gzip compression level', async t => {
t.true(await gzipSize(fixture, {level: 6}) < await gzipSize(fixture, {level: 1}));
t.end();
});
test('sync - get the gzipped size', t => {
t.true(gzipSize.sync(fixture) < fixture.length);
t.end();
});
test('sync - match async version', async t => {
t.is(gzipSize.sync(fixture), await gzipSize(fixture));
t.end();
});
test('sync - gzip compression level', t => {
t.true(gzipSize.sync(fixture, {level: 6}) < gzipSize.sync(fixture, {level: 1}));
t.end();
});
test('stream', async t => {
const stream = fs.createReadStream('test.js').pipe(gzipSize.stream());
await pEvent(stream, 'end');
t.is(stream.gzipSize, gzipSize.sync(fixture));
t.end();
});
test('gzip-size event', async t => {
const stream = fs.createReadStream('test.js').pipe(gzipSize.stream());
const size = await pEvent(stream, 'gzip-size');
t.is(size, gzipSize.sync(fixture));
t.end();
});
test('passthrough', async t => {
let out = '';
const stream = fs.createReadStream('test.js')
.pipe(gzipSize.stream())
.on('data', buffer => {
out += buffer;
});
await pEvent(stream, 'end');
t.is(out, fixture);
t.end();
});
test('file - get the gzipped size', async t => {
t.true(await gzipSize.file('test.js') < fixture.length);
t.end();
});
test('fileSync - get the gzipped size', t => {
t.is(gzipSize.fileSync('test.js'), gzipSize.sync(fixture));
t.end();
});
test('file - match async version', async t => {
t.is(await gzipSize.file('test.js'), await gzipSize(fixture));
t.end();
});
|