Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-import-resolver-jest

JoinColony601.7kMIT3.0.2

🃏 Jest import resolution plugin for eslint-plugin-import

eslint, eslintplugin, jest, resolver, eslint-plugin-import

readme

eslint-import-resolver-jest

"I like my testutils where I can see 'em" 🕵🏽‍♀️

If you're using jest and you have installed custom name mappings in your config via the moduleNameMapper config and you're using the wonderful eslint-plugin-import you might get yelled at by eslint:

grafik

(I oftentimes create an alias for the helpers I use for testing)

Let's fix this!

yarn add eslint-import-resolver-jest -D

or

npm i eslint-import-resolver-jest -D

If you are using the package.json config option from jest everything should just work™.

If you are using a separate config file for jest using the --config option you have to point this plugin to it, too (in your .eslintrc):

"settings": {
  "import/resolver": {
    "jest": {
      "jestConfigFile": "./jest.conf.json"
    }
  }
}

That's it!

If you want to ensure that this resolver only applies to your test files, you can use ESLint's overrides configuration option:

"overrides": [
  {
    "files": ["**/__tests__/**/*.js"],
    "settings": {
      "import/resolver": {
        "jest": {
          "jestConfigFile": "./jest.conf.json"
        }
      }
    }
  }
]

Note

It will only resolve the modules in your test files that you specified via testRegex or testMatch in your jest config.

Contributing

Create issues in this repo or get active yourself:

yarn test # npm test works, too

License

MIT

changelog

eslint-import-resolver-jest changelog

[ > ] 2.1.2 / 30.06.2019

  • Fix test match global patterns on windows (thank you @KevinSjoberg!)

[ > ] 2.1.1 / 16.03.2018

  • Start resolving from file path (by setting basedir in resolve)

[ > ] 2.1.0 / 14.03.2018

  • Support absolute rootDir paths

[ > ] 2.0.1 / 19.02.2018

  • Just some tooling rearrangements and typo fixes

[ > ] 2.0.0 / 18.02.2018

  • Complete rewrite
  • Using the resolver module now to do the heavy lifting
  • Add flow type checking
  • Fixed moduleDirectories support
  • Add modulePaths support

[ > ] 1.1.0 / 02.11.2017

  • A couple of new features / improvements (thanks @GlennScott!)
  • Imports that do not have a file extension. Jest will attempt to resolve the import using a set of file extensions defined in moduleFileExtensions.
  • Allow <rootDir> to be defined within the testMatch. The resolver needs to replace <rootDir> from the testMatch entries before attempting calling micromatch.
  • Adding support to import an index file without an extension. The resolver will try source.ext1 -> source/index.ext1 -> source.ext2 -> source.index.ext2 etc
  • In resolver.test.js mocking find-root to simplify mocking fs.existingSync (every test uses the name root value "" so the mock always returns "")

[ > ] 1.0.1 / 24.08.2017

  • Fix replacement patterns in moduleNameMapper (thanks @samtgarson!)

[ > ] 1.0.0 / 16.04.2017

  • Initial release