Skip to content

test(e2e): Run e2e selectively #17077

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion dev-packages/e2e-tests/lib/getTestMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,27 @@ function getAffectedTestApplications(
.map(line => line.trim())
.filter(Boolean);

// If something in e2e tests themselves are changed, just run everything
// If something in e2e tests themselves are changed, check if only test applications were changed
if (affectedProjects.includes('@sentry-internal/e2e-tests')) {
try {
const changedTestApps = getChangedTestApps(base, head);

// Shared code was changed, run all tests
if (changedTestApps === false) {
return testApplications;
}

// Only test applications that were changed, run selectively
if (changedTestApps.size > 0) {
return testApplications.filter(testApp => changedTestApps.has(testApp));
}
} catch (error) {
// eslint-disable-next-line no-console
console.error('Failed to get changed files, running all tests:', error);
return testApplications;
}

// Fall back to running all tests
return testApplications;
}

Expand All @@ -153,3 +172,32 @@ function getAffectedTestApplications(
return sentryDependencies.some(dep => affectedProjects.includes(dep));
});
}

function getChangedTestApps(base: string, head?: string): false | Set<string> {
const changedFiles = execSync(`git diff --name-only ${base}${head ? `..${head}` : ''} -- dev-packages/e2e-tests/`, {
encoding: 'utf-8',
})
.toString()
.split('\n')
.map(line => line.trim())
.filter(Boolean);

const changedTestApps: Set<string> = new Set();
const testAppsPrefix = 'dev-packages/e2e-tests/test-applications/';

for (const file of changedFiles) {
if (!file.startsWith(testAppsPrefix)) {
// Shared code change - need to run all tests
return false;
}

const pathAfterPrefix = file.slice(testAppsPrefix.length);
const slashIndex = pathAfterPrefix.indexOf('/');

if (slashIndex > 0) {
changedTestApps.add(pathAfterPrefix.slice(0, slashIndex));
}
}

return changedTestApps;
}
Loading