Skip to content

Commit 6a307d4

Browse files
committed
chore: improve some test assertions
1 parent 69cb802 commit 6a307d4

2 files changed

Lines changed: 87 additions & 65 deletions

File tree

src/test/package_helpers.test.ts

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {test, expect, describe} from 'vitest';
1+
import {test, assert, describe} from 'vitest';
22

33
import {
44
url_github_file,
@@ -13,211 +13,227 @@ import {
1313

1414
describe('url_github_file', () => {
1515
test('builds basic file URL', () => {
16-
expect(url_github_file('https://github.com/foo/bar', 'src/index.ts')).toBe(
16+
assert.equal(
17+
url_github_file('https://github.com/foo/bar', 'src/index.ts'),
1718
'https://github.com/foo/bar/blob/main/src/index.ts',
1819
);
1920
});
2021

2122
test('strips leading ./ from file path', () => {
22-
expect(url_github_file('https://github.com/foo/bar', './src/index.ts')).toBe(
23+
assert.equal(
24+
url_github_file('https://github.com/foo/bar', './src/index.ts'),
2325
'https://github.com/foo/bar/blob/main/src/index.ts',
2426
);
2527
});
2628

2729
test('includes line number when provided', () => {
28-
expect(url_github_file('https://github.com/foo/bar', 'src/index.ts', 42)).toBe(
30+
assert.equal(
31+
url_github_file('https://github.com/foo/bar', 'src/index.ts', 42),
2932
'https://github.com/foo/bar/blob/main/src/index.ts#L42',
3033
);
3134
});
3235

3336
test('handles nested paths', () => {
34-
expect(url_github_file('https://github.com/foo/bar', 'src/lib/utils/helpers.ts')).toBe(
37+
assert.equal(
38+
url_github_file('https://github.com/foo/bar', 'src/lib/utils/helpers.ts'),
3539
'https://github.com/foo/bar/blob/main/src/lib/utils/helpers.ts',
3640
);
3741
});
3842

3943
test('handles root-level files', () => {
40-
expect(url_github_file('https://github.com/foo/bar', 'README.md')).toBe(
44+
assert.equal(
45+
url_github_file('https://github.com/foo/bar', 'README.md'),
4146
'https://github.com/foo/bar/blob/main/README.md',
4247
);
4348
});
4449
});
4550

4651
describe('url_github_org', () => {
4752
test('extracts org URL from repo URL', () => {
48-
expect(url_github_org('https://github.com/fuzdev/fuz_ui', 'fuz_ui')).toBe(
53+
assert.equal(
54+
url_github_org('https://github.com/fuzdev/fuz_ui', 'fuz_ui'),
4955
'https://github.com/fuzdev',
5056
);
5157
});
5258

5359
test('returns null when repo name does not match', () => {
54-
expect(url_github_org('https://github.com/fuzdev/fuz_ui', 'other_repo')).toBe(null);
60+
assert.equal(url_github_org('https://github.com/fuzdev/fuz_ui', 'other_repo'), null);
5561
});
5662

5763
test('returns null for partial match', () => {
58-
expect(url_github_org('https://github.com/fuzdev/fuz_ui_extra', 'fuz_ui')).toBe(null);
64+
assert.equal(url_github_org('https://github.com/fuzdev/fuz_ui_extra', 'fuz_ui'), null);
5965
});
6066

6167
test('handles single-word org names', () => {
62-
expect(url_github_org('https://github.com/org/repo', 'repo')).toBe('https://github.com/org');
68+
assert.equal(url_github_org('https://github.com/org/repo', 'repo'), 'https://github.com/org');
6369
});
6470
});
6571

6672
describe('repo_url_github_owner', () => {
6773
test('extracts owner from GitHub URL', () => {
68-
expect(repo_url_github_owner('https://github.com/fuzdev/fuz_ui')).toBe('fuzdev');
74+
assert.equal(repo_url_github_owner('https://github.com/fuzdev/fuz_ui'), 'fuzdev');
6975
});
7076

7177
test('returns null for non-GitHub URL', () => {
72-
expect(repo_url_github_owner('https://gitlab.com/foo/bar')).toBe(null);
78+
assert.equal(repo_url_github_owner('https://gitlab.com/foo/bar'), null);
7379
});
7480

7581
test('returns null for malformed GitHub URL', () => {
76-
expect(repo_url_github_owner('https://github.com/')).toBe(null);
82+
assert.equal(repo_url_github_owner('https://github.com/'), null);
7783
});
7884

7985
test('handles URLs with trailing content', () => {
80-
expect(repo_url_github_owner('https://github.com/owner/repo/tree/main')).toBe('owner');
86+
assert.equal(repo_url_github_owner('https://github.com/owner/repo/tree/main'), 'owner');
8187
});
8288

8389
test('returns null for http (non-https) URL', () => {
84-
expect(repo_url_github_owner('http://github.com/foo/bar')).toBe(null);
90+
assert.equal(repo_url_github_owner('http://github.com/foo/bar'), null);
8591
});
8692
});
8793

8894
describe('url_npm_package', () => {
8995
test('builds URL for unscoped package', () => {
90-
expect(url_npm_package('lodash')).toBe('https://www.npmjs.com/package/lodash');
96+
assert.equal(url_npm_package('lodash'), 'https://www.npmjs.com/package/lodash');
9197
});
9298

9399
test('builds URL for scoped package', () => {
94-
expect(url_npm_package('@fuzdev/fuz_ui')).toBe('https://www.npmjs.com/package/@fuzdev/fuz_ui');
100+
assert.equal(url_npm_package('@fuzdev/fuz_ui'), 'https://www.npmjs.com/package/@fuzdev/fuz_ui');
95101
});
96102
});
97103

98104
describe('package_is_published', () => {
99105
test('returns true for published package', () => {
100-
expect(
106+
assert.equal(
101107
package_is_published({
102108
name: 'my-package',
103109
version: '1.0.0',
104110
exports: {'.': './index.js'},
105111
}),
106-
).toBe(true);
112+
true,
113+
);
107114
});
108115

109116
test('returns false for private package', () => {
110-
expect(
117+
assert.equal(
111118
package_is_published({
112119
name: 'my-package',
113120
version: '1.0.0',
114121
private: true,
115122
exports: {'.': './index.js'},
116123
}),
117-
).toBe(false);
124+
false,
125+
);
118126
});
119127

120128
test('returns false for package without exports', () => {
121-
expect(
129+
assert.equal(
122130
package_is_published({
123131
name: 'my-package',
124132
version: '1.0.0',
125133
}),
126-
).toBe(false);
134+
false,
135+
);
127136
});
128137

129138
test('returns false for initial version 0.0.1', () => {
130-
expect(
139+
assert.equal(
131140
package_is_published({
132141
name: 'my-package',
133142
version: '0.0.1',
134143
exports: {'.': './index.js'},
135144
}),
136-
).toBe(false);
145+
false,
146+
);
137147
});
138148

139149
test('returns true for version 0.0.2', () => {
140-
expect(
150+
assert.equal(
141151
package_is_published({
142152
name: 'my-package',
143153
version: '0.0.2',
144154
exports: {'.': './index.js'},
145155
}),
146-
).toBe(true);
156+
true,
157+
);
147158
});
148159
});
149160

150161
describe('repo_name_parse', () => {
151162
test('returns name for unscoped package', () => {
152-
expect(repo_name_parse('lodash')).toBe('lodash');
163+
assert.equal(repo_name_parse('lodash'), 'lodash');
153164
});
154165

155166
test('extracts name from scoped package', () => {
156-
expect(repo_name_parse('@fuzdev/fuz_ui')).toBe('fuz_ui');
167+
assert.equal(repo_name_parse('@fuzdev/fuz_ui'), 'fuz_ui');
157168
});
158169

159170
test('throws for malformed scoped package', () => {
160-
expect(() => repo_name_parse('@fuzdev')).toThrow('invalid scoped package name');
171+
assert.throws(() => repo_name_parse('@fuzdev'), /invalid scoped package name/);
161172
});
162173

163174
test('handles package names with hyphens', () => {
164-
expect(repo_name_parse('@org/my-package-name')).toBe('my-package-name');
175+
assert.equal(repo_name_parse('@org/my-package-name'), 'my-package-name');
165176
});
166177
});
167178

168179
describe('repo_url_parse', () => {
169180
test('returns null for undefined', () => {
170-
expect(repo_url_parse(undefined)).toBe(null);
181+
assert.equal(repo_url_parse(undefined), null);
171182
});
172183

173184
test('handles string URL directly', () => {
174-
expect(repo_url_parse('https://github.com/foo/bar')).toBe('https://github.com/foo/bar');
185+
assert.equal(repo_url_parse('https://github.com/foo/bar'), 'https://github.com/foo/bar');
175186
});
176187

177188
test('extracts URL from object format', () => {
178-
expect(repo_url_parse({type: 'git', url: 'https://github.com/foo/bar'})).toBe(
189+
assert.equal(
190+
repo_url_parse({type: 'git', url: 'https://github.com/foo/bar'}),
179191
'https://github.com/foo/bar',
180192
);
181193
});
182194

183195
test('strips git+ prefix', () => {
184-
expect(repo_url_parse('git+https://github.com/foo/bar')).toBe('https://github.com/foo/bar');
196+
assert.equal(repo_url_parse('git+https://github.com/foo/bar'), 'https://github.com/foo/bar');
185197
});
186198

187199
test('strips .git suffix', () => {
188-
expect(repo_url_parse('https://github.com/foo/bar.git')).toBe('https://github.com/foo/bar');
200+
assert.equal(repo_url_parse('https://github.com/foo/bar.git'), 'https://github.com/foo/bar');
189201
});
190202

191203
test('strips both git+ prefix and .git suffix', () => {
192-
expect(repo_url_parse({type: 'git', url: 'git+https://github.com/foo/bar.git'})).toBe(
204+
assert.equal(
205+
repo_url_parse({type: 'git', url: 'git+https://github.com/foo/bar.git'}),
193206
'https://github.com/foo/bar',
194207
);
195208
});
196209

197210
test('strips trailing slash', () => {
198-
expect(repo_url_parse('https://github.com/foo/bar/')).toBe('https://github.com/foo/bar');
211+
assert.equal(repo_url_parse('https://github.com/foo/bar/'), 'https://github.com/foo/bar');
199212
});
200213

201214
test('returns null for object without url', () => {
202-
expect(repo_url_parse({type: 'git'} as any)).toBe(null);
215+
assert.equal(repo_url_parse({type: 'git'} as any), null);
203216
});
204217
});
205218

206219
describe('url_well_known', () => {
207220
test('builds .well-known URL', () => {
208-
expect(url_well_known('https://fuz.dev', 'package.json')).toBe(
221+
assert.equal(
222+
url_well_known('https://fuz.dev', 'package.json'),
209223
'https://fuz.dev/.well-known/package.json',
210224
);
211225
});
212226

213227
test('handles homepage with trailing slash', () => {
214-
expect(url_well_known('https://fuz.dev/', 'package.json')).toBe(
228+
assert.equal(
229+
url_well_known('https://fuz.dev/', 'package.json'),
215230
'https://fuz.dev/.well-known/package.json',
216231
);
217232
});
218233

219234
test('handles various filenames', () => {
220-
expect(url_well_known('https://example.com', 'security.txt')).toBe(
235+
assert.equal(
236+
url_well_known('https://example.com', 'security.txt'),
221237
'https://example.com/.well-known/security.txt',
222238
);
223239
});

0 commit comments

Comments
 (0)