Skip to content

Commit ae6afbc

Browse files
committed
fix(bazel/integration): support tracking sizes for file paths that contain output hashes in them (#2897)
Handle a size tracking file path that has a hash output in it PR Close #2897
1 parent c2f0cba commit ae6afbc

File tree

4 files changed

+58
-9
lines changed

4 files changed

+58
-9
lines changed

bazel/integration/test_runner/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ts_project(
99
deps = [
1010
"//bazel:node_modules/@types/node",
1111
"//bazel:node_modules/chalk",
12+
"//bazel:node_modules/tinyglobby",
1213
"//bazel:node_modules/true-case-path",
1314
],
1415
)

bazel/integration/test_runner/size-tracking.mts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import fs from 'node:fs/promises';
1212
import path from 'node:path';
1313
import chalk from 'chalk';
1414
import {debug} from './debug.mjs';
15+
import {globSync} from 'tinyglobby';
1516

1617
// Convience access to chalk colors.
1718
const {red, green} = chalk;
@@ -60,8 +61,8 @@ export class SizeTracker {
6061
};
6162

6263
for (let [filename, expectedSize] of Object.entries(expectedSizes)) {
63-
const generedFilePath = path.join(testWorkingDir, filename);
64-
if (!existsSync(generedFilePath)) {
64+
const generedFilePath = this.findFile(path.join(testWorkingDir, filename));
65+
if (generedFilePath === null) {
6566
sizes[filename] = {
6667
actual: undefined,
6768
failing: true,
@@ -121,4 +122,20 @@ export class SizeTracker {
121122
console.info(Array(80).fill('=').join(''));
122123
console.info();
123124
}
125+
126+
/**
127+
* Find the provided file, replacing hash indicator if necessary for discovery, returns null if
128+
* the file cannot be found.
129+
*/
130+
private findFile(filePath: string): string | null {
131+
if (existsSync(filePath)) {
132+
return filePath;
133+
}
134+
const filePathPattern = filePath.replace('[hash]', '*');
135+
const matchedFiles = globSync(filePathPattern, {onlyFiles: true});
136+
if (matchedFiles.length === 1) {
137+
return matchedFiles[0];
138+
}
139+
return null;
140+
}
124141
}

bazel/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"wait-on": "^8.0.3",
1818
"yargs": "18.0.0",
1919
"protractor": "7.0.0",
20-
"selenium-webdriver": "4.34.0"
20+
"selenium-webdriver": "4.33.0",
21+
"tinyglobby": "0.2.14"
2122
},
2223
"pnpm": {
2324
"onlyBuiltDependencies": []

bazel/pnpm-lock.yaml

Lines changed: 36 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)