Skip to content

Commit f8c80f7

Browse files
authored
ci(e2e): Only run changed E2E tests (#17077)
This pr changes the detection logic for the e2e tests directory. Before we always ran every test whenever something changed in this dir. With this change we check for changed files in the test apps and only run all tests if shared code has been changed.
1 parent c1991d6 commit f8c80f7

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

dev-packages/e2e-tests/lib/getTestMatrix.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,27 @@ function getAffectedTestApplications(
143143
.map(line => line.trim())
144144
.filter(Boolean);
145145

146-
// If something in e2e tests themselves are changed, just run everything
146+
// If something in e2e tests themselves are changed, check if only test applications were changed
147147
if (affectedProjects.includes('@sentry-internal/e2e-tests')) {
148+
try {
149+
const changedTestApps = getChangedTestApps(base, head);
150+
151+
// Shared code was changed, run all tests
152+
if (changedTestApps === false) {
153+
return testApplications;
154+
}
155+
156+
// Only test applications that were changed, run selectively
157+
if (changedTestApps.size > 0) {
158+
return testApplications.filter(testApp => changedTestApps.has(testApp));
159+
}
160+
} catch (error) {
161+
// eslint-disable-next-line no-console
162+
console.error('Failed to get changed files, running all tests:', error);
163+
return testApplications;
164+
}
165+
166+
// Fall back to running all tests
148167
return testApplications;
149168
}
150169

@@ -153,3 +172,32 @@ function getAffectedTestApplications(
153172
return sentryDependencies.some(dep => affectedProjects.includes(dep));
154173
});
155174
}
175+
176+
function getChangedTestApps(base: string, head?: string): false | Set<string> {
177+
const changedFiles = execSync(`git diff --name-only ${base}${head ? `..${head}` : ''} -- dev-packages/e2e-tests/`, {
178+
encoding: 'utf-8',
179+
})
180+
.toString()
181+
.split('\n')
182+
.map(line => line.trim())
183+
.filter(Boolean);
184+
185+
const changedTestApps: Set<string> = new Set();
186+
const testAppsPrefix = 'dev-packages/e2e-tests/test-applications/';
187+
188+
for (const file of changedFiles) {
189+
if (!file.startsWith(testAppsPrefix)) {
190+
// Shared code change - need to run all tests
191+
return false;
192+
}
193+
194+
const pathAfterPrefix = file.slice(testAppsPrefix.length);
195+
const slashIndex = pathAfterPrefix.indexOf('/');
196+
197+
if (slashIndex > 0) {
198+
changedTestApps.add(pathAfterPrefix.slice(0, slashIndex));
199+
}
200+
}
201+
202+
return changedTestApps;
203+
}

0 commit comments

Comments
 (0)