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/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); } 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 7b6efb2dd13b..c6b437af69aa 100644 --- a/dev-packages/e2e-tests/run.ts +++ b/dev-packages/e2e-tests/run.ts @@ -1,10 +1,11 @@ /* 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'; 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'; @@ -12,17 +13,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); @@ -64,21 +57,23 @@ 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(); } - 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/` }); - console.log(`Runnings tests for: ${testAppPaths.join(', ')}`); + console.log(`Running tests for: ${testAppPaths.join(', ')}`); 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;