Skip to content

Commit

Permalink
Merge pull request #168 from inversify/fix/update-test-config-to-dedu…
Browse files Browse the repository at this point in the history
…plicate-jest-haste-map

Update test config roots
  • Loading branch information
notaphplover authored Dec 8, 2024
2 parents 6024b53 + f449179 commit ebfa3b8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ function getJestJsProjectConfig(
) {
const testMatch = getTestMatch(extension, false);

return getJestProjectConfig(projectName, testMatch, testPathIgnorePatterns);
return getJestProjectConfig(
projectName,
false,
testMatch,
testPathIgnorePatterns,
);
}

export default getJestJsProjectConfig;
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import projectRoot from './projectRoot.js';
import getProjectRoot from './getProjectRoot.js';

/**
* @param { !string } projectName Jest project's name
* @param { !boolean } isTargetingSource True if test are under the source folder
* @param { !Array<string> } testMatch Expressions to match to test file paths
* @param { !Array<string> } testPathIgnorePatterns Expressions to match to ignored file paths by jest
* @returns { !import("@jest/types").Config.InitialProjectOptions } Jest config
*/
function getJestProjectConfig(projectName, testMatch, testPathIgnorePatterns) {
function getJestProjectConfig(
projectName,
isTargetingSource,
testMatch,
testPathIgnorePatterns,
) {
/** @type { !import("@jest/types").Config.InitialProjectOptions } */
const projectConfig = {
displayName: projectName,
coveragePathIgnorePatterns: ['/fixtures/', '/node_modules/'],
coverageThreshold: {
global: {
Expand All @@ -19,9 +24,10 @@ function getJestProjectConfig(projectName, testMatch, testPathIgnorePatterns) {
statements: 70,
},
},
displayName: projectName,
moduleFileExtensions: ['ts', 'js', 'json'],
rootDir: '.',
roots: [projectRoot],
roots: [getProjectRoot(isTargetingSource)],
testEnvironment: 'node',
testMatch: testMatch,
testPathIgnorePatterns: testPathIgnorePatterns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ function getJestTsProjectConfig(
const testMatch = getTestMatch(extension, true);

return {
...getJestProjectConfig(projectName, testMatch, testPathIgnorePatterns),
...getJestProjectConfig(
projectName,
true,
testMatch,
testPathIgnorePatterns,
),
transform: {
'^.+\\.ts?$': 'ts-jest',
},
Expand Down
13 changes: 13 additions & 0 deletions packages/foundation/tools/jest-config/lib/config/getProjectRoot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const projectRoot = '<rootDir>';

/**
* @param { !boolean } isTargetingSource True if test are under the source folder
* @returns {!string } Project root path
*/
export default function getProjectRoot(isTargetingSource) {
if (isTargetingSource) {
return `${projectRoot}/src`;
} else {
return `${projectRoot}/lib/cjs`;
}
}
15 changes: 3 additions & 12 deletions packages/foundation/tools/jest-config/lib/config/getTestMatch.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import projectRoot from './projectRoot.js';
import getProjectRoot from './getProjectRoot.js';

/**
* @param { !string } testExtension Test extension files
* @param { !boolean } isTargetingSource True if test are under the source folder
* @returns { !Array.<string> }
*/
function getTestMatch(testExtension, isTargetingSource) {
let testMatch;
const projectRoot = getProjectRoot(isTargetingSource);

if (isTargetingSource) {
testMatch = [`${projectRoot}/src/**/*${testExtension}`];
} else {
testMatch = [
`${projectRoot}/{dist,lib}/*${testExtension}`,
`${projectRoot}/{dist,lib}/!(esm)/**/*${testExtension}`,
];
}

return testMatch;
return [`${projectRoot}/**/*${testExtension}`];
}

export default getTestMatch;

This file was deleted.

0 comments on commit ebfa3b8

Please sign in to comment.