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

jest: Fix configuration of Webpack aliases #1577

Merged
merged 3 commits into from Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/jest/src/index.js
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
@@ -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;
}),
);
});