From 6efac13b55d30103f8d75a5bb9f7ec0e4e0ab8c2 Mon Sep 17 00:00:00 2001 From: cod1k Date: Fri, 11 Jul 2025 16:52:21 +0300 Subject: [PATCH 1/5] Fix typo in test log message in e2e-tests script Corrected a spelling error in the console log output from "Runnings tests" to "Running tests" for clarity. This change ensures proper messaging during test execution. --- dev-packages/e2e-tests/run.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-packages/e2e-tests/run.ts b/dev-packages/e2e-tests/run.ts index 7b6efb2dd13b..ad004a41800f 100644 --- a/dev-packages/e2e-tests/run.ts +++ b/dev-packages/e2e-tests/run.ts @@ -73,7 +73,7 @@ async function run(): Promise { const testAppPaths = appName ? [appName.trim()] : globSync('*', { cwd: `${__dirname}/test-applications/` }); - console.log(`Runnings tests for: ${testAppPaths.join(', ')}`); + console.log(`Running tests for: ${testAppPaths.join(', ')}`); console.log(''); for (const testAppPath of testAppPaths) { From 51277cefe93c7006fe24530d564cb6cf02282782 Mon Sep 17 00:00:00 2001 From: cod1k Date: Fri, 11 Jul 2025 16:52:43 +0300 Subject: [PATCH 2/5] Remove redundant command and enhance file copy with ignore logic Removed the `clean:test-applications` command from e2e test setup as it is unnecessary. Improved the `copyToTemp` function by integrating `.gitignore` and `node_modules` filtering to exclude unwanted files during the copy process. This ensures a cleaner and more efficient temporary workspace. --- dev-packages/e2e-tests/run.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/dev-packages/e2e-tests/run.ts b/dev-packages/e2e-tests/run.ts index ad004a41800f..9e53291a8083 100644 --- a/dev-packages/e2e-tests/run.ts +++ b/dev-packages/e2e-tests/run.ts @@ -68,7 +68,6 @@ async function run(): Promise { registrySetup(); } - await asyncExec('pnpm clean:test-applications', { env, cwd: __dirname }); await asyncExec('pnpm cache delete "@sentry/*"', { env, cwd: __dirname }); const testAppPaths = appName ? [appName.trim()] : globSync('*', { cwd: `${__dirname}/test-applications/` }); From 5dc6dce14b2623218a693de849820d9de239da60 Mon Sep 17 00:00:00 2001 From: cod1k Date: Fri, 11 Jul 2025 16:54:31 +0300 Subject: [PATCH 3/5] Filter files in `copyToTemp` using .gitignore rules Updated the `copyToTemp` function to respect ignore patterns defined in `.gitignore` files and exclude unwanted files like `node_modules`, `dist`, and `build`. This ensures that only relevant files are copied to the temporary directory, improving efficiency and alignment with project standards. --- dev-packages/e2e-tests/lib/copyToTemp.ts | 27 +++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/dev-packages/e2e-tests/lib/copyToTemp.ts b/dev-packages/e2e-tests/lib/copyToTemp.ts index d6667978b924..d8ff8f189098 100644 --- a/dev-packages/e2e-tests/lib/copyToTemp.ts +++ b/dev-packages/e2e-tests/lib/copyToTemp.ts @@ -1,11 +1,32 @@ /* eslint-disable no-console */ -import { readFileSync, writeFileSync } from 'fs'; +import { existsSync, readFileSync, writeFileSync } from 'fs'; import { cp } from 'fs/promises'; -import { join } from 'path'; +import ignore from 'ignore'; +import { dirname, join, relative } from 'path'; export async function copyToTemp(originalPath: string, tmpDirPath: string): Promise { // copy files to tmp dir - await cp(originalPath, tmpDirPath, { recursive: true }); + const ig = ignore(); + const ignoreFileDirs = [ + originalPath, + dirname(__dirname) + ] + ig.add(['.gitignore', 'node_modules', 'dist', 'build']); + for(const dir of ignoreFileDirs) { + const ignore_file = join(dir, '.gitignore'); + if (existsSync(ignore_file)) { + ig.add(readFileSync(ignore_file, 'utf8')); + } + } + + await cp(originalPath, tmpDirPath, { + recursive: true, + filter: src => { + const relPath = relative(originalPath, src); + if (!relPath) return true; + return !ig.ignores(relPath); + }, + }); fixPackageJson(tmpDirPath); } From af78dda8edaf60cf62065922ae6dbb3ce70fc214 Mon Sep 17 00:00:00 2001 From: cod1k Date: Fri, 11 Jul 2025 16:55:28 +0300 Subject: [PATCH 4/5] Refactor asyncExec to improve process output handling Replace manual stdout/stderr piping with predefined stdio settings for concise and reliable output handling. Also, update the asyncExec function signature to use a stricter SpawnOptions type with omitted 'shell' and 'stdio' properties. --- dev-packages/e2e-tests/run.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/dev-packages/e2e-tests/run.ts b/dev-packages/e2e-tests/run.ts index 9e53291a8083..83e9e816f4e3 100644 --- a/dev-packages/e2e-tests/run.ts +++ b/dev-packages/e2e-tests/run.ts @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import { spawn } from 'child_process'; +import { type SpawnOptions, spawn } from 'child_process'; import * as dotenv from 'dotenv'; import { mkdtemp, rm } from 'fs/promises'; import { sync as globSync } from 'glob'; @@ -12,17 +12,9 @@ const DEFAULT_DSN = 'https://username@domain/123'; const DEFAULT_SENTRY_ORG_SLUG = 'sentry-javascript-sdks'; const DEFAULT_SENTRY_PROJECT = 'sentry-javascript-e2e-tests'; -function asyncExec(command: string, options: { env: Record; cwd: string }): Promise { +function asyncExec(command: string, options: Omit): Promise { return new Promise((resolve, reject) => { - const process = spawn(command, { ...options, shell: true }); - - process.stdout.on('data', data => { - console.log(`${data}`); - }); - - process.stderr.on('data', data => { - console.error(`${data}`); - }); + const process = spawn(command, { ...options, shell: true, stdio: ['ignore', 'inherit', 'inherit'] }); process.on('error', error => { reject(error); From 0420ec52d5b7a9ec0403a6b54a17c46e59577d70 Mon Sep 17 00:00:00 2001 From: cod1k Date: Fri, 11 Jul 2025 16:56:17 +0300 Subject: [PATCH 5/5] Refactor e2e test cleanup and temporary directory handling Replaced inline `rimraf` calls with a dedicated `clean.ts` script for better maintainability. Standardized temporary directory management by introducing a consistent prefix and leveraging `path.basename` for clarity. These changes improve code organization and simplify future modifications. --- dev-packages/e2e-tests/clean.ts | 7 +++++++ dev-packages/e2e-tests/package.json | 2 +- dev-packages/e2e-tests/run.ts | 10 +++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 dev-packages/e2e-tests/clean.ts diff --git a/dev-packages/e2e-tests/clean.ts b/dev-packages/e2e-tests/clean.ts new file mode 100644 index 000000000000..b0fd97bceec7 --- /dev/null +++ b/dev-packages/e2e-tests/clean.ts @@ -0,0 +1,7 @@ +import { tmpdir } from 'os'; +import { join } from 'path'; +import { rimrafSync } from 'rimraf'; + +const buildDir = join(tmpdir(), 'sentry-e2e-tests-*'); + +process.exit(Number(!rimrafSync([...process.argv.slice(2), buildDir], { glob: true }))); diff --git a/dev-packages/e2e-tests/package.json b/dev-packages/e2e-tests/package.json index 2b8ff4b260ed..3046dc636168 100644 --- a/dev-packages/e2e-tests/package.json +++ b/dev-packages/e2e-tests/package.json @@ -13,7 +13,7 @@ "test:validate-test-app-setups": "ts-node validate-test-app-setups.ts", "test:prepare": "ts-node prepare.ts", "test:validate": "run-s test:validate-configuration test:validate-test-app-setups", - "clean": "rimraf tmp node_modules && yarn clean:test-applications && yarn clean:pnpm", + "clean": "ts-node ./clean.ts node_modules && yarn clean:test-applications && yarn clean:pnpm", "ci:build-matrix": "ts-node ./lib/getTestMatrix.ts", "ci:build-matrix-optional": "ts-node ./lib/getTestMatrix.ts --optional=true", "ci:copy-to-temp": "ts-node ./ciCopyToTemp.ts", diff --git a/dev-packages/e2e-tests/run.ts b/dev-packages/e2e-tests/run.ts index 83e9e816f4e3..c6b437af69aa 100644 --- a/dev-packages/e2e-tests/run.ts +++ b/dev-packages/e2e-tests/run.ts @@ -4,7 +4,8 @@ import * as dotenv from 'dotenv'; import { mkdtemp, rm } from 'fs/promises'; import { sync as globSync } from 'glob'; import { tmpdir } from 'os'; -import { join, resolve } from 'path'; +import { basename, join, resolve } from 'path'; +import { rimraf } from 'rimraf'; import { copyToTemp } from './lib/copyToTemp'; import { registrySetup } from './registrySetup'; @@ -56,6 +57,9 @@ async function run(): Promise { console.log('Cleaning test-applications...'); console.log(''); + const tmpPrefix = join(tmpdir(), 'sentry-e2e-tests-') + await rimraf(`${tmpPrefix}*`, { glob: true }); + if (!process.env.SKIP_REGISTRY) { registrySetup(); } @@ -68,8 +72,8 @@ async function run(): Promise { console.log(''); for (const testAppPath of testAppPaths) { - const originalPath = resolve('test-applications', testAppPath); - const tmpDirPath = await mkdtemp(join(tmpdir(), `sentry-e2e-tests-${appName}-`)); + const originalPath = resolve(__dirname, 'test-applications', testAppPath); + const tmpDirPath = await mkdtemp(`${tmpPrefix}${basename(testAppPath)}-`); await copyToTemp(originalPath, tmpDirPath); const cwd = tmpDirPath;