Happner Test Modules

1.0.2 · maintenance · verified Sun Apr 19

happner-test-modules is a supplementary library designed to provide utilities and mock components specifically for testing applications built with the `happner` microservices framework. `happner` is a cloud application framework that enables the creation of an interconnected mesh of local and remote components, utilizing `happn-3` for its pub/sub and data layer. This package (currently at version `1.0.2`) offers helper functions to simplify the setup and teardown of `happner` meshes, the loading of test components, and the simulation of component interactions and event flows. These functionalities are crucial for ensuring the reliability of `happner`-based systems. Given that `happner`'s last significant updates (v1.34.1 and `happner-2`) were several years ago, `happner-test-modules` is likely in maintenance mode, receiving updates primarily for compatibility or critical bug fixes rather than active feature development. Its key differentiator is its tailored integration with the `happner` ecosystem, providing specific test paradigms for mesh components and event APIs.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create and interact with a basic `happner` mesh using `happner-test-modules` (implicitly through `happner.create`), define a simple component, call a method on it, and emit/receive an event.

import { createTestMesh } from 'happner-test-modules';
import Happner from 'happner'; // Assuming Happner is a default export for simplicity, or named import can be used

async function runHappnerTest() {
  const config = {
    name: 'testMesh',
    modules: {
      TestComponent: {
        instance: {
          testMethod: async (message) => {
            console.log(`TestComponent received: ${message}`);
            return `Processed: ${message}`;
          }
        }
      }
    },
    components: {
      TestComponent: {}
    }
  };

  let mesh;
  try {
    // Use happner-test-modules to create a test mesh
    mesh = await Happner.create(config);
    console.log('Happner test mesh started.');

    const result = await mesh.exchange.TestComponent.testMethod('Hello from test!');
    console.log(`Result from TestComponent: ${result}`);

    // Example of another test action
    const events = [];
    mesh.event.TestComponent.on('test-event', (data) => {
      events.push(data);
      console.log('Event received:', data);
    });
    await mesh.emit('TestComponent/test-event', { value: 'eventData' });

    // Wait a moment for events to propagate (in real tests, use promises/await for specific events)
    await new Promise(resolve => setTimeout(resolve, 100));
    console.log('Events collected:', events);

  } catch (e) {
    console.error('Error during test:', e);
    process.exit(1);
  } finally {
    if (mesh) {
      await mesh.stop();
      console.log('Happner test mesh stopped.');
    }
  }
}

runHappnerTest();

view raw JSON →