Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use rootDir from ProjectConfig
  • Loading branch information
brandonchinn178 committed Mar 7, 2024
commit 85bccf189e6b4d46e899a784036367f12740c82c
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
12 changes: 7 additions & 5 deletions packages/jest-core/src/__tests__/SearchSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,14 @@ describe('SearchSource', () => {
filter?: Filter,
) => {
const {searchSource, config} = await initSearchSource(initialOptions);
const allConfig = {
...config,
...initialOptions,
testPathPatterns: new TestPathPatterns([]),
};
const {tests: paths} = await searchSource.getTestPaths(
{
...config,
...initialOptions,
testPathPatterns: new TestPathPatterns([]),
},
allConfig,
allConfig,
null,
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