Skip to content

Conversation

@damien-thiesson
Copy link

Description

This PR adds a disableFaker option to allow preserving literal {{...}} expressions in fixtures without Faker processing them. This is useful when fixtures contain template syntax (e.g., Handlebars templates) that conflicts with Faker's syntax.

Problem

Currently, any string containing {{...}} in fixtures is automatically processed by Faker. This causes issues when users need to store actual template strings that use the same syntax.

Example:

  entity: EmailTemplate
  items:
    welcome:
      subject: "Welcome {{firstName}}"  # This gets processed by Faker

Solution

Added a disableFaker boolean option that can be set at:

  1. Fixture level - in YAML/JSON fixture files
  2. Global level - when creating the Parser instance

When disableFaker is true, the FakerParser is skipped, preserving literal {{...}} expressions.

Usage

Per Fixture

  entity: EmailTemplate
  disableFaker: true
  items:
    welcome:
      subject: "Welcome {{firstName}}"  # Preserved as literal string

Globally

  const parser = new Parser({ disableFaker: true });
  const builder = new Builder(dataSource, parser, false);

Changes

  • Added disableFaker?: boolean to IFixturesConfig and IFixture interfaces
  • Created IParserOptions interface for Parser configuration
  • Updated Parser class to accept options and skip FakerParser when disabled
  • Updated Resolver to pass the disableFaker flag through fixtures
  • Added tests to verify the functionality
  • Updated README.md with documentation

Testing

  • Added 2 tests to test/unit/Parser.test.ts verifying faker expressions are preserved when disabled
  • All existing tests pass
  • Fully backward compatible - no breaking changes

Related Issues

This feature helps users who need to store template strings (Handlebars, Mustache, etc.) in their fixtures without having them processed as Faker expressions.

@skrosoft
Copy link

skrosoft commented Jul 8, 2025

Hello! I have the exact same problem, can I help with something to accelerate this approval workflow?

@skrosoft
Copy link

@damien-thiesson I have found a solution with no development required

  entity: EmailTemplate
  items:
    welcome:
      subject: "Welcome {<%= '{firstName}' %>}"

Using EJS templating you can combine variable without disabling FakerJS.

@damien-thiesson
Copy link
Author

Good find @skrosoft. I will continue to use my fork as my application fixtures happens to be very handlebars-heavy, and maintaining those replacements makes it quite inconvenient.

But given how specific my use case is, I am completely fine if you prefer to close this PR. I leave the outcome up to you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants