@@ -5,117 +5,357 @@ import select from 'select-dom';
5
5
import reservedNames from 'github-reserved-names/reserved-names.json' ;
6
6
import { getUsername , getCleanPathname , getRepoPath , getOwnerAndRepo } from './utils' ;
7
7
8
+ const skip = 'skip' ; // To be used only to skip tests of combined functions, i.e. isPageA() || isPageB()
9
+ const domBased = 'skip' ; // To be used only to skip tests that are DOM-based rather than URL-based
10
+
8
11
export const is404 = ( ) : boolean => document . title === 'Page not found · GitHub' ;
12
+ export const is404Test = domBased ; // They're specified in page-detect.ts
9
13
10
14
export const is500 = ( ) : boolean => document . title === 'Server Error · GitHub' || document . title === 'Unicorn! · GitHub' ;
15
+ export const is500Test = domBased ; // They're specified in page-detect.ts
11
16
12
17
export const isBlame = ( ) : boolean => / ^ b l a m e \/ / . test ( getRepoPath ( ) ! ) ;
18
+ export const isBlameTest = [
19
+ 'https://github.com/sindresorhus/refined-github/blame/master/package.json'
20
+ ] ;
13
21
14
22
export const isCommit = ( ) : boolean => isSingleCommit ( ) || isPRCommit ( ) ;
23
+ export const isCommitTest = [
24
+ 'https://github.com/sindresorhus/refined-github/commit/5b614b9035f2035b839f48b4db7bd5c3298d526f' ,
25
+ 'https://github.com/sindresorhus/refined-github/commit/5b614' ,
26
+ 'https://github.com/sindresorhus/refined-github/pull/148/commits/0019603b83bd97c2f7ef240969f49e6126c5ec85' ,
27
+ 'https://github.com/sindresorhus/refined-github/pull/148/commits/00196'
28
+ ] ;
15
29
16
30
export const isCommitList = ( ) : boolean => / ^ c o m m i t s \/ / . test ( getRepoPath ( ) ! ) ;
31
+ export const isCommitListTest = [
32
+ 'https://github.com/sindresorhus/refined-github/commits/master?page=2' ,
33
+ 'https://github.com/sindresorhus/refined-github/commits/test-branch' ,
34
+ 'https://github.com/sindresorhus/refined-github/commits/0.13.0' ,
35
+ 'https://github.com/sindresorhus/refined-github/commits/230c2' ,
36
+ 'https://github.com/sindresorhus/refined-github/commits/230c2935fc5aea9a681174ddbeba6255ca040d63'
37
+ ] ;
17
38
18
39
export const isCompare = ( ) : boolean => / ^ c o m p a r e / . test ( getRepoPath ( ) ! ) ;
40
+ export const isCompareTest = [
41
+ 'https://github.com/sindresorhus/refined-github/compare' ,
42
+ 'https://github.com/sindresorhus/refined-github/compare/' ,
43
+ 'https://github.com/sindresorhus/refined-github/compare/master...branch-name' ,
44
+ 'https://github.com/sindresorhus/refined-github/compare/master...branch-name?quick_pull=1' ,
45
+ 'https://github.com/sindresorhus/refined-github/compare/branch-1...branch-2?quick_pull=1' ,
46
+ 'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1'
47
+ ] ;
19
48
20
49
export const isDashboard = ( ) : boolean => ! isGist ( ) && / ^ $ | ^ ( o r g s [ / ] [ ^ / ] + [ / ] ) ? d a s h b o a r d ( [ / ] | $ ) / . test ( getCleanPathname ( ) ) ;
50
+ export const isDashboardTest = [
51
+ 'https://github.com/' ,
52
+ 'https://github.com' ,
53
+ 'https://github.com/orgs/test/dashboard' ,
54
+ 'https://github.com/dashboard/index/2' ,
55
+ 'https://github.com/dashboard' ,
56
+ 'https://github.com/orgs/edit/dashboard' ,
57
+ 'https://github.big-corp.com/' ,
58
+ 'https://not-github.com/' ,
59
+ 'https://my-little-hub.com/'
60
+ ] ;
21
61
22
62
export const isEnterprise = ( ) : boolean => location . hostname !== 'github.com' && location . hostname !== 'gist.github.com' ;
23
-
24
- export const isGist = ( ) : boolean => location . hostname . startsWith ( 'gist.' ) || location . pathname . startsWith ( 'gist/' ) ;
63
+ export const isEnterpriseTest = [
64
+ 'https://github.big-corp.com/' ,
65
+ 'https://not-github.com/' ,
66
+ 'https://my-little-hub.com/' ,
67
+ 'https://my-little-hub.com/gist'
68
+ ] ;
69
+
70
+ export const isGist = ( ) : boolean => location . hostname . startsWith ( 'gist.' ) || location . pathname . split ( '/' , 2 ) [ 1 ] === 'gist' ;
71
+ export const isGistTest = [
72
+ 'https://gist.github.com' ,
73
+ 'http://gist.github.com' ,
74
+ 'https://gist.github.com/sindresorhus/0ea3c2845718a0a0f0beb579ff14f064' ,
75
+ 'https://my-little-hub.com/gist'
76
+ ] ;
25
77
26
78
export const isGlobalDiscussionList = ( ) : boolean => [ 'issues' , 'pulls' ] . includes ( location . pathname . split ( '/' , 2 ) [ 1 ] ) ;
79
+ export const isGlobalDiscussionListTest = [
80
+ 'https://github.com/issues' ,
81
+ 'https://github.com/issues?q=is%3Apr+is%3Aopen' ,
82
+ 'https://github.com/issues/assigned' ,
83
+ 'https://github.com/issues/mentioned' ,
84
+ 'https://github.com/pulls' ,
85
+ 'https://github.com/pulls?q=issues' ,
86
+ 'https://github.com/pulls/assigned' ,
87
+ 'https://github.com/pulls/mentioned' ,
88
+ 'https://github.com/pulls/review-requested'
89
+ ] ;
27
90
28
91
export const isGlobalSearchResults = ( ) : boolean => location . pathname === '/search' && new URLSearchParams ( location . search ) . get ( 'q' ) !== null ;
92
+ export const isGlobalSearchResultsTest = [
93
+ 'https://github.com/search?q=refined-github&ref=opensearch'
94
+ ] ;
29
95
30
96
export const isIssue = ( ) : boolean => / ^ i s s u e s \/ \d + / . test ( getRepoPath ( ) ! ) ;
97
+ export const isIssueTest = [
98
+ 'https://github.com/sindresorhus/refined-github/issues/146'
99
+ ] ;
31
100
32
101
export const isDiscussionList = ( ) : boolean => isGlobalDiscussionList ( ) || isRepoDiscussionList ( ) ;
102
+ export const isDiscussionListTest = skip ;
33
103
34
- export const isLabel = ( ) : boolean => / ^ l a b e l s \/ \w + / . test ( getRepoPath ( ) ! ) ;
35
-
36
- export const isLabelList = ( ) : boolean => / ^ l a b e l s \/ ? ( ( (? = \? ) .* ) | $ ) / . test ( getRepoPath ( ) ! ) ;
104
+ export const isLabelList = ( ) : boolean => getRepoPath ( ) === 'labels' ;
105
+ export const isLabelListTest = [
106
+ 'https://github.com/sindresorhus/refined-github/labels'
107
+ ] ;
37
108
38
109
export const isMilestone = ( ) : boolean => / ^ m i l e s t o n e \/ \d + / . test ( getRepoPath ( ) ! ) ;
110
+ export const isMilestoneTest = [
111
+ 'https://github.com/sindresorhus/refined-github/milestone/12'
112
+ ] ;
39
113
40
114
export const isMilestoneList = ( ) : boolean => getRepoPath ( ) === 'milestones' ;
115
+ export const isMilestoneListTest = [
116
+ 'https://github.com/sindresorhus/refined-github/milestones'
117
+ ] ;
41
118
42
119
export const isNewIssue = ( ) : boolean => / ^ i s s u e s \/ n e w / . test ( getRepoPath ( ) ! ) ;
120
+ export const isNewIssueTest = [
121
+ 'https://github.com/sindresorhus/refined-github/issues/new'
122
+ ] ;
43
123
44
124
export const isNewRelease = ( ) : boolean => / ^ r e l e a s e s \/ n e w / . test ( getRepoPath ( ) ! ) ;
125
+ export const isNewReleaseTest = [
126
+ 'https://github.com/sindresorhus/refined-github/releases/new'
127
+ ] ;
45
128
46
129
export const isNotifications = ( ) : boolean => / ^ ( [ ^ / ] + [ / ] [ ^ / ] + \/ ) ? n o t i f i c a t i o n s / . test ( getCleanPathname ( ) ) ;
130
+ export const isNotificationsTest = [
131
+ 'https://github.com/notifications' ,
132
+ 'https://github.com/notifications/participating' ,
133
+ 'https://github.com/sindresorhus/notifications/notifications' ,
134
+ 'https://github.com/notifications?all=1'
135
+ ] ;
47
136
48
137
export const isOrganizationProfile = ( ) : boolean => select . exists ( '.orghead' ) ;
138
+ export const isOrganizationProfileTest = domBased ;
49
139
50
140
export const isOrganizationDiscussion = ( ) : boolean => / ^ o r g s \/ [ ^ / ] + \/ t e a m s \/ [ ^ / ] + ( $ | \/ d i s c u s s i o n s ) / . test ( getCleanPathname ( ) ) ;
141
+ export const isOrganizationDiscussionTest = [
142
+ 'https://github.com/orgs/refined-github/teams/core-team/discussions?pinned=1' ,
143
+ 'https://github.com/orgs/refined-github/teams/core-team/discussions/1' ,
144
+ 'https://github.com/orgs/refined-github/teams/core-team'
145
+ ] ;
51
146
52
147
export const isOwnUserProfile = ( ) : boolean => getCleanPathname ( ) === getUsername ( ) ;
148
+ export const isOwnUserProfileTest = domBased ;
53
149
54
150
// If there's a Report Abuse link, we're not part of the org
55
151
export const isOwnOrganizationProfile = ( ) : boolean => isOrganizationProfile ( ) && ! select . exists ( '[href*="contact/report-abuse?report="]' ) ;
152
+ export const isOwnOrganizationProfileTest = domBased ;
56
153
57
154
export const isProject = ( ) : boolean => / ^ p r o j e c t s \/ \d + / . test ( getRepoPath ( ) ! ) ;
155
+ export const isProjectTest = [
156
+ 'https://github.com/sindresorhus/refined-github/projects/3'
157
+ ] ;
58
158
59
159
export const isPR = ( ) : boolean => / ^ p u l l \/ \d + / . test ( getRepoPath ( ) ! ) ;
160
+ export const isPRTest = [
161
+ 'https://github.com/sindresorhus/refined-github/pull/148' ,
162
+ 'https://github.com/sindresorhus/refined-github/pull/148/files' ,
163
+ 'https://github.com/sindresorhus/refined-github/pull/148/conflicts' ,
164
+ 'https://github.com/sindresorhus/refined-github/pull/148/commits/00196' ,
165
+ 'https://github.com/sindresorhus/refined-github/pull/148/commits/0019603b83bd97c2f7ef240969f49e6126c5ec85'
166
+ ] ;
60
167
61
168
export const isConflict = ( ) : boolean => / ^ p u l l \/ \d + \/ c o n f l i c t s / . test ( getRepoPath ( ) ! ) ;
169
+ export const isConflictTest = [
170
+ 'https://github.com/sindresorhus/refined-github/pull/148/conflicts'
171
+ ] ;
62
172
63
173
export const isPRList = ( ) : boolean => location . pathname === '/pulls' || getRepoPath ( ) === 'pulls' ;
174
+ export const isPRListTest = [
175
+ 'https://github.com/pulls' ,
176
+ 'https://github.com/pulls?q=issues' ,
177
+ 'https://github.com/sindresorhus/refined-github/pulls' ,
178
+ 'https://github.com/sindresorhus/refined-github/pulls/' ,
179
+ 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr' ,
180
+ 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed'
181
+ ] ;
64
182
65
183
export const isPRCommit = ( ) : boolean => / ^ p u l l \/ \d + \/ c o m m i t s \/ [ 0 - 9 a - f ] { 5 , 40 } / . test ( getRepoPath ( ) ! ) ;
184
+ export const isPRCommitTest = [
185
+ 'https://github.com/sindresorhus/refined-github/pull/148/commits/0019603b83bd97c2f7ef240969f49e6126c5ec85' ,
186
+ 'https://github.com/sindresorhus/refined-github/pull/148/commits/00196'
187
+ ] ;
66
188
67
189
export const isPRConversation = ( ) : boolean => / ^ p u l l \/ \d + $ / . test ( getRepoPath ( ) ! ) ;
190
+ export const isPRConversationTest = [
191
+ 'https://github.com/sindresorhus/refined-github/pull/148'
192
+ ] ;
68
193
69
194
export const isPRFiles = ( ) : boolean => / ^ p u l l \/ \d + \/ f i l e s / . test ( getRepoPath ( ) ! ) ;
195
+ export const isPRFilesTest = [
196
+ 'https://github.com/sindresorhus/refined-github/pull/148/files'
197
+ ] ;
70
198
71
199
export const isQuickPR = ( ) : boolean => isCompare ( ) && / [ ? & ] q u i c k _ p u l l = 1 ( & | $ ) / . test ( location . search ) ;
72
-
73
- export const isReleasesOrTags = ( ) : boolean => / ^ ( r e l e a s e s | t a g s ) / . test ( getRepoPath ( ) ! ) ;
200
+ export const isQuickPRTest = [
201
+ 'https://github.com/sindresorhus/refined-github/compare/master...branch-name?quick_pull=1' ,
202
+ 'https://github.com/sindresorhus/refined-github/compare/branch-1...branch-2?quick_pull=1' ,
203
+ 'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1'
204
+ ] ;
205
+
206
+ export const isReleasesOrTags = ( ) : boolean => {
207
+ const parts = ( getRepoPath ( ) || '' ) . split ( '/' ) ;
208
+ return / ^ ( r e l e a s e s | t a g s ) $ / . test ( parts [ 0 ] ) && parts [ 1 ] !== 'new' ;
209
+ } ;
210
+
211
+ export const isReleasesOrTagsTest = [
212
+ 'https://github.com/sindresorhus/refined-github/releases' ,
213
+ 'https://github.com/sindresorhus/refined-github/tags' ,
214
+ 'https://github.com/sindresorhus/refined-github/releases/tag/v1.0.0-beta.4' ,
215
+ 'https://github.com/sindresorhus/refined-github/releases/tag/0.2.1'
216
+ ] ;
74
217
75
218
export const isEditingFile = ( ) : boolean => / ^ e d i t / . test ( getRepoPath ( ) ! ) ;
219
+ export const isEditingFileTest = [
220
+ 'https://github.com/sindresorhus/refined-github/edit/master/readme.md' ,
221
+ 'https://github.com/sindresorhus/refined-github/edit/ghe-injection/source/background.ts'
222
+ ] ;
76
223
77
224
export const isRepo = ( ) : boolean => / ^ [ ^ / ] + \/ [ ^ / ] + / . test ( getCleanPathname ( ) ) &&
78
225
! reservedNames . includes ( getOwnerAndRepo ( ) . ownerName ) &&
79
226
! isNotifications ( ) &&
80
227
! isDashboard ( ) &&
81
228
! isGist ( ) &&
82
229
! isRepoSearch ( ) ;
230
+ export const isRepoTest = [
231
+ 'https://github.com/sindresorhus/refined-github/blame/master/package.json' ,
232
+ 'https://github.com/sindresorhus/refined-github/issues/146' ,
233
+ 'https://github.com/sindresorhus/notifications/' ,
234
+ 'https://github.com/sindresorhus/refined-github/pull/148'
235
+ ] ;
236
+ export const isRepoTestSkipNegatives = true ;
83
237
84
238
export const isRepoDiscussionList = ( ) : boolean =>
85
- / ^ ( i s s u e s | p u l l s ) ( $ | \/ $ | \/ (? ! \d + | n e w ) ) / . test ( getRepoPath ( ) ! ) || // `issues/fregante` is a list but `issues/1` isn't
239
+ isRepoPRList ( ) ||
240
+ isRepoIssueList ( ) ||
86
241
/ ^ l a b e l s \/ .+ / . test ( getRepoPath ( ) ! ) ;
242
+ export const isRepoDiscussionListTest = [
243
+ 'http://github.com/sindresorhus/ava/issues' ,
244
+ 'https://github.com/sindresorhus/refined-github/pulls' ,
245
+ 'https://github.com/sindresorhus/refined-github/pulls/' ,
246
+ 'https://github.com/sindresorhus/refined-github/pulls/fregante' ,
247
+ 'https://github.com/sindresorhus/refined-github/issues/fregante' ,
248
+ 'https://github.com/sindresorhus/refined-github/labels/Priority%3A%20critical' ,
249
+ 'https://github.com/sindresorhus/refined-github/issues?q=is%3Aclosed+sort%3Aupdated-desc' ,
250
+ 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr' ,
251
+ 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed' ,
252
+ 'https://github.com/sindresorhus/refined-github/issues'
253
+ ] ;
254
+
255
+ export const isRepoPRList = ( ) : boolean => ( getRepoPath ( ) || '' ) . startsWith ( 'pulls' ) ;
256
+ export const isRepoPRListTest = [
257
+ 'https://github.com/sindresorhus/refined-github/pulls' ,
258
+ 'https://github.com/sindresorhus/refined-github/pulls/' ,
259
+ 'https://github.com/sindresorhus/refined-github/pulls/fregante' ,
260
+ 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr' ,
261
+ 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed'
262
+ ] ;
263
+
264
+ export const isRepoIssueList = ( ) : boolean => {
265
+ const parts = ( getRepoPath ( ) || '' ) . split ( '/' ) ;
266
+ return parts [ 0 ] === 'issues' && parts [ 1 ] !== 'new' && ! / \d / . test ( parts [ 1 ] ) ; // `issues/fregante` is a list but `issues/1` isn't
267
+ } ;
268
+
269
+ export const isRepoIssueListTest = [
270
+ 'http://github.com/sindresorhus/ava/issues' ,
271
+ 'https://github.com/sindresorhus/refined-github/issues' ,
272
+ 'https://github.com/sindresorhus/refined-github/issues/fregante' ,
273
+ 'https://github.com/sindresorhus/refined-github/issues?q=is%3Aclosed+sort%3Aupdated-desc'
274
+ ] ;
87
275
88
276
export const isRepoRoot = ( ) : boolean => / ^ ( t r e e [ / ] [ ^ / ] + ) ? $ / . test ( getRepoPath ( ) ! ) ;
277
+ export const isRepoRootTest = [
278
+ // Some tests are here only as "gotchas" for other tests that may misidentify their pages
279
+ 'https://github.com/sindresorhus/edit' ,
280
+ 'https://github.com/sindresorhus/search' ,
281
+ 'https://github.com/sindresorhus/refined-github' ,
282
+ 'https://github.com/sindresorhus/refined-github/' ,
283
+ 'https://github.com/sindresorhus/notifications/' ,
284
+ 'https://github.com/sindresorhus/refined-github/tree/native-copy-buttons' ,
285
+ 'https://github.com/sindresorhus/refined-github/tree/native-copy-buttons/' ,
286
+ 'https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6' ,
287
+ 'https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6/' ,
288
+ 'https://github.com/sindresorhus/refined-github/tree/57bf4' ,
289
+ 'https://github.com/sindresorhus/refined-github?files=1' ,
290
+ 'https://github.com/sindresorhus/refined-github/tree/master?files=1'
291
+ ] ;
89
292
90
293
export const isRepoSearch = ( ) : boolean => location . pathname . slice ( 1 ) . split ( '/' ) [ 2 ] === 'search' ;
294
+ export const isRepoSearchTest = [
295
+ 'https://github.com/sindresorhus/refined-github/search?q=diff' ,
296
+ 'https://github.com/sindresorhus/refined-github/search?q=diff&unscoped_q=diff&type=Issues' ,
297
+ 'https://github.com/sindresorhus/refined-github/search'
298
+ ] ;
91
299
92
300
export const isRepoSettings = ( ) : boolean => / ^ s e t t i n g s / . test ( getRepoPath ( ) ! ) ;
301
+ export const isRepoSettingsTest = [
302
+ 'https://github.com/sindresorhus/refined-github/settings' ,
303
+ 'https://github.com/sindresorhus/refined-github/settings/branches'
304
+ ] ;
93
305
94
306
export const isRepoTree = ( ) : boolean => isRepoRoot ( ) || / ^ t r e e \/ / . test ( getRepoPath ( ) ! ) ;
307
+ export const isRepoTreeTest = [
308
+ 'https://github.com/sindresorhus/refined-github/tree/master/distribution' ,
309
+ 'https://github.com/sindresorhus/refined-github/tree/0.13.0/distribution' ,
310
+ 'https://github.com/sindresorhus/refined-github/tree/57bf435ee12d14b482df0bbd88013a2814c7512e/distribution'
311
+ ] . concat ( isRepoRootTest ) ;
95
312
96
313
export const isRepoWithAccess = ( ) : boolean => isRepo ( ) && select . exists ( '.reponav-item[href$="/settings"]' ) ;
314
+ export const isRepoWithAccessTest = domBased ;
97
315
98
316
export const isSingleCommit = ( ) : boolean => / ^ c o m m i t \/ [ 0 - 9 a - f ] { 5 , 40 } / . test ( getRepoPath ( ) ! ) ;
317
+ export const isSingleCommitTest = [
318
+ 'https://github.com/sindresorhus/refined-github/commit/5b614b9035f2035b839f48b4db7bd5c3298d526f' ,
319
+ 'https://github.com/sindresorhus/refined-github/commit/5b614'
320
+ ] ;
99
321
100
322
export const isSingleFile = ( ) : boolean => / ^ b l o b \/ / . test ( getRepoPath ( ) ! ) ;
323
+ export const isSingleFileTest = [
324
+ 'https://github.com/sindresorhus/refined-github/blob/master/.gitattributes' ,
325
+ 'https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/distribution/content.css' ,
326
+ 'https://github.com/sindresorhus/refined-github/blob/master/edit.txt'
327
+ ] ;
101
328
102
329
export const isTrending = ( ) : boolean => location . pathname === '/trending' || location . pathname . startsWith ( '/trending/' ) ;
330
+ export const isTrendingTest = [
331
+ 'https://github.com/trending' ,
332
+ 'https://github.com/trending/developers' ,
333
+ 'https://github.com/trending/unknown'
334
+ ] ;
103
335
104
336
export const isUserProfile = ( ) : boolean => select . exists ( '.user-profile-nav' ) ;
337
+ export const isUserProfileTest = domBased ;
105
338
106
339
export const isSingleTagPage = ( ) : boolean => / ^ ( r e l e a s e s \/ t a g ) / . test ( getRepoPath ( ) ! ) ;
340
+ export const isSingleTagPageTest = [
341
+ 'https://github.com/sindresorhus/refined-github/releases/tag/v1.0.0-beta.4' ,
342
+ 'https://github.com/sindresorhus/refined-github/releases/tag/0.2.1'
343
+ ] ;
107
344
345
+ export const hasCommentsTest = skip ;
108
346
export const hasComments = ( ) : boolean =>
109
347
isPR ( ) ||
110
348
isIssue ( ) ||
111
349
isCommit ( ) ||
112
350
isOrganizationDiscussion ( ) ;
113
351
352
+ export const hasRichTextEditorTest = skip ;
114
353
export const hasRichTextEditor = ( ) : boolean =>
115
354
hasComments ( ) ||
116
355
isNewIssue ( ) ||
117
356
isCompare ( ) ;
118
357
358
+ export const hasCodeTest = skip ;
119
359
export const hasCode = ( ) : boolean => // Static code, not the editor
120
360
hasComments ( ) ||
121
361
isRepoTree ( ) || // Readme files
0 commit comments