Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test config roots #168

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading