-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
test(v10/cloudflare): Add Vite-build support to the integration-test runner #22539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import type { Envelope, EnvelopeItemType } from '@sentry/core'; | ||
| import { normalize } from '@sentry/core'; | ||
| import { createBasicSentryServer } from '@sentry-internal/test-utils'; | ||
| import { spawn } from 'child_process'; | ||
| import { existsSync } from 'fs'; | ||
| import { spawn, spawnSync } from 'child_process'; | ||
| import { existsSync, readdirSync, readFileSync } from 'fs'; | ||
| import { join } from 'path'; | ||
| import { inspect } from 'util'; | ||
| import { expect } from 'vitest'; | ||
|
|
@@ -18,6 +18,60 @@ export function cleanupChildProcesses(): void { | |
|
|
||
| process.on('exit', cleanupChildProcesses); | ||
|
|
||
| /** | ||
| * Resolve the wrangler config `wrangler dev` should serve for a worker. | ||
| * | ||
| * Most suites run straight from source (`wrangler dev --config <name>.jsonc`). | ||
| * A suite that opts into the Sentry Vite plugin instead ships a `vite.config.*` | ||
| * (and no top-level `main` in its wrangler config): for those we run `vite build` | ||
| * first — so the plugin's build-time auto-instrumentation transform runs — and | ||
| * point wrangler at the generated config under `dist/<worker>/wrangler.json`. | ||
| * | ||
| * `wranglerConfigName` selects which source config the Vite build corresponds to | ||
| * (`wrangler.jsonc` for the main worker, `wrangler-sub-worker.jsonc` for a sub), | ||
| * so a Vite suite's generated output is matched to the right worker. | ||
| */ | ||
| function resolveWorkerConfig(testPath: string, wranglerConfigName: string): string { | ||
| const sourceConfig = join(testPath, wranglerConfigName); | ||
| const viteConfig = ['vite.config.ts', 'vite.config.mts', 'vite.config.js', 'vite.config.mjs'] | ||
| .map(name => join(testPath, name)) | ||
| .find(existsSync); | ||
|
|
||
| // No Vite config → serve the source wrangler config unchanged (existing path). | ||
| if (!viteConfig) { | ||
| return sourceConfig; | ||
| } | ||
|
|
||
| const result = spawnSync('vite', ['build'], { cwd: testPath, stdio: process.env.DEBUG ? 'inherit' : 'ignore' }); | ||
| if (result.status !== 0) { | ||
| throw new Error(`vite build failed for ${testPath} (exit code ${result.status})`); | ||
|
Comment on lines
+45
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The Suggested FixCache or memoize the result of the Prompt for AI AgentAlso affects:
|
||
| } | ||
|
|
||
| // `@cloudflare/vite-plugin` emits one directory per worker under `dist/`, each | ||
| // containing a resolved `wrangler.json`. Match the one whose original config is | ||
| // this worker's source config so multi-worker suites map correctly. | ||
| const distDir = join(testPath, 'dist'); | ||
| const builtConfig = readdirSync(distDir, { withFileTypes: true }) | ||
|
sentry[bot] marked this conversation as resolved.
|
||
| .filter(entry => entry.isDirectory()) | ||
| .map(entry => join(distDir, entry.name, 'wrangler.json')) | ||
| .find(configPath => existsSync(configPath) && builtFromSource(configPath, sourceConfig)); | ||
|
|
||
| if (!builtConfig) { | ||
| throw new Error(`Could not locate a Vite-built wrangler config for ${sourceConfig} under ${distDir}`); | ||
| } | ||
| return builtConfig; | ||
|
andreiborza marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** Whether a generated `wrangler.json` was built from the given source config. */ | ||
| function builtFromSource(builtConfigPath: string, sourceConfigPath: string): boolean { | ||
| try { | ||
| const built = JSON.parse(readFileSync(builtConfigPath, 'utf8')) as { userConfigPath?: string; configPath?: string }; | ||
| return built.userConfigPath === sourceConfigPath || built.configPath === sourceConfigPath; | ||
|
sentry[bot] marked this conversation as resolved.
|
||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
andreiborza marked this conversation as resolved.
|
||
|
|
||
| // Wrangler can report "Ready" before it can actually handle requests. | ||
| // This retries fetch on connection errors and transient 500 responses to handle this race condition. | ||
| // The budget (maxRetries * retryDelayMs) must cover the "ready-but-not-serving" window, which can be | ||
|
|
@@ -299,7 +353,7 @@ export function createRunner(...paths: string[]) { | |
| [ | ||
| 'dev', | ||
| '--config', | ||
| join(testPath, 'wrangler-sub-worker.jsonc'), | ||
| resolveWorkerConfig(testPath, 'wrangler-sub-worker.jsonc'), | ||
| '--show-interactive-dev-session', | ||
| 'false', | ||
| '--var', | ||
|
|
@@ -325,7 +379,7 @@ export function createRunner(...paths: string[]) { | |
| [ | ||
| 'dev', | ||
| '--config', | ||
| join(testPath, 'wrangler.jsonc'), | ||
| resolveWorkerConfig(testPath, 'wrangler.jsonc'), | ||
|
andreiborza marked this conversation as resolved.
|
||
| '--show-interactive-dev-session', | ||
| 'false', | ||
| '--var', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,7 +155,8 @@ | |
| "**/nx/minimatch": "10.2.5", | ||
| "**/ng-packagr/postcss-url/minimatch": "3.1.5", | ||
| "**/@angular-devkit/build-angular/minimatch": "5.1.9", | ||
| "**/nitropack/rollup-plugin-visualizer": "^6.0.3" | ||
| "**/nitropack/rollup-plugin-visualizer": "^6.0.3", | ||
| "vite": "^6.4.3" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vite 7 pin forced to 6Medium Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit 3071610. Configure here. |
||
| }, | ||
| "version": "0.0.0", | ||
| "name": "sentry-javascript" | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.