Compare commits

..

2 Commits

Author SHA1 Message Date
Joe Savona
28a2150dc7 [compiler][snap] Fix for filter mode with nested files, 'error.' prefix
Fixes some issues i ran into w my recent snap changes:
* Correctly match against patterns that contain subdirectories, eg `fbt/fbt-call`
* When checking if the input pattern has an extension, only prune known supported extensions. Our convention of `error.<name>` for fixtures that error makes the rest of the test name look like an extension to `path.extname()`.

Tested with lots of different patterns including `error.` examples at the top level and in nested directories, etc.
2025-11-25 15:32:46 -08:00
Joseph Savona
fb18ad3fd3 [compiler] Exhaustive deps: extra tests, improve diagnostic (#35213)
First, this adds some more tests and organizes them into an
`exhaustive-deps/` subdirectory.

Second, the diagnostics are overhauled. For each memo block we now
report a single diagnostic which summarizes the issue, plus individual
errors for each missing/extra dependency. Within the extra deps, we
distinguish whether it's truly extra vs whether its just a more (too)
precise version of an inferred dep. For example, if you depend on
`x.y.z` but the inferred dep was `x.y`. Finally, we print the full
inferred deps at the end as a hint (it's also a suggestion, but this
makes it more clear what would be suggested).
2025-11-25 12:09:09 -08:00

View File

@@ -44,21 +44,6 @@ function stripExtension(filename: string, extensions: Array<string>): string {
return filename;
}
/**
* Strip all extensions from a filename
* e.g., "foo.expect.md" -> "foo"
*/
function stripAllExtensions(filename: string): string {
let result = filename;
while (true) {
const extension = path.extname(result);
if (extension === '') {
return result;
}
result = path.basename(result, extension);
}
}
export async function readTestFilter(): Promise<TestFilter | null> {
if (!(await exists(FILTER_PATH))) {
throw new Error(`testfilter file not found at \`${FILTER_PATH}\``);
@@ -134,13 +119,15 @@ async function readInputFixtures(
// `alias-while` => search for `alias-while{.js,.jsx,.ts,.tsx}`
// `alias-while.js` => search as-is
// `alias-while.expect.md` => search for `alias-while{.js,.jsx,.ts,.tsx}`
const basename = path.basename(pattern);
const basenameWithoutExt = stripAllExtensions(basename);
const hasExtension = basename !== basenameWithoutExt;
const patternWithoutExt = stripExtension(pattern, [
...INPUT_EXTENSIONS,
SNAPSHOT_EXTENSION,
]);
const hasExtension = pattern !== patternWithoutExt;
const globPattern =
hasExtension && !pattern.endsWith(SNAPSHOT_EXTENSION)
? pattern
: `${basenameWithoutExt}{${INPUT_EXTENSIONS.join(',')}}`;
: `${patternWithoutExt}{${INPUT_EXTENSIONS.join(',')}}`;
return glob.glob(globPattern, {
cwd: rootDir,
});
@@ -181,7 +168,10 @@ async function readOutputFixtures(
await Promise.all(
filter.paths.map(pattern => {
// Strip all extensions and find matching .expect.md files
const basenameWithoutExt = stripAllExtensions(pattern);
const basenameWithoutExt = stripExtension(pattern, [
...INPUT_EXTENSIONS,
SNAPSHOT_EXTENSION,
]);
return glob.glob(`${basenameWithoutExt}${SNAPSHOT_EXTENSION}`, {
cwd: rootDir,
});