1
- import test from 'ava' ;
1
+ /// <reference types="bun-types" />
2
+ /// <reference lib="dom" />
3
+ import assert from 'node:assert/strict' ;
4
+ import { test } from 'bun:test' ;
2
5
import stripIndent from 'strip-indent' ;
3
6
import { getAllUrls , getTests } from './collector.js' ;
4
7
import * as pageDetect from './index.js' ;
@@ -15,12 +18,12 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
15
18
16
19
const validURLs = getTests ( detectName ) ;
17
20
18
- if ( validURLs [ 0 ] === 'combinedTestOnly' || String ( detect ) . startsWith ( '()=>' ) ) {
21
+ if ( validURLs [ 0 ] === 'combinedTestOnly' || String ( detect ) . startsWith ( '() =>' ) ) {
19
22
continue ;
20
23
}
21
24
22
- test ( detectName + ' has tests' , t => {
23
- t . true (
25
+ test ( detectName + ' has tests' , ( ) => {
26
+ assert . ok (
24
27
Array . isArray ( validURLs ) ,
25
28
`The function \`${ detectName } \` doesn’t have any tests. Set them via \`collect.set()\`` ,
26
29
) ;
@@ -31,8 +34,8 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
31
34
}
32
35
33
36
for ( const url of validURLs ) {
34
- test ( `${ detectName } ${ url . replace ( 'https://github.com' , '' ) } ` , t => {
35
- t . true (
37
+ test ( `${ detectName } ${ url . replace ( 'https://github.com' , '' ) } ` , ( ) => {
38
+ assert . ok (
36
39
detect ( new URL ( url ) ) ,
37
40
stripIndent ( `
38
41
Is this URL \`${ detectName } \`?
@@ -52,9 +55,10 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
52
55
53
56
for ( const url of allUrls ) {
54
57
if ( ! validURLs . includes ( url ) ) {
55
- test ( `${ detectName } NO ${ url } ` , t => {
56
- t . false (
58
+ test ( `${ detectName } NO ${ url } ` , ( ) => {
59
+ assert . equal (
57
60
detect ( new URL ( url ) ) ,
61
+ false ,
58
62
stripIndent ( `
59
63
Is this URL \`${ detectName } \`?
60
64
${ url . replace ( 'https://github.com' , '' ) }
@@ -68,125 +72,125 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
68
72
}
69
73
}
70
74
71
- test ( 'is404' , t => {
75
+ test ( 'is404' , ( ) => {
72
76
document . title = 'Page not found · GitHub' ;
73
- t . true ( pageDetect . is404 ( ) ) ;
77
+ assert . ok ( pageDetect . is404 ( ) ) ;
74
78
75
79
document . title = 'File not found · GitHub' ;
76
- t . true ( pageDetect . is404 ( ) ) ;
80
+ assert . ok ( pageDetect . is404 ( ) ) ;
77
81
78
82
document . title = 'examples/404: Page not found examples' ;
79
- t . false ( pageDetect . is404 ( ) ) ;
83
+ assert . equal ( pageDetect . is404 ( ) , false ) ;
80
84
81
85
document . title = 'Dashboard' ;
82
- t . false ( pageDetect . is404 ( ) ) ;
86
+ assert . equal ( pageDetect . is404 ( ) , false ) ;
83
87
84
88
document . title = 'Page not found · Issue #266 · sintaxi/surge · GitHub' ;
85
- t . false ( pageDetect . is404 ( ) ) ;
89
+ assert . equal ( pageDetect . is404 ( ) , false ) ;
86
90
} ) ;
87
91
88
- test ( 'is500' , t => {
92
+ test ( 'is500' , ( ) => {
89
93
document . title = 'Server Error · GitHub' ;
90
- t . true ( pageDetect . is500 ( ) ) ;
94
+ assert . ok ( pageDetect . is500 ( ) ) ;
91
95
92
96
document . title = 'Unicorn! · GitHub' ;
93
- t . true ( pageDetect . is500 ( ) ) ;
97
+ assert . ok ( pageDetect . is500 ( ) ) ;
94
98
95
99
document . title = 'examples/500: Server Error examples' ;
96
- t . false ( pageDetect . is500 ( ) ) ;
100
+ assert . equal ( pageDetect . is500 ( ) , false ) ;
97
101
98
102
document . title = 'sindresorhus/unicorn: You can’t tell what doesn’t exist' ;
99
- t . false ( pageDetect . is500 ( ) ) ;
103
+ assert . equal ( pageDetect . is500 ( ) , false ) ;
100
104
101
105
document . title = 'Dashboard' ;
102
- t . false ( pageDetect . is500 ( ) ) ;
106
+ assert . equal ( pageDetect . is500 ( ) , false ) ;
103
107
104
108
document . title = 'Server Error · Issue #266 · sintaxi/surge · GitHub' ;
105
- t . false ( pageDetect . is500 ( ) ) ;
109
+ assert . equal ( pageDetect . is500 ( ) , false ) ;
106
110
} ) ;
107
111
108
- test ( 'isPRCommit404' , t => {
112
+ test ( 'isPRCommit404' , ( ) => {
109
113
document . title = 'Commit range not found · Pull Request #3227 · sindresorhus/refined-github' ;
110
114
location . href = 'https://github.com/sindresorhus/refined-github/pull/3227/commits/32c8a88360a85739f151566eae0225d530ce6a15' ;
111
- t . true ( pageDetect . isPRCommit404 ( ) ) ;
115
+ assert . ok ( pageDetect . isPRCommit404 ( ) ) ;
112
116
113
117
document . title = 'Experiment with `@primer/octicons-react` icons by FloEdelmann · Pull Request #3227 · sindresorhus/refined-github' ;
114
118
location . href = 'https://github.com/sindresorhus/refined-github/pull/3227/commits/edbdcdd5559a2a8da78abdc7cb0814155713974c' ;
115
- t . false ( pageDetect . isPRCommit404 ( ) ) ;
119
+ assert . equal ( pageDetect . isPRCommit404 ( ) , false ) ;
116
120
117
121
document . title = 'Commit range not found by SomeContributor · Pull Request #999999 · sindresorhus/refined-github' ;
118
122
location . href = 'https://github.com/sindresorhus/refined-github/pull/999999/commits/32c8a88360a85739f151566eae0225d530ce6a15' ;
119
- t . false ( pageDetect . isPRCommit404 ( ) ) ;
123
+ assert . equal ( pageDetect . isPRCommit404 ( ) , false ) ;
120
124
} ) ;
121
125
122
- test ( 'isPRFile404' , t => {
126
+ test ( 'isPRFile404' , ( ) => {
123
127
document . title = 'Commit range not found · Pull Request #789 · sindresorhus/eslint-plugin-unicorn' ;
124
128
location . href = 'https://github.com/sindresorhus/eslint-plugin-unicorn/pull/789/files/a58b37845f1b2660221de019e4ae6c736feedc26..eed168224d7994652b1d1ff69a5c8cebee223faf' ;
125
- t . true ( pageDetect . isPRFile404 ( ) ) ;
129
+ assert . ok ( pageDetect . isPRFile404 ( ) ) ;
126
130
127
131
document . title = 'Add `align-repository-header` feature by fregante · Pull Request #3313 · sindresorhus/refined-github' ;
128
132
location . href = 'https://github.com/sindresorhus/refined-github/pull/3313/files/a14fb2c94eae3ca83a3a97688a171fcc3405524f..fbeeba9825f12b5ded9cd4bb04d5df4b0cf2f2a8' ;
129
- t . false ( pageDetect . isPRFile404 ( ) ) ;
133
+ assert . equal ( pageDetect . isPRFile404 ( ) , false ) ;
130
134
} ) ;
131
135
132
- test ( 'isRepoFile404' , t => {
136
+ test ( 'isRepoFile404' , ( ) => {
133
137
document . title = 'File not found' ;
134
138
location . href = 'https://github.com/fregante/GhostText/tree/3cacd7df71b097dc525d99c7aa2f54d31b02fcc8/chrome/scripts/InputArea' ;
135
- t . true ( pageDetect . isRepoFile404 ( ) ) ;
139
+ assert . ok ( pageDetect . isRepoFile404 ( ) ) ;
136
140
137
141
document . title = 'File not found' ;
138
142
location . href = 'https://github.com/refined-github/refined-github/blob/some-non-existent-ref/source/features/bugs-tab.tsx' ;
139
- t . true ( pageDetect . isRepoFile404 ( ) ) ;
143
+ assert . ok ( pageDetect . isRepoFile404 ( ) ) ;
140
144
} ) ;
141
145
142
146
const { getRepositoryInfo} = pageDetect . utils ;
143
- test ( 'getRepositoryInfo' , t => {
147
+ test ( 'getRepositoryInfo' , ( ) => {
144
148
const inputTypes = [
145
149
getRepositoryInfo , // Full URL
146
150
( url : string ) => getRepositoryInfo ( new URL ( url ) . pathname ) , // Pathname only
147
151
( url : string ) => getRepositoryInfo ( new URL ( url ) ) , // URL object
148
152
] ;
149
153
for ( const getRepositoryInfoAdapter of inputTypes ) {
150
- t . is ( getRepositoryInfoAdapter ( 'https://github.com' ) , undefined ) ;
151
- t . is ( getRepositoryInfoAdapter ( 'https://gist.github.com/' ) , undefined ) ;
152
- t . is ( getRepositoryInfoAdapter ( 'https://github.com/settings/developers' ) , undefined ) ;
153
- t . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection' ) , {
154
+ assert . equal ( getRepositoryInfoAdapter ( 'https://github.com' ) , undefined ) ;
155
+ assert . equal ( getRepositoryInfoAdapter ( 'https://gist.github.com/' ) , undefined ) ;
156
+ assert . equal ( getRepositoryInfoAdapter ( 'https://github.com/settings/developers' ) , undefined ) ;
157
+ assert . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection' ) , {
154
158
owner : 'refined-github' ,
155
159
name : 'github-url-detection' ,
156
160
nameWithOwner : 'refined-github/github-url-detection' ,
157
161
path : '' ,
158
162
} ) ;
159
- t . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection/' ) , {
163
+ assert . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection/' ) , {
160
164
owner : 'refined-github' ,
161
165
name : 'github-url-detection' ,
162
166
nameWithOwner : 'refined-github/github-url-detection' ,
163
167
path : '' ,
164
168
} ) ;
165
- t . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection/blame/master/package.json' ) , {
169
+ assert . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection/blame/master/package.json' ) , {
166
170
owner : 'refined-github' ,
167
171
name : 'github-url-detection' ,
168
172
nameWithOwner : 'refined-github/github-url-detection' ,
169
173
path : 'blame/master/package.json' ,
170
174
} ) ;
171
- t . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection/commit/57bf4' ) , {
175
+ assert . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection/commit/57bf4' ) , {
172
176
owner : 'refined-github' ,
173
177
name : 'github-url-detection' ,
174
178
nameWithOwner : 'refined-github/github-url-detection' ,
175
179
path : 'commit/57bf4' ,
176
180
} ) ;
177
- t . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection/compare/test-branch?quick_pull=0' ) , {
181
+ assert . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection/compare/test-branch?quick_pull=0' ) , {
178
182
owner : 'refined-github' ,
179
183
name : 'github-url-detection' ,
180
184
nameWithOwner : 'refined-github/github-url-detection' ,
181
185
path : 'compare/test-branch' ,
182
186
} ) ;
183
- t . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection/tree/master/distribution' ) , {
187
+ assert . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection/tree/master/distribution' ) , {
184
188
owner : 'refined-github' ,
185
189
name : 'github-url-detection' ,
186
190
nameWithOwner : 'refined-github/github-url-detection' ,
187
191
path : 'tree/master/distribution' ,
188
192
} ) ;
189
- t . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection/tree/master/distribution/' ) , {
193
+ assert . deepEqual ( getRepositoryInfoAdapter ( 'https://github.com/refined-github/github-url-detection/tree/master/distribution/' ) , {
190
194
owner : 'refined-github' ,
191
195
name : 'github-url-detection' ,
192
196
nameWithOwner : 'refined-github/github-url-detection' ,
0 commit comments