Skip to content

Commit

Permalink
fix() add mapping to jest config
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Sep 20, 2019
1 parent 21d8b0c commit ff60b43
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/lib/library/library.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ function transform(options: LibraryOptions): LibraryOptions {
}

function updatePackageJson(options: LibraryOptions) {
const distRoot = join(options.path as Path, options.name, 'src');
const packageKey = options.prefix
? options.prefix + '/' + options.name
: options.name;

return (host: Tree) => {
if (!host.exists('package.json')) {
return host;
Expand All @@ -74,8 +79,21 @@ function updatePackageJson(options: LibraryOptions) {
host,
'package.json',
(packageJson: Record<string, any>) => {
// tslint:disable:no-unused-expression
packageJson.scripts && updateNpmScripts(packageJson.scripts);
if (packageJson.scripts) {
updateNpmScripts(packageJson.scripts);
}
if (!packageJson.jest) {
return;
}
if (!packageJson.jest.moduleNameMapper) {
packageJson.jest.moduleNameMapper = {};
}
const deepPackagePath = packageKey + '/(.*)';
packageJson.jest.moduleNameMapper[deepPackagePath] = join(
'<rootDir>' as Path,
distRoot,
'$1',
);
},
);
};
Expand Down

0 comments on commit ff60b43

Please sign in to comment.