@samitouri / QOS-React-2 / commits / 627b583650

[compiler][snap] Fix for filter mode with nested files, 'error.' prefix (#35215)

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.

Joseph Savona committed Nov 25, 2025 at 15:39 UTC 627b583650078514eff22498514682a8522282b1
1 file changed +10 -20
compiler/packages/snap/src/fixture-utils.ts
+10 -20
@@ -44,21 +44,6 @@ function stripExtension(filename: string, extensions: Array<string>): string {
44 return filename;
45 }
46
47 -/**
48 - * Strip all extensions from a filename
49 - * e.g., "foo.expect.md" -> "foo"
50 - */
51 -function stripAllExtensions(filename: string): string {
52 - let result = filename;
53 - while (true) {
54 - const extension = path.extname(result);
55 - if (extension === '') {
56 - return result;
57 - }
58 - result = path.basename(result, extension);
59 - }
60 -}
61 -
47 export async function readTestFilter(): Promise<TestFilter | null> {
48 if (!(await exists(FILTER_PATH))) {
49 throw new Error(`testfilter file not found at \`${FILTER_PATH}\``);
@@ -134,13 +119,15 @@ async function readInputFixtures(
119 // `alias-while` => search for `alias-while{.js,.jsx,.ts,.tsx}`
120 // `alias-while.js` => search as-is
121 // `alias-while.expect.md` => search for `alias-while{.js,.jsx,.ts,.tsx}`
137 - const basename = path.basename(pattern);
138 - const basenameWithoutExt = stripAllExtensions(basename);
139 - const hasExtension = basename !== basenameWithoutExt;
122 + const patternWithoutExt = stripExtension(pattern, [
123 + ...INPUT_EXTENSIONS,
124 + SNAPSHOT_EXTENSION,
125 + ]);
126 + const hasExtension = pattern !== patternWithoutExt;
127 const globPattern =
128 hasExtension && !pattern.endsWith(SNAPSHOT_EXTENSION)
129 ? pattern
143 - : `${basenameWithoutExt}{${INPUT_EXTENSIONS.join(',')}}`;
130 + : `${patternWithoutExt}{${INPUT_EXTENSIONS.join(',')}}`;
131 return glob.glob(globPattern, {
132 cwd: rootDir,
133 });
@@ -181,7 +168,10 @@ async function readOutputFixtures(
168 await Promise.all(
169 filter.paths.map(pattern => {
170 // Strip all extensions and find matching .expect.md files
184 - const basenameWithoutExt = stripAllExtensions(pattern);
171 + const basenameWithoutExt = stripExtension(pattern, [
172 + ...INPUT_EXTENSIONS,
173 + SNAPSHOT_EXTENSION,
174 + ]);
175 return glob.glob(`${basenameWithoutExt}${SNAPSHOT_EXTENSION}`, {
176 cwd: rootDir,
177 });