# jest-erb-transformer

> Jest transformer for Embedded Ruby (`.erb`) files in Ruby projects

Latest version **1.2.12** (published 2023-09-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install jest-erb-transformer
pnpm add jest-erb-transformer
yarn add jest-erb-transformer
bun add jest-erb-transformer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.12 |
| Published | 2023-09-04 |
| First published | 2020-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Chris Wood |
| Maintainers | cpcwood |
| Keywords | erb, erubi, transformer, jest, ruby, rails |

## Links

- npm: https://www.npmjs.com/package/jest-erb-transformer
- Repository: https://github.com/cpcwood/jest-erb-transformer
- Homepage: https://github.com/cpcwood/jest-erb-transformer#readme
- Issues: https://github.com/cpcwood/jest-erb-transformer/issues
- npm.io page: https://npm.io/package/jest-erb-transformer

## Dependencies (2)

- [babel-jest](https://npm.io/package/babel-jest.md) ^29.6.4
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.22.15

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.2.12 (latest) — 2023-09-04
- 1.2.11 — 2023-09-04
- 1.2.10 — 2023-02-12
- 1.2.9 — 2023-01-08
- 1.2.8 — 2022-09-12
- 1.2.7 — 2022-04-03
- 1.2.6 — 2021-09-24
- 1.2.5 — 2021-09-02
- 1.2.4 — 2021-07-01
- 1.2.3 — 2021-06-01
- 1.2.2 — 2021-05-11
- 1.2.1 — 2020-12-30
- 1.2.0 — 2020-12-29
- 1.1.1 — 2020-12-24
- 1.1.0 — 2020-11-19
- … 19 more at https://npm.io/package/jest-erb-transformer/versions

## README

# Jest ERB Transformer

[![npm-version](https://img.shields.io/npm/v/jest-erb-transformer.svg?color=blueviolet&style=flat-square)](https://www.npmjs.com/package/jest-erb-transformer) [![build-status](https://img.shields.io/circleci/build/gh/cpcwood/jest-erb-transformer?style=flat-square)](https://app.circleci.com/pipelines/github/cpcwood/jest-erb-transformer) [![code-coverage](https://img.shields.io/coveralls/github/cpcwood/jest-erb-transformer.svg?style=flat-square)](https://coveralls.io/github/cpcwood/jest-erb-transformer) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](https://standardjs.com)

## Overview 

Custom transformer for compiling Embedded Ruby template files (```.erb```) for use in the Jest JavaScript testing framework.

## Install

Add to project using your package manager, e.g. yarn:

```sh
yarn add jest-erb-transformer --dev
```

## Configuration

### Jest Configuration

Ensure the ```"erb"``` file extension and the jest-erb-transformer extension matcher and configuration is included in the project's ```package.json``` jest key:

```json
"moduleFileExtensions": [
  "js",
  "erb"
],
```

```json
"transform": {
  "^.+\\.erb$": "jest-erb-transformer"
}
```

See the [Jest docs](https://jestjs.io/docs/en/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object) for more information on the configuration of transformers.

### Options

To add custom configuration, such as using the Ruby on Rails runner for ERB compilation, add a configuration object to the transformer entry in the project ```package.json``` using the [Jest transformer configuration syntax](https://jestjs.io/docs/en/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object). For example, to compile in the rails environment:

```json
"transform": {
  "^.+\\.erb$": [ "jest-erb-transformer", { "application": "rails" } ]
}
```

#### Babel

By default the transformer does not process its output with [Babel](https://babeljs.io/). 

To perform post-processing with Babel, either configure the transformer ```babelConfig``` option as outlined in the options table below, or I have found including the ```.erb``` files in the [babel-jest](https://www.npmjs.com/package/babel-jest) transformer directly has worked in some scenarios. For example:

```json
"transform": {
  "^.+\\.js(?:\\.erb)?$": "babel-jest",
  "^.+\\.erb$": [ "jest-erb-transformer", { "application": "rails" } ]
  }
```

#### All Options

| Key | Default Value | Description |
| :--- | :--- | :--- |
| ```"application"``` | ```"ruby"``` | Transformer is run using ```ruby``` by default, set value to ```"rails"``` to use ```bin/rails runner```. The ```"rails"``` option can be useful if the .erb files include Ruby on Rails specific environment variables such as ```Rails.application.credentials```. |
| ```"engine"``` | ```"erb"``` | Transformer uses the ruby 'ERB' engine by default, to use the [Erubi](https://github.com/jeremyevans/erubi) engine set the value to ```"erubi"```. |
| ```"timeout"``` | ```"5000"``` | Set the timeout duration in milliseconds for the compilation of individual files. |
| ```"babelConfig"``` | ```false``` | Process the output of the ERB transformer using [babel-jest](https://www.npmjs.com/package/babel-jest). <br> Options: <ul><li>```false``` - Disables the use of Babel.</li><li>```true``` - Babel processing using project or file-relative [Babel configuration file](https://babeljs.io/docs/en/config-files).</li><li>```./path/to/.babelrc.json``` - Relative path to Babel configuration file to be used for processing.</li><li>```{ "comments": false }``` - Object containing [Babel options](https://babeljs.io/docs/en/options) to be used for processing.</li></ul> | 
## Contributing

Feel free to ask questions using [issues](https://github.com/cpcwood/jest-erb-transformer/issues) or contribute if you have any improvements.

## License

MIT

---
_Source: https://npm.io/package/jest-erb-transformer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
