github moleculerjs/moleculer v0.14.0-rc1

latest releases: v0.14.33, v0.14.32, v0.14.31...
pre-release4 years ago

Minimum Node version is 10 (BREAKING)

The Node version 8 LTS lifecycle has been ended on December 31, 2019, so the minimum required Node version is 10.

Bluebird dropped (BREAKING)

The Bluebird Promise library has been dropped from the project because as of Node 10 the native Promise implementation is faster (2x) than Bluebird.

Nonetheless, you can use your desired Promise library, just set the Promise broker options.

Using Bluebird

const BluebirdPromise = require("bluebird");

// moleculer.config.js
module.exports = {
    Promise: BluebirdPromise
};

Please note, the given Promise library will be polyfilled with delay, method, timeout and mapSeries methods (which are used inside Moleculer core modules).

Better service event handler testing

Service class has a new emitLocalEventHandler method in order to call a service event handler directly. It can be useful in Unit Tests because you don't need to emit an event with broker.emit.

Example

// posts.service.js
module.exports = {
    name: "posts",

    events: {
        async "user.created"(ctx) {
            this.myMethod(ctx.params);
        }
    }
};
// posts.service.spec.js
describe("Test events", () => {
    const broker = new ServiceBroker({ logger: false });
    const svc = broker.createService(PostService);

    beforeAll(() => broker.start());
    afterAll(() => broker.stop());

    describe("Test 'user.created' event", () => {
        beforeAll(() => svc.myMethod = jest.fn());
        afterAll(() => svc.myMethod.mockRestore());

        it("should call the event handler", async () => {
            await svc.emitLocalEventHandler("branch.closed", { a: 5 });

            expect(svc.myMethod).toBeCalledTimes(1);
            expect(svc.myMethod).toBeCalledWith({ a: 5 });
        });
    });
});

Stream objectMode support

Thanks for @artur-krueger, the request & response streams support objectMode, as well. You can also send Javascript objects via streams.

Example

Other changes

  • In metrics, the defaultBuckets value has been changed to milliseconds.
  • add caller label for EVENT_RECEIVED_TOTAL metric.
  • the heartbeat logic can be disabled by heartbeatInterval: 0 broker option.
  • remove the new currentContext property in Service & ServiceBroker.
  • in Service instances the original schema (before applying mixins) is available via this.originalSchema.

Don't miss a new moleculer release

NewReleases is sending notifications on new releases.