Registry / testing / efate
library1.5.1jsnpmunverified

Efate is a JavaScript and TypeScript test fixture generator designed to address common pain points in managing test data within moderate to large web applications. It provides a type-safe API for defining and creating test fixtures, offering a robust alternative to static JSON files. The library, currently at version 1.5.1, aims to ensure consistent, unique, and understandable values for test objects while allowing specific field overrides for particular test cases. Its core differentiator lies in preventing 'Test Fixture Change Transference,' where modifying a fixture for one test can inadvertently affect subsequent tests in the same file. Efate enables the generation of individual mock objects or arrays of objects, with granular control over data generation and overriding capabilities, fostering more reliable and maintainable test suites. While no specific release cadence is noted in the provided material, the 1.x version series suggests a stable and actively maintained state for its current feature set.

npm install efate
INSTALL
IMPORT
SIG · EFATE
E
efate
testingjavascriptv1.5.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createFixtureFactory
✓ import { createFixtureFactory } from 'efate';
✗ const createFixtureFactory = require('efate');
The primary entry point to initialize the fixture builder. Use ESM import for modern TypeScript/JavaScript projects.
Fixture
✓ import type { Fixture } from 'efate';
✗ import { Fixture } from 'efate';
Use 'import type' for type-only imports like `Fixture` and `FixtureBuilder` to ensure they are stripped during compilation, preventing potential runtime issues or bundle size increases.
FixtureBuilder
✓ import type { FixtureBuilder } from 'efate';
✗ import { FixtureBuilder } from 'efate';
Similar to `Fixture`, `FixtureBuilder` is a type definition and should be imported using 'import type'.

Demonstrates how to define a type-safe fixture, create single objects with and without overrides, and generate arrays of fixtures.

import { createFixtureFactory } from 'efate'; interface User { id: number; firstName: string; lastName: string; title?: string; } // Initialize the fixture factory const createFixture = createFixtureFactory(); // Define a user fixture with specified field generation rules const userFixture = createFixture<User>((t) => { t.id.asNumber(); // id increments for each new fixture t.firstName.asString(); t.lastName.asString(); }); // Create a single user fixture with default generated values const user1 = userFixture.create(); console.log('Single user (default):', user1); // Example: { id: 1, firstName: 'firstName1', lastName: 'lastName1' } // Create a user fixture with specific overrides const user2 = userFixture.create({ title: 'Lead Engineer', firstName: 'Alice' }); console.log('User with overrides:', user2); // Example: { id: 2, firstName: 'Alice', lastName: 'lastName2', title: 'Lead Engineer' } // Create an array of three user fixtures, with a partial override for the first element const usersArray = userFixture.createArrayWith(3, [ { firstName: 'Bob', lastName: 'Johnson' }, null, // No override for the second element { title: 'Manager' } // Override for the third element ]); console.log('Array of users:', usersArray);
Debug
Known issues
gotchaCareless mutation of fixture objects retrieved from `create()` or `createArrayWith()` in one test block can lead to unintended side effects in subsequent tests within the same file or test run if not properly isolated. Efate is designed to provide fresh instances, but local mutations are still possible.
fix
Always treat generated fixtures as potentially mutable within the scope of a single test. If you need a completely independent copy for further modification, consider deep cloning the object, although Efate aims to make this unnecessary for initial creation.
affects: >=1.0.0
gotchaAttempting to import Efate using CommonJS `require()` syntax (`const efate = require('efate');`) in a modern ESM-only project or build environment will result in runtime errors due to module resolution mismatches.
fix
Ensure you are using ECMAScript Module (ESM) `import` syntax: `import { createFixtureFactory } from 'efate';` within your TypeScript or modern JavaScript project configuration.
affects: >=1.0.0
gotchaWhen defining fixtures, ensure all fields referenced in the fixture definition (e.g., `t.id.asNumber()`) strictly adhere to the provided TypeScript interface `<T>`. Mismatches will lead to compilation errors.
fix
Verify that your fixture definition precisely matches the fields and types declared in your generic interface. If adding new fields, update the interface first.
affects: >=1.0.0
gotchaThe `createArrayWith` method accepts different override types (single Partial, array of Partials, or a function). Misunderstanding these nuances can lead to unexpected array generation behavior.
fix
Review the documentation for `createArrayWith` carefully. For per-element control, pass an array of `Partial<T>` where `null` or `undefined` indicates no override for that specific index.
affects: >=1.0.0
Errors
Common errors & fixes
Property 'someInvalidField' does not exist on type 'User'.
Attempting to define a fixture field that is not part of the `User` interface, or misspelling a field.
fix
Update your TypeScript interface (`User` in this example) to include 'someInvalidField', or correct the field name in your fixture definition.
TypeError: createFixtureFactory is not a function
This typically occurs when `efate` is imported incorrectly, often using CommonJS `require` in an environment expecting ESM, or incorrect destructuring.
fix
Ensure you are using `import { createFixtureFactory } from 'efate';` and that your project is configured for ESM or correctly transpiling CJS modules.
ReferenceError: userFixture is not defined
The `userFixture` variable was accessed before it was declared or outside its scope.
fix
Ensure `const userFixture = createFixture<User>(...)` is executed before `userFixture.create()` is called, and that both calls are within the same lexical scope.
Upgrade
Version history
1.5.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources