diff --git a/packages/jest/src/index.js b/packages/jest/src/index.js index 01567e9a9..f7c9c8692 100644 --- a/packages/jest/src/index.js +++ b/packages/jest/src/index.js @@ -63,7 +63,7 @@ module.exports = (options = {}) => (neutrino) => { moduleNameMapper: Object.keys(aliases).reduce( (mapper, key) => ({ ...mapper, - [`^${key}$`]: `${getFinalPath(aliases[key])}$1`, + [`^${key}$`]: `${getFinalPath(aliases[key])}`, }), { [extensionsToNames(media)]: require.resolve('./file-mock'), diff --git a/packages/jest/test/jest_test.js b/packages/jest/test/jest_test.js index c96a805d6..113e5fecf 100644 --- a/packages/jest/test/jest_test.js +++ b/packages/jest/test/jest_test.js @@ -1,3 +1,4 @@ +import path from 'path'; import test from 'ava'; import airbnbPreset from '../../airbnb'; import eslintPreset from '../../eslint'; @@ -150,3 +151,18 @@ test('exposes babel config without babel-loader specific options', (t) => { t.false('cacheIdentifier' in babelOptions); t.false('customize' in babelOptions); }); + +test('configures webpack aliases in moduleNameMapper correctly', (t) => { + const api = new Neutrino(); + const reactPath = path.resolve(path.join('node_modules', 'react')); + api.use(reactPreset()); + api.use(mw()); + api.config.resolve.alias.set('react', reactPath); + const config = api.outputHandlers.get('jest')(api); + + t.true( + Object.entries(config.moduleNameMapper).some(([key, alias]) => { + return key === '^react$' && alias === reactPath; + }), + ); +});