-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
84 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { promises as fs } from 'fs'; | ||
import path from 'path'; | ||
|
||
// Recursively find directories and check for package.json with a test script | ||
export async function discoverTestDirs(dirToSearch: string): Promise<string[]> { | ||
const files = await fs.readdir(dirToSearch, { withFileTypes: true }); | ||
|
||
return files.reduce( | ||
async (accPromise, file) => { | ||
const acc = await accPromise; | ||
|
||
const fullPath = path.join(dirToSearch, file.name); | ||
|
||
if (file.isDirectory() && !fullPath.includes('node_modules')) { | ||
// Check for package.json and if it contains a test script | ||
const packageJsonPath = path.join(fullPath, 'package.json'); | ||
const hasTestScript = await checkForTestScript(packageJsonPath); | ||
|
||
// Recurse into subdirectory | ||
return [ | ||
...acc, | ||
...(hasTestScript ? [fullPath] : []), | ||
...(await discoverTestDirs(fullPath)) | ||
]; | ||
} | ||
|
||
return []; | ||
}, | ||
Promise.resolve([] as string[]) | ||
); | ||
} | ||
|
||
// Check if package.json exists and contains a test script | ||
async function checkForTestScript(packageJsonPath: string): Promise<boolean> { | ||
try { | ||
const packageJson = await fs.readFile(packageJsonPath, 'utf-8'); | ||
const packageData = JSON.parse(packageJson); | ||
return ( | ||
packageData.scripts !== undefined && | ||
packageData.scripts.test !== undefined | ||
); | ||
} catch { | ||
// Return false if the file doesn't exist or there's a JSON error | ||
return false; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { discoverTestDirs } from './discover_test_dirs.js'; | ||
import { dirToTestInfo } from './dir_to_test_info.js'; | ||
|
||
export async function getTestInfos(dirs: string[], excludeDirs: string[]) { | ||
const allDirs = ( | ||
await dirs.reduce( | ||
async (accPromise, dir) => { | ||
const acc = await accPromise; | ||
const discoveredDirs = await discoverTestDirs(dir); | ||
return [...acc, ...discoveredDirs]; | ||
}, | ||
Promise.resolve([] as string[]) | ||
) | ||
) | ||
.filter((dir) => dir && !isExcluded(dir, excludeDirs)) | ||
.sort(); | ||
|
||
const testInfos = allDirs.map((dir) => dirToTestInfo(dir)); | ||
|
||
return testInfos; | ||
} | ||
|
||
function isExcluded(dir, excludeDirs) { | ||
return excludeDirs.some((exclude) => dir.includes(exclude)); | ||
} |
File renamed without changes.