@platform/cell.schema
Version:
URI and database schemas for the `cell.os`.
91 lines (90 loc) • 3.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var test_1 = require("../../test");
var _1 = require(".");
describe('ManifestHash', function () {
var EMPTY = test_1.Hash.sha256([]);
var testFile = function (options) {
if (options === void 0) { options = {}; }
var _a = options.path, path = _a === void 0 ? 'dir/foo.txt' : _a, _b = options.text, text = _b === void 0 ? 'hello' : _b;
var data = new TextEncoder().encode(text);
var bytes = data.byteLength;
var filehash = test_1.Hash.sha256(data);
return { path: path, bytes: bytes, filehash: filehash };
};
var testFiles = function (length) {
return Array.from({ length: length }).map(function (v, i) {
var path = "dir/file-".concat(i + 1, ".png");
var text = path;
return testFile({ path: path, text: text });
});
};
var expectHash = function (value, expected) {
(0, test_1.expect)(value.endsWith(expected)).to.eql(true, "value: ".concat(value, " | expected: ").concat(expected));
};
it('sha256', function () {
var data = new TextEncoder().encode('hello');
(0, test_1.expect)(_1.ManifestHash.sha256(data)).to.eql(test_1.Hash.sha256(data));
});
describe('files', function () {
it('empty', function () {
var manifest = { files: [], hash: { files: EMPTY } };
(0, test_1.expect)(_1.ManifestHash.files([])).to.eql(EMPTY);
(0, test_1.expect)(_1.ManifestHash.files(manifest)).to.eql(EMPTY);
});
it('single', function () {
var file = testFile();
expectHash(_1.ManifestHash.files([file]), '3f202283e3b9d0e5');
});
it('many (order agnostic)', function () {
var files = testFiles(3);
var res1 = _1.ManifestHash.files(files);
var res2 = _1.ManifestHash.files([files[2], files[1], files[0]]);
var res3 = _1.ManifestHash.files([files[1], files[0], files[2]]);
var HASH = 'c5c2e5f3dffc8eaab';
expectHash(res1, HASH);
expectHash(res2, HASH);
expectHash(res3, HASH);
});
});
describe('ModuleManifest', function () {
var module = {
namespace: 'foo.bar',
version: '1.2.3',
compiler: "@platform/compiler@0.0.0",
compiledAt: 123456789,
mode: 'production',
target: 'web',
entry: 'index.html',
remote: {
entry: 'remoteEntry.js',
exports: [],
},
};
it('empty', function () {
var res = _1.ManifestHash.module(module, []);
expectHash(res.files, EMPTY);
expectHash(res.module, '225a4bf897b1dcf7a91c6fc4');
});
it('files', function () {
var files = testFiles(5);
var res = _1.ManifestHash.module(module, files);
expectHash(res.files, _1.ManifestHash.files(files));
expectHash(res.module, '7fa30f0e145b9b5cade7d9b');
});
});
describe('DirManifest', function () {
var dir = { indexedAt: 123456789 };
it('empty', function () {
var res = _1.ManifestHash.dir(dir, []);
expectHash(res.files, EMPTY);
expectHash(res.dir, '0733adc460c49ae4f7f5ee');
});
it('files', function () {
var files = testFiles(3);
var res = _1.ManifestHash.dir(dir, files);
expectHash(res.files, _1.ManifestHash.files(files));
expectHash(res.dir, '5f711c806e5b214bd2720');
});
});
});