Skip to content

Decorators fail with nested require calls #2760

@kpdecker

Description

@kpdecker

When register is called within another register call, the nested dependency does not seem to decorate the server:

        it('exposes server decorations to next register when nested', function (done) {

            var server = new Hapi.Server();
            server.connection();

            var a = function (srv, options, next) {

                srv.decorate('server', 'a', function () {

                    return 'a';
                });

                return next();
            };

            a.attributes = {
                name: 'a'
            };

            var b = function (srv, options, next) {

                srv.register([a], function(err) {

                    expect(err).to.not.exist();
                    return next(typeof srv.a === 'function' ? null : new Error('Missing decoration'));
                });
            };

            b.attributes = {
                name: 'b'
            };

            server.register([b], function (err) {

                expect(err).to.not.exist();
                server.initialize(function (err) {

                    expect(err).to.not.exist();
                    done();
                });
            });
        });

Fails with:

  271) Plugin register() exposes server decorations to next register when nested:

      Missing decoration

      at ./test/plugin.js:1019:36

Related to #2727

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions