Repository navigation
Expand file tree
/
Copy pathweekly-flaky-tests.test.mjs
More file actions
99 lines (88 loc) · 3.14 KB
/
Copy pathweekly-flaky-tests.test.mjs
File metadata and controls
99 lines (88 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { describe, expect, it, vi } from 'vitest';
import { collectReport } from './weekly-flaky-tests.mjs';
const REPOSITORY_URL = 'https://github.com/getsentry/sentry-javascript';
const context = { repo: { owner: 'getsentry', repo: 'sentry-javascript' }, serverUrl: 'https://github.com', runId: 99 };
const now = new Date('2026-11-16T06:00:00Z');
const jobTimeout = {
annotation_level: 'failure',
path: '.github',
message: 'The job has exceeded the maximum execution time of 15m0s',
};
const processExit = { annotation_level: 'failure', path: '.github', message: 'Process completed with exit code 1.' };
function job(id, name, conclusion, steps) {
return {
id,
name,
conclusion,
check_run_url: `https://api.github.com/repos/getsentry/sentry-javascript/check-runs/${id}`,
html_url: `${REPOSITORY_URL}/actions/runs/7/job/${id}`,
steps: steps.map(([stepName, stepConclusion]) => ({ name: stepName, conclusion: stepConclusion })),
};
}
function collect(jobs, annotationsByJob) {
const github = {
rest: {
actions: { listWorkflowRuns: vi.fn(), listJobsForWorkflowRun: vi.fn() },
checks: { listAnnotations: vi.fn() },
},
paginate: vi.fn(async (method, params) => {
if (method === github.rest.actions.listWorkflowRuns) {
return [{ id: 7, event: 'push', conclusion: 'failure', run_attempt: 1 }];
}
if (method === github.rest.actions.listJobsForWorkflowRun) {
return jobs;
}
return annotationsByJob[params.check_run_id] ?? [];
}),
};
return collectReport({ github, context, core: { info: vi.fn() }, now });
}
describe('collectReport', () => {
it('reports the failed step of a job that failed outside a test', async () => {
const report = await collect(
[
job(11, 'Bun Unit Tests', 'failure', [
['Set up Bun', 'failure'],
['Run tests', 'skipped'],
]),
],
{ 11: [processExit] },
);
expect(report.steps).toEqual([
{
family: 'Bun Unit Tests',
name: 'Set up Bun',
outcome: 'failed',
runs: new Map([[7, `${REPOSITORY_URL}/actions/runs/7/job/11`]]),
},
]);
expect(report.tests).toEqual([]);
});
it('reports a job that reached its time limit as timed out', async () => {
const report = await collect(
[
job(12, 'Playwright esm chromium Tests', 'cancelled', [
['Restore caches', 'success'],
['Install Playwright', 'cancelled'],
['Run Playwright tests', 'cancelled'],
]),
],
{ 12: [jobTimeout] },
);
expect(report.steps).toEqual([
{
family: 'Playwright Tests',
name: 'Install Playwright',
outcome: 'timed out',
runs: new Map([[7, `${REPOSITORY_URL}/actions/runs/7/job/12`]]),
},
]);
});
it('ignores a cancelled job that did not time out', async () => {
const report = await collect([job(13, 'Lint', 'cancelled', [['Lint source files', 'cancelled']])], {
13: [{ annotation_level: 'failure', path: '.github', message: 'The operation was canceled.' }],
});
expect(report.steps).toEqual([]);
expect(report.failedJobs).toBe(0);
});
});