Skip to content

🎥 Make videos programmatically with React

Internal tests: Retry stalled package checks

Jonny Burgerca464f759c83
diff --git a/packages/it-tests/src/monorepo/no-dev-files.test.ts b/packages/it-tests/src/monorepo/no-dev-files.test.ts
index 71aa111dd8..5cf306a1b2 100644
--- a/packages/it-tests/src/monorepo/no-dev-files.test.ts
+++ b/packages/it-tests/src/monorepo/no-dev-files.test.ts
@@ -1,12 +1,13 @@
import {test} from 'bun:test';
import {copyFileSync, existsSync, unlinkSync} from 'fs';
import path from 'path';
-import {$} from 'bun';
import {getAllPackages} from './get-all-packages';
const packages = getAllPackages().filter((pkg) => pkg.pkg !== 'google-fonts');
const MAX_CONCURRENT_PACK_CHECKS = 8;
+const PACK_TIMEOUT_MS = 15000;
+const MAX_PACK_ATTEMPTS = 3;
let activePackChecks = 0;
const packCheckQueue: Array<() => void> = [];
@@ -49,8 +50,56 @@ const assertNoDevFilesPublished = async (pkgPath: string) => {
try {
let hasPackedLicense = false;
- const files = $`bun pm pack --dry-run`.cwd(dir).lines();
- for await (const file of files) {
+ let packedFiles = '';
+ for (let attempt = 1; attempt <= MAX_PACK_ATTEMPTS; attempt++) {
+ const startedAt = Date.now();
+ console.log(
+ `Packing ${packageJson.name} (attempt ${attempt}/${MAX_PACK_ATTEMPTS})`,
+ );
+ const proc = Bun.spawn([process.execPath, 'pm', 'pack', '--dry-run'], {
+ cwd: dir,
+ stdout: 'pipe',
+ stderr: 'pipe',
+ });
+ let timedOut = false;
+ const timeout = setTimeout(() => {
+ timedOut = true;
+ proc.kill();
+ }, PACK_TIMEOUT_MS);
+
+ try {
+ const [stdout, stderr, exitCode] = await Promise.all([
+ new Response(proc.stdout).text(),
+ new Response(proc.stderr).text(),
+ proc.exited,
+ ]);
+ if (timedOut) {
+ throw new Error(`timed out after ${PACK_TIMEOUT_MS}ms`);
+ }
+
+ if (exitCode !== 0) {
+ throw new Error(`exited with code ${exitCode}: ${stderr.trim()}`);
+ }
+
+ packedFiles = stdout;
+ console.log(
+ `Packed ${packageJson.name} in ${Date.now() - startedAt}ms`,
+ );
+ break;
+ } catch (error) {
+ const reason = error instanceof Error ? error.message : String(error);
+ console.warn(
+ `Packing ${packageJson.name} failed on attempt ${attempt}/${MAX_PACK_ATTEMPTS} after ${Date.now() - startedAt}ms: ${reason}`,
+ );
+ if (attempt === MAX_PACK_ATTEMPTS) {
+ throw new Error(`Could not pack ${packageJson.name}: ${reason}`);
+ }
+ } finally {
+ clearTimeout(timeout);
+ }
+ }
+
+ for (const file of packedFiles.split('\n')) {
const line = file.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, '');
if (!line.startsWith('packed')) {
continue;
@@ -112,5 +161,5 @@ test(
throw new Error(errors.join('\n'));
}
},
- {timeout: 40000},
+ {timeout: 90000},
);