@jest/transform

  • Version 29.3.1
  • Published
  • 51.3 kB
  • 15 dependencies
  • MIT license

Install

npm i @jest/transform
yarn add @jest/transform
pnpm add @jest/transform

Overview

Overview not available.

Index

Functions

function createScriptTransformer

createScriptTransformer: (
config: Config.ProjectConfig,
cacheFS?: StringMap
) => Promise<ScriptTransformer>;

    function createTranspilingRequire

    createTranspilingRequire: (
    config: Config.ProjectConfig
    ) => Promise<
    <TModuleType = unknown>(
    resolverPath: string,
    applyInteropRequireDefault?: boolean
    ) => Promise<TModuleType>
    >;

      function handlePotentialSyntaxError

      handlePotentialSyntaxError: (e: ErrorWithCodeFrame) => ErrorWithCodeFrame;

        function shouldInstrument

        shouldInstrument: (
        filename: string,
        options: ShouldInstrumentOptions,
        config: Config.ProjectConfig
        ) => boolean;

          Interfaces

          interface AsyncTransformer

          interface AsyncTransformer<TransformerConfig = unknown> {}

            property canInstrument

            canInstrument?: boolean;
            • Indicates if the transformer is capable of instrumenting the code for code coverage.

              If V8 coverage is _not_ active, and this is true, Jest will assume the code is instrumented. If V8 coverage is _not_ active, and this is false. Jest will instrument the code returned by this transformer using Babel.

            property getCacheKey

            getCacheKey?: (
            sourceText: string,
            sourcePath: string,
            options: TransformOptions<TransformerConfig>
            ) => string;

              property getCacheKeyAsync

              getCacheKeyAsync?: (
              sourceText: string,
              sourcePath: string,
              options: TransformOptions<TransformerConfig>
              ) => Promise<string>;

                property process

                process?: (
                sourceText: string,
                sourcePath: string,
                options: TransformOptions<TransformerConfig>
                ) => TransformedSource;

                  property processAsync

                  processAsync: (
                  sourceText: string,
                  sourcePath: string,
                  options: TransformOptions<TransformerConfig>
                  ) => Promise<TransformedSource>;

                    interface CallerTransformOptions

                    interface CallerTransformOptions {}

                      property supportsDynamicImport

                      supportsDynamicImport: boolean;

                        property supportsExportNamespaceFrom

                        supportsExportNamespaceFrom: boolean;

                          property supportsStaticESM

                          supportsStaticESM: boolean;

                            property supportsTopLevelAwait

                            supportsTopLevelAwait: boolean;

                              interface ShouldInstrumentOptions

                              interface ShouldInstrumentOptions
                              extends Pick<
                              Config.GlobalConfig,
                              'collectCoverage' | 'collectCoverageFrom' | 'coverageProvider'
                              > {}

                                property changedFiles

                                changedFiles?: Set<string>;

                                  property sourcesRelatedToTestsInChangedFiles

                                  sourcesRelatedToTestsInChangedFiles?: Set<string>;

                                    interface SyncTransformer

                                    interface SyncTransformer<TransformerConfig = unknown> {}

                                      property canInstrument

                                      canInstrument?: boolean;
                                      • Indicates if the transformer is capable of instrumenting the code for code coverage.

                                        If V8 coverage is _not_ active, and this is true, Jest will assume the code is instrumented. If V8 coverage is _not_ active, and this is false. Jest will instrument the code returned by this transformer using Babel.

                                      property getCacheKey

                                      getCacheKey?: (
                                      sourceText: string,
                                      sourcePath: string,
                                      options: TransformOptions<TransformerConfig>
                                      ) => string;

                                        property getCacheKeyAsync

                                        getCacheKeyAsync?: (
                                        sourceText: string,
                                        sourcePath: string,
                                        options: TransformOptions<TransformerConfig>
                                        ) => Promise<string>;

                                          property process

                                          process: (
                                          sourceText: string,
                                          sourcePath: string,
                                          options: TransformOptions<TransformerConfig>
                                          ) => TransformedSource;

                                            property processAsync

                                            processAsync?: (
                                            sourceText: string,
                                            sourcePath: string,
                                            options: TransformOptions<TransformerConfig>
                                            ) => Promise<TransformedSource>;

                                              interface TransformationOptions

                                              interface TransformationOptions
                                              extends ShouldInstrumentOptions,
                                              CallerTransformOptions {}

                                                property isInternalModule

                                                isInternalModule?: boolean;

                                                  interface TransformOptions

                                                  interface TransformOptions<TransformerConfig = unknown>
                                                  extends ReducedTransformOptions {}

                                                    property cacheFS

                                                    cacheFS: StringMap;
                                                    • Cached file system which is used by jest-runtime to improve performance.

                                                    property config

                                                    config: Config.ProjectConfig;
                                                    • Jest configuration of currently running project.

                                                    property configString

                                                    configString: string;
                                                    • Stringified version of the config - useful in cache busting.

                                                    property transformerConfig

                                                    transformerConfig: TransformerConfig;
                                                    • Transformer configuration passed through transform option by the user.

                                                    Type Aliases

                                                    type ScriptTransformer

                                                    type ScriptTransformer = ScriptTransformer_2;

                                                      type TransformedSource

                                                      type TransformedSource = {
                                                      code: string;
                                                      map?: FixedRawSourceMap | string | null;
                                                      };

                                                        type Transformer

                                                        type Transformer_2<TransformerConfig = unknown> =
                                                        | SyncTransformer<TransformerConfig>
                                                        | AsyncTransformer<TransformerConfig>;
                                                        • We have both sync (process) and async (processAsync) code transformation, which both can be provided. require will always use process, and import will use processAsync if it exists, otherwise fall back to process. Meaning, if you use import exclusively you do not need process, but in most cases supplying both makes sense: Jest transpiles on demand rather than ahead of time, so the sync one needs to exist.

                                                          For more info on the sync vs async model, see https://jestjs.io/docs/code-transformation#writing-custom-transformers

                                                        type TransformerCreator

                                                        type TransformerCreator<
                                                        X extends Transformer_2<TransformerConfig>,
                                                        TransformerConfig = unknown
                                                        > = (transformerConfig?: TransformerConfig) => X;

                                                          type TransformerFactory

                                                          type TransformerFactory<X extends Transformer_2> = {
                                                          createTransformer: TransformerCreator<X>;
                                                          };
                                                          • Instead of having your custom transformer implement the Transformer interface directly, you can choose to export a factory function to dynamically create transformers. This is to allow having a transformer config in your jest config.

                                                          type TransformResult

                                                          type TransformResult = TransformTypes.TransformResult;

                                                            Package Files (1)

                                                            Dependencies (15)

                                                            Dev Dependencies (7)

                                                            Peer Dependencies (0)

                                                            No peer dependencies.

                                                            Badge

                                                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@jest/transform.

                                                            • Markdown
                                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@jest/transform)
                                                            • HTML
                                                              <a href="https://www.jsdocs.io/package/@jest/transform"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>