# rollup-jest

> Rollup preprocessor for Jest

Latest version **3.1.0** (published 2022-10-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install rollup-jest
pnpm add rollup-jest
yarn add rollup-jest
bun add rollup-jest
```

## 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 | 3.1.0 |
| Published | 2022-10-29 |
| First published | 2019-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12.0 |
| Dependencies | 1 |
| Unpacked size | 11.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Maintainers | ambarli |
| Keywords | jest, rollup, testing |

## Links

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

## Dependencies (1)

- [concat-merge](https://npm.io/package/concat-merge.md) ^1.0.2

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 3.1.0 (latest) — 2022-10-29
- 3.0.0 — 2022-06-06
- 2.0.0 — 2022-05-13
- 1.1.3 — 2021-09-28
- 1.1.2 — 2021-07-21
- 1.1.1 — 2021-01-30
- 1.1.0 — 2021-01-30
- 1.0.1 — 2021-01-09
- 1.0.0 — 2021-01-09
- 0.0.2 — 2019-01-20

## README

# rollup-jest

Rollup preprocessor for Jest.

[![Coverage Status](https://coveralls.io/repos/github/ambar/rollup-jest/badge.svg?branch=master)](https://coveralls.io/github/ambar/rollup-jest?branch=master)
[![npm version](https://badgen.net/npm/v/rollup-jest)](https://www.npmjs.com/package/rollup-jest)

## Install

```bash
npm install rollup-jest rollup --save-dev
```

## Usage

Add preset to Jest config:

```json
{
  "jest": {
    "preset": "rollup-jest"
  }
}

// alternatively, specifying the files to transform:
{
  "jest": {
    "transform": {
      "\\.m?js$": "rollup-jest"
    },
  }
}

// or with options:
// the preset enables sourcemaps by default
{
  "jest": {
    "transform": {
      "\\.m?js$": ["rollup-jest", {"output": {"sourcemap": true}}]
    },
  }
}
```

Write your tests with ES modules:

```js
import path from 'path'

test('parses extname', () => {
  expect(path.extname('foo.md')).toBe('.md')
})
```

Happy testing!

## Configuration

### Use `configFile` field

NOTE: To use ESM format `configFile` in Rollup v3, you should add `--experimental-vm-module` flag to run jest，eg. `NODE_OPTIONS=--experimental-vm-modules npm run test`

```json
{
  "jest": {
    "transform": {
      "\\.js$": ["rollup-jest", {"configFile": "./rollup.config.js"}]
    }
  }
}
```

`rollup.config.js`:

```js
import inject from '@rollup/plugin-inject'

let config = {}
if (process.env.NODE_ENV === 'test') {
  config = {
    plugins: [inject({React: 'react'})],
  }
}

export default config
```

### Use inline config

```json
{
  "jest": {
    "transform": {
      "\\.js$": [
        "rollup-jest",
        {"plugins": [["@rollup/plugin-inject", {"React": "react"}]]}
      ]
    }
  }
}
```

### All options

- `useCache: boolean`: Default `true`. Enable caching of entry module. This can mess with plugins (e.g. typescript).
- `resolveImports: 'relative' | boolean`: Default `false`. Resolve (bundle) imports, either all (incl. packages) or only relative files.
- `args: any`: If your config file exports a function, you can use this field to pass arguments that aren't supported in rollup's `inputOptions`.
- `plugins: Plugin[]`: Gets merged with plugins from config file. Special syntax `[name, options]` allows you to specify the plugin in json without `require`.

## Related

- [es-jest](https://github.com/ambar/es-jest)
- [babel-jest](https://github.com/facebook/jest/tree/master/packages/babel-jest)
- [ts-jest](https://github.com/kulshekhar/ts-jest)

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