diff --git a/packages/duck-runner/src/index.mjs b/packages/duck-runner/src/index.mjs index 20600c0..bb2ef26 100644 --- a/packages/duck-runner/src/index.mjs +++ b/packages/duck-runner/src/index.mjs @@ -24,12 +24,12 @@ const DuckRunnerComponent = (...args) => { Kit.Bus = new EventEmitter(); + next(); + for (const name in modes) { manager.Mode(name, modes[name]); } - next(); - for (const name in roles) { const RoleKit = Kit(`Role<${name}>`); diff --git a/packages/duck-web/src/index.mjs b/packages/duck-web/src/index.mjs index d0263aa..1f2f1ff 100644 --- a/packages/duck-web/src/index.mjs +++ b/packages/duck-web/src/index.mjs @@ -51,10 +51,6 @@ const DuckWebComponent = (options = [DEFAULT_APPLICATION]) => { map.set(id, { id, description, ApplicationProxy }); }; - for (const Application of staticApplicationList) { - register(Application); - } - const Web = Kit.Web = { register, Application: Utils.throwNotInstalled, @@ -65,6 +61,10 @@ const DuckWebComponent = (options = [DEFAULT_APPLICATION]) => { next(); + for (const Application of staticApplicationList) { + register(Application); + } + Web.Application = function Application(id, ...args) { Assert.Type.String(id, 'id'); diff --git a/packages/duck-web/test/DuckWeb.spec.mjs b/packages/duck-web/test/DuckWeb.spec.mjs index b8b09d9..bce52b6 100644 --- a/packages/duck-web/test/DuckWeb.spec.mjs +++ b/packages/duck-web/test/DuckWeb.spec.mjs @@ -31,6 +31,24 @@ describe('DuckWeb', function () { }}); describe('>Web', function () { + it('should create component and access injection in assembler.', function () { + Duck.define({ + id: 'foo', + components: [ + DuckWeb.Component([{ + id: 'Foo', + provider: ({ mock }) => { + console.log(mock); + return () => {}; + }, + description: '', + }]), + ], + }, function ({ Kit }) { + Kit.mock = {}; + })(); + }); + describe('::register()', function () { it('should rigister a custom Application.', function () { Duck.define({ @@ -154,7 +172,27 @@ describe('DuckWeb', function () { }); }); - it('should throw if not installed.'); + it('should throw if not installed.', function () { + assert.throws(() => { + Duck.define({ + id: 'foo', + components: [ + DuckWeb.Component([ + { + id: 'Foo', + provider: () => () => {}, + description: 'Bar', + }, + ]), + ], + }, (Kit) => { + Kit.Web.Application('Foo'); + })(); + }, { + name: 'Error', + message: 'Installation not completed.', + }); + }); }); }); @@ -207,14 +245,14 @@ describe('DuckWeb', function () { })(); const listener = Kit.Web.App('Redirect'); - const server = http.createServer(listener).listen(8080, '127.0.0.2'); + const server = http.createServer(listener).listen(8081, '127.0.0.2'); - const response = await fetch('http://127.0.0.2:8080/', { + const response = await fetch('http://127.0.0.2:8081/', { redirect: 'manual', }); assert.equal(response.status, 302); - assert.equal(response.headers.get('Location'), 'https://127.0.0.2:8080/'); + assert.equal(response.headers.get('Location'), 'https://127.0.0.2:8081/'); server.close(); });