Skip to content

Commit

Permalink
fix: repair jest optimization for Angular 14 upgrade (#1210)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi authored Jul 19, 2022
1 parent c824159 commit 491d78b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
10 changes: 7 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const fs = require('fs');
const { pathsToModuleNameMapper } = require('ts-jest');

const tsConfig = require('comment-json').parse(fs.readFileSync('./tsconfig.json', { encoding: 'utf-8' }));

const esModules = ['lodash-es/.*', 'swiper', 'ssr-window', 'dom7', '.*\\.mjs$'];

module.exports = {
Expand All @@ -13,9 +18,7 @@ module.exports = {
setupFilesAfterEnv: ['<rootDir>/src/setupJest.ts'],
transformIgnorePatterns: [`node_modules/(?!${esModules.join('|')})`],
moduleNameMapper: {
'^ish-(.*)$': '<rootDir>/src/app/$1',
'^organization-management$': '<rootDir>/projects/organization-management/src/app/exports',
'^requisition-management$': '<rootDir>/projects/requisition-management/src/app/exports',
...pathsToModuleNameMapper(tsConfig.compilerOptions.paths, { prefix: '<rootDir>' }),
// This forces jest to use a Node+CommonJS version of uuid. Refer to the following resources for more info:
// https://github.com/uuidjs/uuid/pull/616
// https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149
Expand All @@ -27,4 +30,5 @@ module.exports = {
'./src/jest-serializer/NgrxActionSerializer.js',
'./src/jest-serializer/NgrxActionArraySerializer.js',
],
dependencyExtractor: '<rootDir>/jest.dependency-extractor.js',
};
15 changes: 15 additions & 0 deletions jest.dependency-extractor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const crypto = require('crypto');
const fs = require('fs');

module.exports = {
extract(code, filePath, defaultExtract) {
if (/\.(module|facade)\.ts$/.test(filePath) && !/(store|shared)\.module\.ts$/.test(filePath)) {
return new Set();
}
return defaultExtract(code, filePath);
},

getCacheKey() {
return crypto.createHash('md5').update(fs.readFileSync(__filename)).digest('hex');
},
};

0 comments on commit 491d78b

Please sign in to comment.