Skip to content

Commit 066ebf7

Browse files
committed
test: Run E2E tests in isolated tmp directory
1 parent 3913754 commit 066ebf7

File tree

10 files changed

+96
-9
lines changed

10 files changed

+96
-9
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -920,19 +920,24 @@ jobs:
920920
env:
921921
E2E_TEST_PUBLISH_SCRIPT_NODE_VERSION: ${{ steps.versions.outputs.node }}
922922

923+
- name: Copy to temp
924+
run:
925+
yarn ci:copy-to-temp ./test-applications/${{ matrix.test-application }} ${{ runner.temp }}/test-application
926+
working-directory: dev-packages/e2e-tests
927+
923928
- name: Build E2E app
924-
working-directory: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}
929+
working-directory: ${{ runner.temp }}/test-application
925930
timeout-minutes: 7
926931
run: pnpm ${{ matrix.build-command || 'test:build' }}
927932

928933
- name: Install Playwright
929934
uses: ./.github/actions/install-playwright
930935
with:
931936
browsers: chromium
932-
cwd: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}
937+
cwd: ${{ runner.temp }}/test-application
933938

934939
- name: Run E2E test
935-
working-directory: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}
940+
working-directory: ${{ runner.temp }}/test-application
936941
timeout-minutes: 10
937942
run: pnpm test:assert
938943

@@ -941,7 +946,7 @@ jobs:
941946
if: failure()
942947
with:
943948
name: playwright-traces-job_e2e_playwright_tests-${{ matrix.test-application}}
944-
path: dev-packages/e2e-tests/test-applications/${{ matrix.test-application}}/test-results
949+
path: ${{ runner.temp }}/test-application/test-results
945950
overwrite: true
946951
retention-days: 7
947952

@@ -955,7 +960,7 @@ jobs:
955960
if: always()
956961
with:
957962
name: E2E Test Dump (${{ matrix.label || matrix.test-application }})
958-
path: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}/event-dumps
963+
path: ${{ runner.temp }}/test-application/event-dumps
959964
overwrite: true
960965
retention-days: 7
961966
if-no-files-found: ignore
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* eslint-disable no-console */
2+
3+
import { copyToTemp } from './lib/copyToTemp';
4+
5+
async function run(): Promise<void> {
6+
const originalPath = process.argv[2];
7+
const tmpDirPath = process.argv[3];
8+
9+
if (!originalPath || !tmpDirPath) {
10+
throw new Error('Original path and tmp dir path are required');
11+
}
12+
13+
console.log(`Copying ${originalPath} to ${tmpDirPath}...`);
14+
15+
await copyToTemp(originalPath, tmpDirPath);
16+
}
17+
18+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
19+
run();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { readFileSync, writeFileSync } from 'fs';
2+
import { cp } from 'fs/promises';
3+
import { join, relative, resolve } from 'path';
4+
5+
export async function copyToTemp(originalPath: string, tmpDirPath: string): Promise<void> {
6+
// copy files to tmp dir
7+
await cp(originalPath, tmpDirPath, { recursive: true });
8+
9+
fixPackageJson(tmpDirPath);
10+
}
11+
12+
function fixPackageJson(cwd: string): void {
13+
const packageJsonPath = join(cwd, 'package.json');
14+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as {
15+
devDependencies?: Record<string, string>;
16+
volta?: Record<string, unknown>;
17+
};
18+
19+
// 1. Fix file dependencies
20+
if (packageJson.devDependencies?.['@sentry-internal/test-utils']) {
21+
const relativePath = resolve(relative(cwd, join(__dirname, '../test-utils')));
22+
packageJson.devDependencies['@sentry-internal/test-utils'] = `link:${relativePath}`;
23+
}
24+
25+
// 2. Fix volta extends
26+
if (packageJson.volta?.extends === '../../package.json') {
27+
const voltaPath = resolve(relative(cwd, join(__dirname, './package.json')));
28+
packageJson.volta.extends = voltaPath;
29+
}
30+
31+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
32+
}

dev-packages/e2e-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"clean": "rimraf tmp node_modules && yarn clean:test-applications && yarn clean:pnpm",
1717
"ci:build-matrix": "ts-node ./lib/getTestMatrix.ts",
1818
"ci:build-matrix-optional": "ts-node ./lib/getTestMatrix.ts --optional=true",
19+
"ci:copy-to-temp": "ts-node ./ciCopyToTemp.ts",
1920
"clean:test-applications": "rimraf --glob test-applications/**/{node_modules,dist,build,.next,.nuxt,.sveltekit,.react-router,.astro,.output,pnpm-lock.yaml,.last-run.json,test-results}",
2021
"clean:pnpm": "pnpm store prune"
2122
},

