npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

moleculer-pact

v1.0.3

Published

This library will make it easy to do contract testing for [Moleculer](https://moleculer.services) services with [Pact](https://docs.pact.io)

Readme

Moleculer-pact

This library will make it easy to do contract testing for Moleculer services with Pact

Why I created this library?

I needed to do contract testing for a micro-services projet written in moleculer. and pact is a great library for contract testing. but I have found it quite difficult to integrate into moleculer concept. So this library will fix that for the time being, until a better solution comes along.

How ?

This library uses a hacky way of using the HTTP protocol to do the contract testing for moleculer services.

Support ?

I will continue to add features like streams, but will stop supporting once I found a better solution.


Installation

npm i moleculer-pact

Example

client.test.js (consumer)

const path = require('path');
const { MoleculerProvider, MockBroker } = require('moleculer-pact');

const pact = require('@pact-foundation/pact-node');
const { MatchersV3 } = require('@pact-foundation/pact');

describe('Test Describe', () => {
    const mock_port = 1234;
    const pactFilesDir = path.resolve(process.cwd(), 'tests', 'pacts');

    const provider = new MoleculerProvider({
        consumer: 'bundler-service',
        provider: 'printable-service',
        port: mock_port,
        pactFilesDir: pactFilesDir
    });

    const publisherOpts = {
        pactFilesOrDirs: [pactFilesDir],
        pactBroker: 'http://127.0.0.1:9292',
        pactBrokerUsername: 'testuser',
        pactBrokerPassword: 'testpass',
        consumerVersion: '1.0.0'
    };

    afterAll(async () => {
        await pact.publishPacts(publisherOpts);
        console.log('Published pacts');
    });
    it('test: isPrintJobReady', () => {
        provider
            .uponReceiving('a call to check if print job is done')
            .withCall({
                action: 'isPrintJobReady',
                params: {
                    printJobId: '123456789-10'
                },
                opts: {}
            })
            .willRespondWith({
                ctx: {},
                willReturn: MatchersV3.boolean()
            });
        return provider.executeTest(async (mockServer) => {
            const broker = new MockBroker(mockServer);
            const ret = await broker.call(
                'isPrintJobReady',
                {
                    printJobId: '123456789-10'
                },
                {}
            );
            expect(typeof ret).toEqual('boolean');
        });
    });
});

server.test.js (provider)

const assert = require('assert');
const { ServiceBroker, Context } = require('moleculer');
const { MoleculerVerifier } = require('moleculer-pact');

const Service = {
    name: 'printable-service',
    actions: {
        isPrintJobReady: {
            // Add param validation
            params: {
                printJobId: 'string'
            },
            handler(ctx) {
                return Math.random() * 10 > 5;
            }
        }
    }
};

let broker = new ServiceBroker({ logger: false });
let serviceS = broker.createService(Service);

const consumer_name = 'bundler-service';

beforeAll(() => broker.start());
afterAll(async () => {
    await broker.stop();
});

describe('Pact Verification', () => {
    const options = {
        provider: 'printable-service',
        pactBrokerUrl: 'http://127.0.0.1:9292',
        pactBrokerUsername: 'testuser',
        pactBrokerPassword: 'testpass',
        consumerVersionSelectors: [
            {
                consumer: consumer_name,
                latest: true,
                currentlyDeployed: false
            }
        ],
        publishVerificationResult: true,
        providerVersion: '1.0.0'
    };

    const verifier = new MoleculerVerifier(
        'printable-service',
        broker,
        options
    );

    beforeAll(async () => {
        await verifier.initialize();
    });
    afterAll(async () => {
        await verifier.destroy();
    });

    it('verifies the provider', async () => {
        try {
            const verifyRes = await verifier.verifyProvider();
            console.log('Pact Verification Complete!');
            console.log('Result:', verifyRes);
        } catch (e) {
            console.log(e);
            assert.fail();
        }
    });
});

Asynchronous Pacts

You dont need this library to test asynchronous message pacts. since it can be done using just Pact-js