stefanbuck / jest-transform-yaml

Transforms YAML files into JSON output, similar to yaml-loader in Webpack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jest-transform-yaml

A Jest transformer that allows the import of YAML files

Description

When you store your data in YAML format for your application, you might want to import that data within your Jest tests. By default, Jest does not know how to import YAML files, so you will need to provide a transformer that can properly load it.

Installation

NOTE: I generally recommend saving exact dependencies to avoid accidental/unintentional updates, hence the added flags below.

# NPM
npm install jest-transform-yaml --save-dev

# Yarn
yarn add jest-transform-yaml --dev --exact

# PNPM
pnpm add jest-transform-yaml --save-dev --save-exact

Usage

In your jest.config.js (or jest.config.ts) file, add the following:

module.exports = {
    // ...
    transform: {
        // ... other transforms ...
        "\\.yaml$": "jest-transform-yaml",
    },
    "moduleFileExtensions": [
        // .. other file extensions ... 
        "yaml"
    ],
    // ...
}

Node support

Currently, this is set up to be tested against all Node LTS versions and the current. If you observe an issue within your project around Node version support, please feel free to raise a PR or add an issue 😄

Alternatives

About

Transforms YAML files into JSON output, similar to yaml-loader in Webpack


Languages

Language:TypeScript 85.5%Language:JavaScript 14.5%