CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jest-each

Parameterised tests for Jest that enable running the same test multiple times with different data sets using arrays or tagged template literals

85

1.10x
Overview
Eval results
Files

task.mdevals/scenario-9/

TypeScript Code Transformer with Source Map Support

Build a custom code transformer for Jest that transforms TypeScript files and preserves source maps for accurate error reporting and debugging.

Problem Description

You need to create a Jest transformer that converts TypeScript code to JavaScript while maintaining source map information. This transformer should integrate into Jest's transformation pipeline and ensure that stack traces and error messages point to the original TypeScript source locations, not the compiled JavaScript.

Requirements

Your transformer must:

  1. Accept TypeScript source code and transform it to JavaScript
  2. Generate and preserve source maps through the transformation process
  3. Return both the transformed code and the source map in the format Jest expects
  4. Configure Jest to use your custom transformer for .ts files
  5. Ensure that when tests fail, the error messages reference the original TypeScript line numbers

Configuration

Create a Jest configuration that:

  • Maps .ts file extensions to your custom transformer
  • Enables source map support
  • Configures the transformer to preserve source maps through the transformation pipeline

Test Requirements

Write tests that verify:

  • The transformer correctly transforms TypeScript to JavaScript @test
  • Source maps are generated and included in the transformation result @test
  • Error stack traces reference original TypeScript line numbers, not compiled JavaScript @test

Implementation

@generates

API

import type { TransformOptions, TransformedSource } from '@jest/transform';

/**
 * Custom Jest transformer that converts TypeScript to JavaScript
 * and preserves source maps for accurate debugging
 */
export function process(
  sourceText: string,
  sourcePath: string,
  options: TransformOptions
): TransformedSource;

/**
 * Returns cache key for the transformer to enable proper caching
 */
export function getCacheKey?(
  sourceText: string,
  sourcePath: string,
  options: TransformOptions
): string;

Dependencies { .dependencies }

@jest/transform { .dependency }

Provides transformer types and interfaces for Jest's transformation pipeline.

typescript { .dependency }

TypeScript compiler for transforming TypeScript code to JavaScript.

Install with Tessl CLI

npx tessl i tessl/npm-jest-each

tile.json