UNPKG

wechaty-puppet-service

Version:
35 lines 2.35 kB
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tstest_1 = require("tstest"); const file_box_1 = require("file-box"); const normalize_filebox_js_1 = require("./normalize-filebox.js"); const kbFileBox = (size) => file_box_1.FileBox.fromBuffer(Buffer.from(new Int8Array(size * 1024).fill(0)), size + 'KB.txt'); (0, tstest_1.test)('canPassthrough() size threshold', async (t) => { t.ok((0, normalize_filebox_js_1.canPassthrough)(kbFileBox(16)), 'should passthrough 16KB'); t.notOk((0, normalize_filebox_js_1.canPassthrough)(kbFileBox(32)), 'should not passthrough 32KB'); }); (0, tstest_1.test)('canPassthrough(): always true for green types', async (t) => { const URL = 'https://example.com'; const QRCODE = 'qrcode'; const UUID = '12345678-1234-5678-1234-567812345678'; t.ok((0, normalize_filebox_js_1.canPassthrough)(file_box_1.FileBox.fromUrl(URL)), 'should passthrough Url'); t.ok((0, normalize_filebox_js_1.canPassthrough)(file_box_1.FileBox.fromQRCode(QRCODE)), 'should passthrough QRCode'); t.ok((0, normalize_filebox_js_1.canPassthrough)(file_box_1.FileBox.fromUuid(UUID)), 'should passthrough UUID'); }); (0, tstest_1.test)('canPassthrough(): always false for red types', async (t) => { const streamFileBox = file_box_1.FileBox.fromStream(await file_box_1.FileBox.fromQRCode('qr').toStream()); const localFileBox = file_box_1.FileBox.fromFile('tests/fixtures/smoke-testing.ts'); t.notOk((0, normalize_filebox_js_1.canPassthrough)(streamFileBox), 'should not passthrough Stream'); t.notOk((0, normalize_filebox_js_1.canPassthrough)(localFileBox), 'should not passthrough File'); }); (0, tstest_1.test)('canPassthrough(): will depend on the size for yellow types', async (t) => { const bufferFileBox = file_box_1.FileBox.fromBuffer(Buffer.from('buf')); const base64FileBox = file_box_1.FileBox.fromBase64(Buffer.from('buf').toString('base64')); t.ok((0, normalize_filebox_js_1.canPassthrough)(bufferFileBox), 'should not passthrough small Buffer'); t.ok((0, normalize_filebox_js_1.canPassthrough)(base64FileBox), 'should not passthrough small Base64'); /** * TODO: add the large size test which will over the threshold */ }); //# sourceMappingURL=normalize-filebox.spec.js.map