Skip to content

Commit af4ff81

Browse files
authored
Replace AVA with bun:test (#188)
1 parent 61be460 commit af4ff81

File tree

6 files changed

+191
-1555
lines changed

6 files changed

+191
-1555
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
run: npm ci || npm install
2828
- name: build
2929
run: npm run build --if-present
30-
- name: AVA
31-
run: npx ava
30+
- name: Test
31+
run: npm run test:unit
3232

3333
Build:
3434
runs-on: ubuntu-latest

collector.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
export const testableUrls = new Map<string, string[]>();
44

55
export function addTests(test: string, urls: string[]): void {
6-
// @ts-expect-error KISS for Vite
76
if (process.env.NODE_ENV !== 'bundling') {
87
testableUrls.set(test, urls);
98
}

test.ts renamed to index.test.ts

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
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';
25
import stripIndent from 'strip-indent';
36
import {getAllUrls, getTests} from './collector.js';
47
import * as pageDetect from './index.js';
@@ -15,12 +18,12 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
1518

1619
const validURLs = getTests(detectName);
1720

18-
if (validURLs[0] === 'combinedTestOnly' || String(detect).startsWith('()=>')) {
21+
if (validURLs[0] === 'combinedTestOnly' || String(detect).startsWith('() =>')) {
1922
continue;
2023
}
2124

22-
test(detectName + ' has tests', t => {
23-
t.true(
25+
test(detectName + ' has tests', () => {
26+
assert.ok(
2427
Array.isArray(validURLs),
2528
`The function \`${detectName}\` doesn’t have any tests. Set them via \`collect.set()\``,
2629
);
@@ -31,8 +34,8 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
3134
}
3235

3336
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(
3639
detect(new URL(url)),
3740
stripIndent(`
3841
Is this URL \`${detectName}\`?
@@ -52,9 +55,10 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
5255

5356
for (const url of allUrls) {
5457
if (!validURLs.includes(url)) {
55-
test(`${detectName} NO ${url}`, t => {
56-
t.false(
58+
test(`${detectName} NO ${url}`, () => {
59+
assert.equal(
5760
detect(new URL(url)),
61+
false,
5862
stripIndent(`
5963
Is this URL \`${detectName}\`?
6064
${url.replace('https://github.com', '')}
@@ -68,125 +72,125 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
6872
}
6973
}
7074

71-
test('is404', t => {
75+
test('is404', () => {
7276
document.title = 'Page not found · GitHub';
73-
t.true(pageDetect.is404());
77+
assert.ok(pageDetect.is404());
7478

7579
document.title = 'File not found · GitHub';
76-
t.true(pageDetect.is404());
80+
assert.ok(pageDetect.is404());
7781

7882
document.title = 'examples/404: Page not found examples';
79-
t.false(pageDetect.is404());
83+
assert.equal(pageDetect.is404(), false);
8084

8185
document.title = 'Dashboard';
82-
t.false(pageDetect.is404());
86+
assert.equal(pageDetect.is404(), false);
8387

8488
document.title = 'Page not found · Issue #266 · sintaxi/surge · GitHub';
85-
t.false(pageDetect.is404());
89+
assert.equal(pageDetect.is404(), false);
8690
});
8791

88-
test('is500', t => {
92+
test('is500', () => {
8993
document.title = 'Server Error · GitHub';
90-
t.true(pageDetect.is500());
94+
assert.ok(pageDetect.is500());
9195

9296
document.title = 'Unicorn! · GitHub';
93-
t.true(pageDetect.is500());
97+
assert.ok(pageDetect.is500());
9498

9599
document.title = 'examples/500: Server Error examples';
96-
t.false(pageDetect.is500());
100+
assert.equal(pageDetect.is500(), false);
97101

98102
document.title = 'sindresorhus/unicorn: You can’t tell what doesn’t exist';
99-
t.false(pageDetect.is500());
103+
assert.equal(pageDetect.is500(), false);
100104

101105
document.title = 'Dashboard';
102-
t.false(pageDetect.is500());
106+
assert.equal(pageDetect.is500(), false);
103107

104108
document.title = 'Server Error · Issue #266 · sintaxi/surge · GitHub';
105-
t.false(pageDetect.is500());
109+
assert.equal(pageDetect.is500(), false);
106110
});
107111

108-
test('isPRCommit404', t => {
112+
test('isPRCommit404', () => {
109113
document.title = 'Commit range not found · Pull Request #3227 · sindresorhus/refined-github';
110114
location.href = 'https://github.com/sindresorhus/refined-github/pull/3227/commits/32c8a88360a85739f151566eae0225d530ce6a15';
111-
t.true(pageDetect.isPRCommit404());
115+
assert.ok(pageDetect.isPRCommit404());
112116

113117
document.title = 'Experiment with `@primer/octicons-react` icons by FloEdelmann · Pull Request #3227 · sindresorhus/refined-github';
114118
location.href = 'https://github.com/sindresorhus/refined-github/pull/3227/commits/edbdcdd5559a2a8da78abdc7cb0814155713974c';
115-
t.false(pageDetect.isPRCommit404());
119+
assert.equal(pageDetect.isPRCommit404(), false);
116120

117121
document.title = 'Commit range not found by SomeContributor · Pull Request #999999 · sindresorhus/refined-github';
118122
location.href = 'https://github.com/sindresorhus/refined-github/pull/999999/commits/32c8a88360a85739f151566eae0225d530ce6a15';
119-
t.false(pageDetect.isPRCommit404());
123+
assert.equal(pageDetect.isPRCommit404(), false);
120124
});
121125

122-
test('isPRFile404', t => {
126+
test('isPRFile404', () => {
123127
document.title = 'Commit range not found · Pull Request #789 · sindresorhus/eslint-plugin-unicorn';
124128
location.href = 'https://github.com/sindresorhus/eslint-plugin-unicorn/pull/789/files/a58b37845f1b2660221de019e4ae6c736feedc26..eed168224d7994652b1d1ff69a5c8cebee223faf';
125-
t.true(pageDetect.isPRFile404());
129+
assert.ok(pageDetect.isPRFile404());
126130

127131
document.title = 'Add `align-repository-header` feature by fregante · Pull Request #3313 · sindresorhus/refined-github';
128132
location.href = 'https://github.com/sindresorhus/refined-github/pull/3313/files/a14fb2c94eae3ca83a3a97688a171fcc3405524f..fbeeba9825f12b5ded9cd4bb04d5df4b0cf2f2a8';
129-
t.false(pageDetect.isPRFile404());
133+
assert.equal(pageDetect.isPRFile404(), false);
130134
});
131135

132-
test('isRepoFile404', t => {
136+
test('isRepoFile404', () => {
133137
document.title = 'File not found';
134138
location.href = 'https://github.com/fregante/GhostText/tree/3cacd7df71b097dc525d99c7aa2f54d31b02fcc8/chrome/scripts/InputArea';
135-
t.true(pageDetect.isRepoFile404());
139+
assert.ok(pageDetect.isRepoFile404());
136140

137141
document.title = 'File not found';
138142
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());
140144
});
141145

142146
const {getRepositoryInfo} = pageDetect.utils;
143-
test('getRepositoryInfo', t => {
147+
test('getRepositoryInfo', () => {
144148
const inputTypes = [
145149
getRepositoryInfo, // Full URL
146150
(url: string) => getRepositoryInfo(new URL(url).pathname), // Pathname only
147151
(url: string) => getRepositoryInfo(new URL(url)), // URL object
148152
];
149153
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'), {
154158
owner: 'refined-github',
155159
name: 'github-url-detection',
156160
nameWithOwner: 'refined-github/github-url-detection',
157161
path: '',
158162
});
159-
t.deepEqual(getRepositoryInfoAdapter('https://github.com/refined-github/github-url-detection/'), {
163+
assert.deepEqual(getRepositoryInfoAdapter('https://github.com/refined-github/github-url-detection/'), {
160164
owner: 'refined-github',
161165
name: 'github-url-detection',
162166
nameWithOwner: 'refined-github/github-url-detection',
163167
path: '',
164168
});
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'), {
166170
owner: 'refined-github',
167171
name: 'github-url-detection',
168172
nameWithOwner: 'refined-github/github-url-detection',
169173
path: 'blame/master/package.json',
170174
});
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'), {
172176
owner: 'refined-github',
173177
name: 'github-url-detection',
174178
nameWithOwner: 'refined-github/github-url-detection',
175179
path: 'commit/57bf4',
176180
});
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'), {
178182
owner: 'refined-github',
179183
name: 'github-url-detection',
180184
nameWithOwner: 'refined-github/github-url-detection',
181185
path: 'compare/test-branch',
182186
});
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'), {
184188
owner: 'refined-github',
185189
name: 'github-url-detection',
186190
nameWithOwner: 'refined-github/github-url-detection',
187191
path: 'tree/master/distribution',
188192
});
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/'), {
190194
owner: 'refined-github',
191195
name: 'github-url-detection',
192196
nameWithOwner: 'refined-github/github-url-detection',

0 commit comments

Comments
 (0)