Skip to content

Commit

Permalink
add base case to get_test_info recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Jan 21, 2025
1 parent c22de20 commit 8997eb9
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions .github/actions/get_test_infos/discover_test_dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ import { join } from 'path';

// Recursively find directories and check for package.json with a test script
export async function discoverTestDirs(dirToSearch: string): Promise<string[]> {
// Check the root directory first
const hasTestScript = await checkForTestScript(
join(dirToSearch, 'package.json')
);
if (hasTestScript === true) {
return [dirToSearch];
}

// If no test script found, check subdirectories
const files = await readdir(dirToSearch, { withFileTypes: true });

return files.reduce(
async (accPromise, file) => {
const acc = await accPromise;

const fullPath = join(dirToSearch, file.name);

if (file.isDirectory() && !fullPath.includes('node_modules')) {
// Check for package.json and if it contains a test script
const packageJsonPath = join(fullPath, 'package.json');
const hasTestScript = await checkForTestScript(packageJsonPath);

// Recurse into subdirectory
return [
...acc,
...(hasTestScript ? [fullPath] : []),
...(await discoverTestDirs(fullPath))
];
return [...acc, ...(await discoverTestDirs(fullPath))];
}

return acc;
Expand Down

0 comments on commit 8997eb9

Please sign in to comment.