3.1.0 • Published 2 years ago

rollup-jest v3.1.0

Weekly downloads
964
License
MIT
Repository
github
Last release
2 years ago

rollup-jest

Rollup preprocessor for Jest.

Coverage Status npm version

Install

npm install rollup-jest rollup --save-dev

Usage

Add preset to Jest config:

{
  "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:

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

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

rollup.config.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

{
  "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

3.1.0

2 years ago

3.0.0

2 years ago

2.0.0

2 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago