Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
chore(e2e-tests): Use tarball symlinks for E2E tests instead of verdaccio#20386
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
08876641f93f1f9287dd50800fa75cb9c0ba34d06da78242bb2caccb4cccd6326432cba8a9f05File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Diff view
Diff view
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,3 +4,4 @@ tmp | ||
| .tmp_build_stderr | ||
| pnpm-lock.yaml | ||
| .last-run.json | ||
| packed | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* eslint-disable no-console */ | ||
| import { addPnpmOverrides } from './lib/pnpmOverrides'; | ||
| import * as path from 'path'; | ||
| async function run(): Promise<void> { | ||
| const tmpDirPath = process.argv[2]; | ||
| const packedDirPath = process.argv[3]; | ||
| if (!tmpDirPath || !packedDirPath) { | ||
| throw new Error('Tmp dir path and packed dir path are required'); | ||
| } | ||
| await addPnpmOverrides(path.resolve(tmpDirPath), path.resolve(packedDirPath)); | ||
| } | ||
| run().catch(error => { | ||
| console.error(error); | ||
| process.exit(1); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import * as path from 'path'; | ||
| import * as fs from 'fs'; | ||
| import { sync as globSync } from 'glob'; | ||
| const E2E_TESTS_ROOT = path.resolve(__dirname, '..'); | ||
| const REPOSITORY_ROOT = path.resolve(E2E_TESTS_ROOT, '../..'); | ||
| /** | ||
| * Workspace @sentry and @sentry-internal packages that have a built tarball for the E2E version. | ||
| * @returns The names of the published Sentry tarball packages. | ||
| */ | ||
| export function getPublishedSentryTarballPackageNames(): string[] { | ||
| const version = getE2eTestsPackageVersion(); | ||
| const names: string[] = []; | ||
| for (const packageJsonPath of globSync('packages/*/package.json', { | ||
| cwd: REPOSITORY_ROOT, | ||
| absolute: true, | ||
| })) { | ||
| const pkg = readJson<{ name?: string }>(packageJsonPath); | ||
| const name = pkg.name; | ||
| if (!name || (!name.startsWith('@sentry/') && !name.startsWith('@sentry-internal/'))) { | ||
| continue; | ||
| } | ||
| const packageDir = path.dirname(packageJsonPath); | ||
| const tarball = path.join(packageDir, versionedTarballFilename(name, version)); | ||
| if (fs.existsSync(tarball)) { | ||
| names.push(name); | ||
| } | ||
| } | ||
| return names.sort(); | ||
| } | ||
| /** Stable symlink name in `packed/` (no version segment). */ | ||
| export function packedSymlinkFilename(packageName: string): string { | ||
| return `${npmPackBasename(packageName)}-packed.tgz`; | ||
| } | ||
| /** | ||
| * Versioned tarball filename produced by `npm pack` in a package directory. | ||
| */ | ||
| export function versionedTarballFilename(packageName: string, version: string): string { | ||
| return `${npmPackBasename(packageName)}-${version}.tgz`; | ||
| } | ||
| /** | ||
| * npm pack tarball basename (without version and .tgz), e.g. `@sentry/core` -> `sentry-core`. | ||
| */ | ||
| function npmPackBasename(packageName: string): string { | ||
| return packageName.replace(/^@/, '').replace(/\//g, '-'); | ||
| } | ||
| function readJson<T>(filePath: string): T { | ||
| return JSON.parse(fs.readFileSync(filePath, 'utf8')) as T; | ||
| } | ||
| function getE2eTestsPackageVersion(): string { | ||
| return readJson<{ version: string }>(path.join(E2E_TESTS_ROOT, 'package.json')).version; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { readFile, writeFile } from 'fs/promises'; | ||
| import * as path from 'path'; | ||
| import { getPublishedSentryTarballPackageNames, packedSymlinkFilename } from './packedTarballUtils'; | ||
| import { fixFileLinkDependencies } from './copyToTemp'; | ||
| /** | ||
| * For a given temp test application directory, add pnpm.overrides to pin the internal Sentry packages to the packed tarballs. | ||
| * This is used to ensure that the test application uses the correct version of the internal Sentry packages. | ||
| * @param tmpDirPath - The temporary directory path of the test application. | ||
| * @param packedDirPath - The path to the packed tarballs. | ||
| * @param packageNames - The names of the internal Sentry packages to pin to the packed tarballs. | ||
| * @returns | ||
| */ | ||
| export async function addPnpmOverrides(tmpDirPath: string, packedDirPath: string): Promise<void> { | ||
| const packageJsonPath = path.join(tmpDirPath, 'package.json'); | ||
| const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8')) as { | ||
| pnpm?: { overrides?: Record<string, string> }; | ||
| }; | ||
| const overrides: Record<string, string> = {}; | ||
| const packageNames = getPublishedSentryTarballPackageNames(); | ||
| for (const packageName of packageNames) { | ||
| overrides[packageName] = `file:${packedDirPath}/${packedSymlinkFilename(packageName)}`; | ||
| } | ||
| const fixedOverrides = packageJson.pnpm?.overrides ?? {}; | ||
| fixFileLinkDependencies(fixedOverrides); | ||
| packageJson.pnpm = { | ||
| ...packageJson.pnpm, | ||
| overrides: { | ||
| ...overrides, | ||
| ...fixedOverrides, | ||
| }, | ||
| }; | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // oxlint-disable-next-line no-console | ||
| console.log(`Added ${packageNames.length} internal Sentry packages to pnpm.overrides`); | ||
| await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2)); | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The merge order for
pnpm.overridesis incorrect. Existing overrides frompackage.jsonare applied after the new tarball overrides, causing the new ones to be ignored on key conflicts.Severity: MEDIUM
Suggested Fix
Reverse the spread operator order in the
overridesobject to be{ ...fixedOverrides, ...overrides }. This ensures that the newly generated tarball overrides will correctly take precedence over any pre-existing overrides in the test application'spackage.json.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is expected, we need to be able to override this.