Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
jest: Fix configuration of Webpack aliases (#1577)
Browse files Browse the repository at this point in the history
  • Loading branch information
constgen authored Jun 25, 2020
1 parent 230e815 commit 3e66d22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
16 changes: 16 additions & 0 deletions packages/jest/test/jest_test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'path';
import test from 'ava';
import airbnbPreset from '../../airbnb';
import eslintPreset from '../../eslint';
Expand Down Expand Up @@ -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;
}),
);
});

0 comments on commit 3e66d22

Please sign in to comment.