Skip to content

Commit

Permalink
@produck/duck-runner:
Browse files Browse the repository at this point in the history
[FIXED] first define then register
@produck/duck-web:
[FIXED] first define then register
  • Loading branch information
lichaozhy committed Nov 25, 2024
1 parent 8769d38 commit b3fe304
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/duck-runner/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}>`);

Expand Down
8 changes: 4 additions & 4 deletions packages/duck-web/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');

Expand Down
46 changes: 42 additions & 4 deletions packages/duck-web/test/DuckWeb.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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.',
});
});
});
});

Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit b3fe304

Please sign in to comment.