Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
createFixture
✓ import { createFixture } from 'llparse-test-fixture';
✗ const createFixture = require('llparse-test-fixture').createFixture;
The library primarily targets ESM environments for testing modern Node.js and browser projects. While CJS might work via transpilation, direct `require` is discouraged since v3 due to its TypeScript-first design.
ParserTestStream
✓ import { ParserTestStream } from 'llparse-test-fixture';
✗ import ParserTestStream from 'llparse-test-fixture/stream';
This is a named export; there is no default export. Direct subpath imports are generally not supported or recommended for stability.
IParsedEvent
✓ import type { IParsedEvent } from 'llparse-test-fixture';
✗ import { IParsedEvent } from 'llparse-test-fixture';
IParsedEvent is a TypeScript type definition, intended for type-only imports to avoid bundling unnecessary runtime code. Using a regular import might lead to compilation errors in some TypeScript configurations.
Demonstrates how to use `llparse-test-fixture` to test a hypothetical `llparse`-generated parser, feeding it data, capturing events, and asserting expected outcomes.
import { createFixture, ParserTestStream, IParsedEvent } from 'llparse-test-fixture';
// Assume 'my-llparse-parser' is a module that exports a class
// generated by llparse, with a parse() method and event callbacks.
// For demonstration, we'll mock a simple parser structure.
interface MyParserCallbackEvents {
on_data?: (value: number) => void;
on_complete?: () => void;
}
class MockLLParseParser {
private callbacks: MyParserCallbackEvents = {};
constructor(callbacks: MyParserCallbackEvents) {
this.callbacks = callbacks;
}
// Simulate parsing, calling callbacks based on input
parse(data: Buffer): number {
for (const byte of data) {
if (byte === 0x01 && this.callbacks.on_data) {
this.callbacks.on_data(byte);
} else if (byte === 0x02 && this.callbacks.on_complete) {
this.callbacks.on_complete();
}
}
return data.length;
}
// Simulate reinitialization
reset(): void {
console.log('Parser reset.');
}
}
describe('My LLParse Parser', () => {
it('should parse simple data and trigger complete event', async () => {
const events: IParsedEvent[] = [];
const fixture = createFixture(MockLLParseParser, {
on_data: (value) => events.push({ type: 'data', value }),
on_complete: () => events.push({ type: 'complete' })
});
const parser = fixture.parser; // Access the mocked parser instance
const stream = new ParserTestStream(parser);
stream.feed(Buffer.from([0x01, 0x01]));
stream.feed(Buffer.from([0x02]));
stream.end();
// Wait for all async parsing to settle if applicable (mocked here as sync)
await new Promise(resolve => setImmediate(resolve));
expect(events).toEqual([
{ type: 'data', value: 1 },
{ type: 'data', value: 1 },
{ type: 'complete' }
]);
expect(fixture.getCalls('on_complete').length).toBe(1);
});
it('should handle parser reset correctly', async () => {
const events: IParsedEvent[] = [];
const fixture = createFixture(MockLLParseParser, {
on_data: (value) => events.push({ type: 'data', value })
});
const parser = fixture.parser;
parser.parse(Buffer.from([0x01]));
fixture.reset(); // Calls the parser's reset method
parser.parse(Buffer.from([0x01]));
expect(events.length).toBe(2); // Events before and after reset
});
});
Errors
Common errors & fixes
Error: Cannot find module 'llparse-test-fixture'
The package is not installed or the import path is incorrect, or it's a CommonJS project trying to import an ESM-only library.
fixRun `npm install llparse-test-fixture` or `yarn add llparse-test-fixture`. For CJS projects, ensure proper transpilation or switch to ESM if possible, as the library is primarily designed for ESM.
TypeError: Cannot read properties of undefined (reading 'on_data')
The mocked parser or the fixture was not correctly initialized with the expected callback handlers, or the `llparse` parser logic changed its expected callback names.
fixDouble-check the `createFixture` call to ensure all expected `llparse` callbacks are provided. Consult the documentation for your `llparse`-generated parser to confirm the exact callback API.
TS2742: The inferred type of '...' cannot be named without a reference to '.../node_modules/llparse-test-fixture/index.d.ts'. This is likely not portable. A type annotation is necessary.
This TypeScript error indicates that a type inference resulted in a complex type that TypeScript cannot easily name or reference across module boundaries without an explicit import, often seen when `isolatedModules` is enabled.
fixExplicitly import and use the necessary types, e.g., `import type { IParsedEvent } from 'llparse-test-fixture';` for type-only imports, or add explicit type annotations to variables where the complex type is inferred. Audit
Dependencies
llparserequiredProvides the core parser generation API for which this package creates test fixtures. While not a direct runtime dependency of the fixture itself, it's a conceptual peer dependency for any project using this fixture to test `llparse`-generated code.