@platform/cell.schema
Version:
URI and database schemas for the `cell.os`.
226 lines (225 loc) • 11.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var test_1 = require("../../test");
var _1 = require(".");
describe.only('ManifestUrl', function () {
var MANIFEST = {
kind: 'module',
hash: {
files: 'sha256-73794e8fb93173aaa883aa595b322c3976596e2cb58fff4210c74643ca0ad56c',
module: 'sha256-94aacbf4ae6c5ab206b3d4cb5674fdecebf1f814b54f1fbfec646760edd23549',
},
module: {
namespace: 'mock.foobar',
version: '0.0.0',
compiler: '@platform/cell.compiler@0.0.0',
compiledAt: 1636667570203,
mode: 'production',
target: 'web',
entry: 'index.html',
remote: {
entry: 'remoteEntry.js',
exports: [{ path: './Dev' }],
},
},
files: [],
};
describe('parse', function () {
it('cell (uri)', function () {
var href = 'http://localhost:1234/cell:foo:A1/fs/dir/child/index.json?foo=123';
var url = _1.ManifestUrl.parse(" ".concat(href, " "));
(0, test_1.expect)(url.ok).to.eql(true);
(0, test_1.expect)(url.error).to.eql(undefined);
(0, test_1.expect)(url.params.entry).to.eql('');
(0, test_1.expect)(url.href).to.eql(href);
(0, test_1.expect)(url.domain).to.eql('localhost:1234');
(0, test_1.expect)(url.path).to.eql('dir/child/index.json');
(0, test_1.expect)(url.dir).to.eql('dir/child');
(0, test_1.expect)(url.filename).to.eql('index.json');
(0, test_1.expect)(url.cell).to.eql('cell:foo:A1');
});
it('non-cell (url)', function () {
var href = 'https://domain.com/foo/index.json?foo=123';
var url = _1.ManifestUrl.parse(" ".concat(href, " "));
(0, test_1.expect)(url.ok).to.eql(true);
(0, test_1.expect)(url.error).to.eql(undefined);
(0, test_1.expect)(url.params.entry).to.eql('');
(0, test_1.expect)(url.href).to.eql(href);
(0, test_1.expect)(url.domain).to.eql('domain.com');
(0, test_1.expect)(url.path).to.eql('foo/index.json');
(0, test_1.expect)(url.dir).to.eql('foo');
(0, test_1.expect)(url.filename).to.eql('index.json');
(0, test_1.expect)(url.cell).to.eql('');
(0, test_1.expect)(Boolean(url.cell)).to.eql(false);
});
it('domain:<port>', function () {
var test = function (href, dir, filename) {
var url = _1.ManifestUrl.parse(href);
(0, test_1.expect)(url.dir).to.eql(dir);
(0, test_1.expect)(url.filename).to.eql(filename);
(0, test_1.expect)(url.path).to.eql("".concat(dir ? "".concat(dir, "/") : dir).concat(filename));
};
test('http://localhost:1234/foo/index.json?foo=123', 'foo', 'index.json');
test('localhost:1234/foo/index.json?foo=123', 'foo', 'index.json');
test('localhost:1234/index.json?foo=123', '', 'index.json');
test('domain.com:8080/index.json?foo=123', '', 'index.json');
});
it('protocol', function () {
var test = function (href, expected) {
var url = _1.ManifestUrl.parse(href);
(0, test_1.expect)(url.protocol).to.eql(expected);
};
test('http://localhost:1234/foo/index.json', 'http');
test('localhost:1234/foo/index.json', 'http');
test('domain.com/foo/index.json', 'https');
test('https://domain.com/foo/index.json', 'https');
test('http://domain.com/foo/index.json', 'https');
});
describe('entry', function () {
it('empty string ("") - nothing', function () {
var test = function (path) {
var href = " https://domain.com/".concat(path, " ");
var url = _1.ManifestUrl.parse(href);
(0, test_1.expect)(url.ok).to.eql(true);
(0, test_1.expect)(url.params.entry).to.eql('');
};
test('index.json');
test('foo/index.json');
test('foo/index.json?');
test('foo/index.json?foo=123');
test('foo/index.json?entry');
test('foo/index.json?entry=');
});
it('entry path', function () {
var test = function (path, expected) {
var href = " https://domain.com/".concat(path, " ");
var url = _1.ManifestUrl.parse(href);
(0, test_1.expect)(url.ok).to.eql(true);
(0, test_1.expect)(url.params.entry).to.eql(expected);
};
test('index.json?entry=foo', 'foo');
test('index.json?entry=./DEV.ui.video', './DEV.ui.video');
});
});
describe('valid', function () {
it('cell (uri)', function () {
var test = function (input, dir, filename) {
var url = _1.ManifestUrl.parse(" ".concat(input, " "));
(0, test_1.expect)(url.ok).to.eql(true);
(0, test_1.expect)(url.error).to.eql(undefined);
(0, test_1.expect)(url.dir).to.eql(dir);
(0, test_1.expect)(url.filename).to.eql(filename);
(0, test_1.expect)(Boolean(url.cell)).to.eql(true);
};
test('http://localhost/cell:foo:A1/fs/index.json', '', 'index.json');
test('http://localhost/cell:foo:A1/fs/manifest.json', '', 'manifest.json');
test('http://localhost/cell:foo:A1/fs/foo.json', '', 'foo.json');
test('http://localhost/cell:foo:A1/fs/foo/index.json', 'foo', 'index.json');
test('http://localhost/cell:foo:A1/fs/foo/bar/boom.json', 'foo/bar', 'boom.json');
});
it('non-cell (url)', function () {
var test = function (input, dir, filename) {
var url = _1.ManifestUrl.parse(" ".concat(input, " "));
(0, test_1.expect)(url.ok).to.eql(true);
(0, test_1.expect)(url.error).to.eql(undefined);
(0, test_1.expect)(url.dir).to.eql(dir);
(0, test_1.expect)(url.filename).to.eql(filename);
(0, test_1.expect)(Boolean(url.cell)).to.eql(false);
};
test('http://localhost/index.json', '', 'index.json');
test('http://localhost/manifest.json', '', 'manifest.json');
test('http://localhost/foo.json', '', 'foo.json');
test('https://domain.com/index.json', '', 'index.json');
test('http://localhost/foo/index.json', 'foo', 'index.json');
test('http://localhost/foo/bar/boom.json', 'foo/bar', 'boom.json');
test('https://domain.com/foo/bar/index.json', 'foo/bar', 'index.json');
});
});
describe('invalid (error)', function () {
var test = function (input) {
var url = _1.ManifestUrl.parse(input);
(0, test_1.expect)(url.ok).to.eql(false, input);
(0, test_1.expect)(url.error).to.include('Invalid manifest URL', input);
};
it('input type', function () {
[undefined, null, true, 123, {}, []].forEach(function (value) { return test(value); });
});
it('empty ("")', function () {
test('');
test(' ');
});
it('invalid url format', function () {
test('http://localhost/');
test('localhost/');
test('localhost:1234');
test('domain.com');
test('http://localhost/ns:foo');
test('http://localhost/cell:foo:A1');
test('http://localhost/cell:foo:A1/');
test('http://localhost/cell:foo:A1/foo');
test('http://localhost/cell:foo:A1/fs');
test('http://localhost/cell:foo:A1/fs/ ');
test('http://localhost/cell:foo:A1/fs/foo');
test('http://localhost/cell:foo:A1/fs/foo/bar');
});
});
});
describe('params', function () {
it('modify: entry', function () {
var url1 = _1.ManifestUrl.parse('https://domain.com:8080/foo/index.json');
var url2 = _1.ManifestUrl.params(url1, { entry: ' ./foo/bar ' });
(0, test_1.expect)(url1).to.not.eql(url2);
(0, test_1.expect)(url2.href).to.eql('https://domain.com:8080/foo/index.json?entry=./foo/bar');
(0, test_1.expect)(url1.params.entry).to.eql('');
(0, test_1.expect)(url2.params.entry).to.eql('./foo/bar');
});
});
describe('toRemoteEntryUrl', function () {
it('derives "remoteyEntry.js" endpoint', function () {
var test = function (href, expected) {
var res1 = _1.ManifestUrl.toRemoteEntryUrl(href, MANIFEST);
var res2 = _1.ManifestUrl.toRemoteEntryUrl(_1.ManifestUrl.parse(href), MANIFEST);
(0, test_1.expect)(res1).to.eql(expected);
(0, test_1.expect)(res2).to.eql(expected);
};
test('https://domain.com/foo/index.json', 'https://domain.com/foo/remoteEntry.js');
test('domain.com/foo/index.json', 'https://domain.com/foo/remoteEntry.js');
test('localhost:1234/foo/index.json', 'http://localhost:1234/foo/remoteEntry.js');
test('localhost/index.json', 'http://localhost/remoteEntry.js');
});
it('no {remote} section within manifest', function () {
var test = function (href) {
var manifest = test_1.R.clone(MANIFEST);
delete manifest.module.remote;
(0, test_1.expect)(_1.ManifestUrl.toRemoteEntryUrl(href, manifest)).to.eql('');
};
test('domain.com/foo/index.json');
test('domain.com/index.json');
});
it('no manifest (undefined)', function () {
var href = 'domain.com/foo/index.json';
(0, test_1.expect)(_1.ManifestUrl.toRemoteEntryUrl(href, undefined)).to.eql('');
});
it('error', function () {
var url = _1.ManifestUrl.parse('domain.com/fail/');
(0, test_1.expect)(url.error).to.include('Invalid manifest URL');
var fn = function () { return _1.ManifestUrl.toRemoteEntryUrl(url, MANIFEST); };
(0, test_1.expect)(fn).to.throw(/Failed to derive remote-entry URL/);
});
});
describe('toRemoteImport', function () {
it('success', function () {
var entry = './Foo';
var res = _1.ManifestUrl.toRemoteImport('localhost/foo/index.json', MANIFEST, entry);
(0, test_1.expect)(res.url).to.eql('http://localhost/foo/remoteEntry.js');
(0, test_1.expect)(res.namespace).to.eql(MANIFEST.module.namespace);
(0, test_1.expect)(res.entry).to.eql(entry);
});
it('error: invalid URL', function () {
var entry = './Foo';
var url = _1.ManifestUrl.parse('domain.com/fail/');
var fn = function () { return _1.ManifestUrl.toRemoteImport(url, MANIFEST, entry); };
(0, test_1.expect)(fn).to.throw(/Failed to derive remote-entry URL/);
});
});
});