dev-packages/e2e-tests/run.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/* eslint-disable no-console */
22
import { spawn } from 'child_process';
33
import * as dotenv from 'dotenv';
4+
import { mkdtemp, rm } from 'fs/promises';
45
import { sync as globSync } from 'glob';
5-
import { resolve } from 'path';
6+
import { tmpdir } from 'os';
7+
import { join, resolve } from 'path';
8+
import { copyToTemp } from './lib/copyToTemp';
69
import { registrySetup } from './registrySetup';
710

811
const DEFAULT_DSN = 'https://username@domain/123';
@@ -39,7 +42,7 @@ async function run(): Promise<void> {
3942
dotenv.config();
4043

4144
// Allow to run a single app only via `yarn test:run <app-name>`
42-
const appName = process.argv[2];
45+
const appName = process.argv[2] || '';
4346

4447
const dsn = process.env.E2E_TEST_DSN || DEFAULT_DSN;
4548

@@ -73,13 +76,20 @@ async function run(): Promise<void> {
7376
console.log('');
7477

7578
for (const testAppPath of testAppPaths) {
76-
const cwd = resolve('test-applications', testAppPath);
79+
const originalPath = resolve('test-applications', testAppPath);
80+
const tmpDirPath = await mkdtemp(join(tmpdir(), `sentry-e2e-tests-${appName}-`));
7781

78-
console.log(`Building ${testAppPath}...`);
82+
await copyToTemp(originalPath, tmpDirPath);
83+
const cwd = tmpDirPath;
84+
85+
console.log(`Building ${testAppPath} in ${tmpDirPath}...`);
7986
await asyncExec('pnpm test:build', { env, cwd });
8087

8188
console.log(`Testing ${testAppPath}...`);
8289
await asyncExec('pnpm test:assert', { env, cwd });
90+
91+
// clean up (although this is tmp, still nice to do)
92+
await rm(tmpDirPath, { recursive: true });
8393
}
8494
} catch (error) {
8595
console.error(error);

dev-packages/e2e-tests/test-applications/nuxt-3-dynamic-import/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"dependencies": {
1717
"@sentry/nuxt": "latest || *",
18+
"@sentry/core": "latest || *",
1819
"nuxt": "^3.14.0"
1920
},
2021
"devDependencies": {
@@ -26,5 +27,8 @@
2627
"nitropack": "~2.9.7",
2728
"ofetch": "^1.4.0"
2829
}
30+
},
31+
"volta": {
32+
"extends": "../../package.json"
2933
}
3034
}

dev-packages/e2e-tests/test-applications/nuxt-3-min/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@sentry/nuxt": "latest || *",
20+
"@sentry/core": "latest || *",
2021
"nuxt": "3.7.0"
2122
},
2223
"devDependencies": {
@@ -26,5 +27,8 @@
2627
"overrides": {
2728
"nitropack": "2.10.0",
2829
"ofetch": "1.4.0"
30+
},
31+
"volta": {
32+
"extends": "../../package.json"
2933
}
3034
}

dev-packages/e2e-tests/test-applications/nuxt-3-top-level-import/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
},
1616
"dependencies": {
1717
"@sentry/nuxt": "latest || *",
18+
"@sentry/core": "latest || *",
1819
"nuxt": "^3.14.0"
1920
},
2021
"devDependencies": {
2122
"@playwright/test": "~1.50.0",
2223
"@sentry-internal/test-utils": "link:../../../test-utils"
24+
},
25+
"volta": {
26+
"extends": "../../package.json"
2327
}
2428
}

dev-packages/e2e-tests/test-applications/nuxt-3/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@sentry/nuxt": "latest || *",
20+
"@sentry/core": "latest || *",
2021
"nuxt": "^3.14.0"
2122
},
2223
"devDependencies": {
@@ -30,5 +31,8 @@
3031
"label": "nuxt-3 (canary)"
3132
}
3233
]
34+
},
35+
"volta": {
36+
"extends": "../../package.json"
3337
}
3438
}

dev-packages/e2e-tests/test-applications/nuxt-4/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dependencies": {
1919
"@pinia/nuxt": "^0.5.5",
2020
"@sentry/nuxt": "latest || *",
21+
"@sentry/core": "latest || *",
2122
"nuxt": "^4.0.0-alpha.4"
2223
},
2324
"devDependencies": {
@@ -27,6 +28,9 @@
2728
"overrides": {
2829
"@vercel/nft": "0.27.4"
2930
},
31+
"volta": {
32+
"extends": "../../package.json"
33+
},
3034
"sentryTest": {
3135
"optionalVariants": [
3236
{

0 commit comments

Comments
 (0)