# jest-test-module-preprocessor

> This package aims to simplify requiring module file when testing with Jest

Latest version **1.0.0** (published 2017-02-08) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install jest-test-module-preprocessor
pnpm add jest-test-module-preprocessor
yarn add jest-test-module-preprocessor
bun add jest-test-module-preprocessor
```

## 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.0.0 |
| Published | 2017-02-08 |
| First published | 2017-02-08 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | OpenGG |
| Maintainers | opengg |
| Keywords | jest |

## Links

- npm: https://www.npmjs.com/package/jest-test-module-preprocessor
- Repository: https://github.com/OpenGG/jest-test-module-preprocessor
- Homepage: https://github.com/OpenGG/jest-test-module-preprocessor#readme
- Issues: https://github.com/OpenGG/jest-test-module-preprocessor/issues
- npm.io page: https://npm.io/package/jest-test-module-preprocessor

## Recent versions

- 1.0.0 (latest) — 2017-02-08

## README

# jest-test-module-preprocessor
This package aims to simplify requiring module file when testing with Jest

## Usage

0. Run following command in project root

        npm install --save-dev jest-test-module-preprocessor

0. Add following property to your jest config

        {
          "transform": {
            "\\.js$": "<rootDir>/jest/transform.js"
          }
        }

0. Put following code in `jest/transform.js`

        const preprocessor = require('jest-test-module-preprocessor')();

        module.exports = {
          process: (...args) => {
            const transformed = preprocessor.process(...args);
            return transformed;
          },
        };

0. Then you can simplify require the module you intrested when writing test file

        // In <rootDir>/test/a/b/c/d.spec.js
        const d = require('__module__');

        // The above statement is same as
        // require('../../../../src/a/b/c/d.js');


## Configuration

When initializing preprocessor, an optional configuration can be used.

    const preprocessor = require('jest-test-module-preprocessor')({
      modulePlaceholder: '__module__',
      srcDir: 'src'
    });

## Notes about `babel-jest`

> When "transform" is overwritten in any way the `babel-jest` is not loaded automatically anymore

In order to utilize `babel-jest`, modify `jest/transform.js` as following:

    const preprocessor = require('jest-test-module-preprocessor')();

    const babel = require('babel-jest');

    module.exports = Object.assign(
      {},
      babel,
      {
        process: (...args) => {
          const transformed = preprocessor.process(...args);
          const code = babel.process(
            transformed,
            ...args.slice(1)
          );
          return code;
        },
      }
    );

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