Core Changes: - Completely rewrote CustomResolver reducer with dependency-ordered processing - Enhanced plugin initialization with proper dependency injection - Improved delta processing and property value tracking - Added robust error handling for duplicate property IDs Resolver Improvements: - Updated to use new accumulator structure - Implemented execution order processing for plugins - Enhanced debug logging and error reporting - Simplified TimestampResolver by removing unused initializer Configuration Updates: - Added TypeScript path aliases for test helpers - Improved module resolution paths Key Benefits: - More robust plugin dependency management - More efficient state updates - Enhanced type safety - Better error messages and debugging - More consistent plugin initialization This refactoring focuses on improving the robustness of the resolver, especially around plugin lifecycle management and dependency handling. The changes ensure better separation of concerns and more predictable behavior when dealing with complex plugin dependencies.
2.8 KiB
2.8 KiB
Test Helpers
This document provides documentation for the test helper functions available in the Rhizome Node test suite.
testResolverWithPlugins
A helper function for testing custom resolvers with plugins and a sequence of deltas.
Import
import { testResolverWithPlugins, createTestDelta } from '@test-helpers/resolver-test-helper';
Signature
function testResolverWithPlugins<T>({
entityId,
plugins,
deltas,
expectedResult
}: {
entityId: string;
plugins: Record<string, ResolverPlugin>;
deltas: Delta[];
expectedResult: (result: T) => void;
}): Promise<void>;
Parameters
entityId
: The ID of the entity to testplugins
: An object mapping property names to their respective resolver pluginsdeltas
: An array ofDelta
objects to processexpectedResult
: A callback function that receives the resolved result for assertions
Return Value
A promise that resolves when the test is complete.
Example Usage
import { testResolverWithPlugins, createTestDelta } from '@test-helpers/resolver-test-helper';
import { ConcatenationPlugin } from '@src/views/resolvers/custom-resolvers/builtin-plugins';
describe('MyCustomResolver', () => {
test('should process deltas correctly', async () => {
// Run test with plugins and deltas
await testResolverWithPlugins({
entityId: 'entity1',
plugins: {
myProperty: new ConcatenationPlugin()
},
deltas: [
createTestDelta('user1', 'host1')
.setProperty('entity1', 'myProperty', 'value1')
.buildV1(),
createTestDelta('user1', 'host1')
.setProperty('entity1', 'myProperty', 'value2')
.buildV1()
],
expectedResult: (result) => {
expect(result.properties.myProperty).toBe('value1 value2');
}
});
});
});
createTestDelta
A helper function for creating test deltas with a fluent API.
Example Usage
const delta = createTestDelta('user1', 'host1')
.withTimestamp(1000)
.setProperty('entity1', 'tags', 'red', 'color1')
.buildV1();
How It Works
- Creates a new
Lossless
instance for the test - Sets up a
CustomResolver
with the provided plugins - Ingests all provided deltas into the
Lossless
instance - Retrieves a view for the specified entity
- Processes the view through the resolver
- Calls the
expectedResult
callback with the resolved entity
Best Practices
- Use this helper when testing custom resolvers with plugins
- The helper handles all setup and teardown of test resources
- Use
createTestDelta
for consistent delta creation in tests - The helper ensures type safety between the resolver and the expected result type
- Each test gets a fresh
Lossless
instance automatically