Forger Help

Integration with Jest

Jest + ts-jest is the primary environment Forger is developed and tested in. The key points: use the ts-patch compiler inside ts-jest and register Forger's transformer.

1. Install dependencies

npm install --save-dev @artstesh/forger ts-patch

2. Configure ts-jest

The transformer must run for the spec files — this is where Forger.create<T>() calls live:

/** jest.config.js */ module.exports = { preset: 'ts-jest', transform: { '.*.spec.ts': ['ts-jest', { compiler: 'ts-patch/compiler', astTransformers: { before: ['@artstesh/forger/lib/utils/transformer'] } }] } };

Two things matter:

  • compiler: 'ts-patch/compiler' — the patched TypeScript compiler that executes plugins-declared transformers;

  • astTransformers.before — Forger's transformer, applied to the AST before ts-jest transpiles the spec.

Alternative: project-wide tsconfig plugins

Instead of (or in addition to) astTransformers, declare the transformer in tsconfig.json:

{ "compilerOptions": { "plugins": [ { "transform": "@artstesh/forger/lib/utils/transformer" } ] } }

With ts-patch/compiler as the ts-jest compiler, plugins declared this way are picked up automatically. This is the setup the Forger repository itself uses for its own test suite.

Isolated config variant

For suites that run specs in separate processes, a globals-based config also works (this is the jest-isolated.config.js variant used in the Forger repository):

/** jest-isolated.config.js */ module.exports = { preset: 'ts-jest', cache: false, globals: { 'ts-jest': { compiler: 'ts-patch/compiler', astTransformers: { before: ['@artstesh/forger/lib/utils/transformer'] } } } };

Sanity check

it('forger is wired up', () => { expect(typeof Forger.create<string>()).toBe('string'); });

If this fails with undefined, the transformer is not being applied — re-check step 2. See Caveats.

08 September 2026