@@ -6,35 +6,6 @@ import {Octokit} from '@octokit/core'
66import { throttling } from '@octokit/plugin-throttling'
77const OctokitWithThrottling = Octokit . plugin ( throttling )
88
9- const WAIT_FOR_PULL_REQUESTS = ! ! process . env . WAIT_FOR_PULL_REQUESTS
10- const POLL_INTERVAL_MS = 30_000 // 30 seconds
11- const POLL_TIMEOUT_MS = 15 * 60 * 1000 // 15 minutes
12-
13- /**
14- * Repeatedly calls `fn` until `predicate(result)` returns `true`, or until the timeout is exceeded.
15- * Errors thrown by `fn` (e.g. HTTP 404) are swallowed while polling continues.
16- */
17- async function pollUntil < T > (
18- fn : ( ) => Promise < T > ,
19- predicate : ( result : T ) => boolean ,
20- { intervalMs, timeoutMs} : { intervalMs : number ; timeoutMs : number } ,
21- ) : Promise < T > {
22- const deadline = Date . now ( ) + timeoutMs
23- let lastError : unknown
24- while ( true ) {
25- try {
26- const result = await fn ( )
27- if ( predicate ( result ) ) return result
28- } catch ( error ) {
29- lastError = error
30- }
31- if ( Date . now ( ) >= deadline ) {
32- throw lastError ?? new Error ( `Timed out after ${ timeoutMs } ms waiting for condition` )
33- }
34- await new Promise ( resolve => setTimeout ( resolve , intervalMs ) )
35- }
36- }
37-
389function createOctokit ( ) : InstanceType < typeof OctokitWithThrottling > {
3910 return new OctokitWithThrottling ( {
4011 auth : process . env . GITHUB_TOKEN ,
@@ -67,13 +38,10 @@ describe('site-with-errors', () => {
6738 } )
6839
6940 it ( 'cache has expected results' , ( ) => {
70- const actual = results . map ( ( { issue : { url : issueUrl } , pullRequest , findings} ) => {
41+ const actual = results . map ( ( { issue : { url : issueUrl } , findings} ) => {
7142 const { problemUrl, solutionLong, screenshotId, ...finding } = findings [ 0 ]
7243 // Check volatile fields for existence only
7344 expect ( issueUrl ) . toBeDefined ( )
74- if ( WAIT_FOR_PULL_REQUESTS ) {
75- expect ( pullRequest ?. url ) . toBeDefined ( )
76- }
7745 expect ( problemUrl ) . toBeDefined ( )
7846 expect ( solutionLong ) . toBeDefined ( )
7947 // Check `problemUrl`, ignoring axe version
@@ -195,42 +163,4 @@ describe('site-with-errors', () => {
195163 }
196164 } )
197165 } )
198-
199- describe . runIf ( ! ! process . env . GITHUB_TOKEN && WAIT_FOR_PULL_REQUESTS ) ( 'pull requests' , ( ) => {
200- let pullRequests : Endpoints [ 'GET /repos/{owner}/{repo}/pulls/{pull_number}' ] [ 'response' ] [ 'data' ] [ ]
201-
202- beforeAll ( async ( ) => {
203- const octokit = createOctokit ( )
204- pullRequests = await Promise . all (
205- results . map ( async ( { pullRequest : { url : pullRequestUrl } } ) => {
206- expect ( pullRequestUrl ) . toBeDefined ( )
207- const { owner, repo, pullNumber} =
208- / h t t p s : \/ \/ g i t h u b \. c o m \/ (?< owner > [ ^ / ] + ) \/ (?< repo > [ ^ / ] + ) \/ p u l l \/ (?< pullNumber > \d + ) / . exec (
209- pullRequestUrl ! ,
210- ) ! . groups !
211- return pollUntil (
212- async ( ) => {
213- const { data} = await octokit . request ( 'GET /repos/{owner}/{repo}/pulls/{pull_number}' , {
214- owner,
215- repo,
216- pull_number : parseInt ( pullNumber , 10 ) ,
217- } )
218- return data
219- } ,
220- pr => pr . state === 'open' ,
221- { intervalMs : POLL_INTERVAL_MS , timeoutMs : POLL_TIMEOUT_MS } ,
222- )
223- } ) ,
224- )
225- } , POLL_TIMEOUT_MS + 60_000 )
226-
227- it ( 'pull requests exist and have expected author, state, and assignee' , async ( ) => {
228- for ( const pullRequest of pullRequests ) {
229- expect ( pullRequest . user . login ) . toBe ( 'Copilot' )
230- expect ( pullRequest . state ) . toBe ( 'open' )
231- expect ( pullRequest . assignees ) . toBeDefined ( )
232- expect ( pullRequest . assignees ! . some ( a => a . login === 'Copilot' ) ) . toBe ( true )
233- }
234- } )
235- } )
236166} )
0 commit comments