Skip to content

Commit

Permalink
Use rootDir from ProjectConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonchinn178 committed Mar 3, 2024
1 parent 7e6a3c1 commit b3f945c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
10 changes: 8 additions & 2 deletions packages/jest-core/src/SearchSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export default class SearchSource {

private async _getTestPaths(
globalConfig: Config.GlobalConfig,
projectConfig: Config.ProjectConfig,
changedFiles?: ChangedFiles,
): Promise<SearchResult> {
if (globalConfig.onlyChanged) {
Expand Down Expand Up @@ -297,7 +298,7 @@ export default class SearchSource {
} else {
return this.findMatchingTests(
globalConfig.testPathPatterns.toExecutor({
rootDir: globalConfig.rootDir,
rootDir: projectConfig.rootDir,
}),
);
}
Expand Down Expand Up @@ -327,10 +328,15 @@ export default class SearchSource {

async getTestPaths(
globalConfig: Config.GlobalConfig,
projectConfig: Config.ProjectConfig,
changedFiles?: ChangedFiles,
filter?: Filter,
): Promise<SearchResult> {
const searchResult = await this._getTestPaths(globalConfig, changedFiles);
const searchResult = await this._getTestPaths(
globalConfig,
projectConfig,
changedFiles,
);

const filterPath = globalConfig.filter;

Expand Down
9 changes: 8 additions & 1 deletion packages/jest-core/src/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ import type {Filter, TestRunData} from './types';

const getTestPaths = async (
globalConfig: Config.GlobalConfig,
projectConfig: Config.ProjectConfig,
source: SearchSource,
outputStream: WriteStream,
changedFiles: ChangedFiles | undefined,
jestHooks: JestHookEmitter,
filter?: Filter,
) => {
const data = await source.getTestPaths(globalConfig, changedFiles, filter);
const data = await source.getTestPaths(
globalConfig,
projectConfig,
changedFiles,
filter,
);

if (data.tests.length === 0 && globalConfig.onlyChanged && data.noSCM) {
new CustomConsole(outputStream, outputStream).log(
Expand Down Expand Up @@ -188,6 +194,7 @@ export default async function runJest({
const searchSource = searchSources[index];
const matches = await getTestPaths(
globalConfig,
context.config,
searchSource,
outputStream,
changedFilesPromise && (await changedFilesPromise),
Expand Down
9 changes: 5 additions & 4 deletions packages/jest-core/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,14 @@ export default async function watch(

const emitFileChange = () => {
if (hooks.isUsed('onFileChange')) {
const testPathPatternsExecutor = new TestPathPatterns([]).toExecutor({
rootDir: globalConfig.rootDir,
});
const projects = searchSources.map(({context, searchSource}) => ({
config: context.config,
testPaths: searchSource
.findMatchingTests(testPathPatternsExecutor)
.findMatchingTests(
new TestPathPatterns([]).toExecutor({
rootDir: context.config.rootDir,
}),
)
.tests.map(t => t.path),
}));
hooks.getEmitter().onFileChange({projects});
Expand Down

0 comments on commit b3f945c

Please sign in to comment.