Skip to content

Commit 016c190

Browse files
committed
switch to bun
- Replace npm/yarn with bun for package management - Replace AVA with bun test for testing (14 tests, same coverage) - Replace CircleCI with GitHub Actions - Remove ESLint and babel-eslint (deprecated tooling) - Reduce devDependencies from 529 packages to 4 No changes to the library code or public API.
1 parent cb9236b commit 016c190

File tree

8 files changed

+93
-11289
lines changed

8 files changed

+93
-11289
lines changed

.circleci/config.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: oven-sh/setup-bun@v2
15+
- run: bun install
16+
- run: bun test

bun.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,61 @@
1-
/* eslint-disable import/no-extraneous-dependencies */
2-
import test from 'ava';
1+
import { test, expect } from 'bun:test';
32
import replaceString from './';
43
import reactStringReplace from '.';
54

6-
test("Doesn't throw if not given invalid input", t => {
7-
t.notThrows(() => replaceString());
8-
t.notThrows(() => replaceString(''));
5+
test("Doesn't throw if not given invalid input", () => {
6+
expect(() => replaceString()).not.toThrow();
7+
expect(() => replaceString('')).not.toThrow();
98
});
109

11-
test('Returns an array', t => {
12-
t.true(Array.isArray(replaceString('blah', 'blah', x => x)));
10+
test('Returns an array', () => {
11+
expect(Array.isArray(replaceString('blah', 'blah', x => x))).toBe(true);
1312
});
1413

15-
test('Returns correct character offsets', t => {
14+
test('Returns correct character offsets', () => {
1615
const correctOffsets = [6, 17];
1716
const charOffsets = [];
1817

1918
replaceString('Hey there, stranger', 'er', (m, i, o) => charOffsets.push(o));
20-
t.deepEqual(charOffsets, correctOffsets);
19+
expect(charOffsets).toEqual(correctOffsets);
2120
});
2221

23-
test('Works with matching groups', t => {
24-
t.deepEqual(
25-
replaceString('hey there', /(hey)/g, x => ({ worked: x })),
26-
['', { worked: 'hey' }, ' there']
27-
);
22+
test('Works with matching groups', () => {
23+
expect(
24+
replaceString('hey there', /(hey)/g, x => ({ worked: x }))
25+
).toEqual(['', { worked: 'hey' }, ' there']);
2826
});
2927

30-
test('Respects global flag to replace multiple matches', t => {
28+
test('Respects global flag to replace multiple matches', () => {
3129
const str = 'Hey @ian_sinn and @other_handle, check out this link https://github.com/iansinnott/';
32-
t.deepEqual(
33-
replaceString(str, /@(\w+)/g, x => ({ worked: x })),
34-
['Hey ', { worked: 'ian_sinn' }, ' and ', { worked: 'other_handle' }, ', check out this link https://github.com/iansinnott/']
35-
);
30+
expect(
31+
replaceString(str, /@(\w+)/g, x => ({ worked: x }))
32+
).toEqual(['Hey ', { worked: 'ian_sinn' }, ' and ', { worked: 'other_handle' }, ', check out this link https://github.com/iansinnott/']);
3633
});
3734

38-
test('Works with strings', t => {
39-
t.deepEqual(
40-
replaceString('hey there', 'hey', x => ({ worked: x })),
41-
['', { worked: 'hey' }, ' there']
42-
);
35+
test('Works with strings', () => {
36+
expect(
37+
replaceString('hey there', 'hey', x => ({ worked: x }))
38+
).toEqual(['', { worked: 'hey' }, ' there']);
4339
});
4440

45-
test('Works with arrays', t => {
41+
test('Works with arrays', () => {
4642
const input = ['hey there', { value: 'you' }, 'again'];
47-
t.deepEqual(
48-
replaceString(input, 'hey', x => ({ worked: x })),
49-
['', { worked: 'hey' }, ' there', { value: 'you' }, 'again']
50-
);
43+
expect(
44+
replaceString(input, 'hey', x => ({ worked: x }))
45+
).toEqual(['', { worked: 'hey' }, ' there', { value: 'you' }, 'again']);
5146
});
5247

53-
test('Successfully escapes parens in strings', t => {
54-
t.deepEqual(
55-
replaceString('(hey) there', '(hey)', x => ({ worked: x })),
56-
['', { worked: '(hey)' }, ' there']
57-
);
48+
test('Successfully escapes parens in strings', () => {
49+
expect(
50+
replaceString('(hey) there', '(hey)', x => ({ worked: x }))
51+
).toEqual(['', { worked: '(hey)' }, ' there']);
5852

59-
t.deepEqual(
60-
replaceString('hey ((y)(you)) there', '((y)(you))', x => ({ worked: x })),
61-
['hey ', { worked: '((y)(you))' }, ' there']
62-
);
53+
expect(
54+
replaceString('hey ((y)(you)) there', '((y)(you))', x => ({ worked: x }))
55+
).toEqual(['hey ', { worked: '((y)(you))' }, ' there']);
6356
});
6457

65-
test('Can be called consecutively on returned result of previous call', t => {
58+
test('Can be called consecutively on returned result of previous call', () => {
6659
const originalTweet = 'Hey @iansinnott, check out this link https://github.com/iansinnott/ Hope to see you at #reactconf';
6760
let reactReplacedTweet;
6861

@@ -71,7 +64,7 @@ test('Can be called consecutively on returned result of previous call', t => {
7164
{ type: 'url', value: match }
7265
));
7366

74-
t.deepEqual(reactReplacedTweet, [
67+
expect(reactReplacedTweet).toEqual([
7568
'Hey @iansinnott, check out this link ',
7669
{ type: 'url', value: 'https://github.com/iansinnott/' },
7770
' Hope to see you at #reactconf',
@@ -82,7 +75,7 @@ test('Can be called consecutively on returned result of previous call', t => {
8275
{ type: 'mention', value: match }
8376
));
8477

85-
t.deepEqual(reactReplacedTweet, [
78+
expect(reactReplacedTweet).toEqual([
8679
'Hey ',
8780
{ type: 'mention', value: '@iansinnott' },
8881
', check out this link ',
@@ -95,7 +88,7 @@ test('Can be called consecutively on returned result of previous call', t => {
9588
{ type: 'hashtag', value: match }
9689
));
9790

98-
t.deepEqual(reactReplacedTweet, [
91+
expect(reactReplacedTweet).toEqual([
9992
'Hey ',
10093
{ type: 'mention', value: '@iansinnott' },
10194
', check out this link ',
@@ -112,15 +105,15 @@ test('Can be called consecutively on returned result of previous call', t => {
112105
* ''. This was causing an error where I was checking for !str, even though an
113106
* empty string should actually be allwed.
114107
*/
115-
test('Allows empty strings within results', t => {
108+
test('Allows empty strings within results', () => {
116109
let replacedContent;
117110
const string = '@username http://a_photo.jpg';
118111

119112
replacedContent = replaceString(string, /(http?:\/\/.*\.(?:png|jpg))/g, match => {
120113
return { key: 'image', match };
121114
});
122115

123-
t.deepEqual(replacedContent, [
116+
expect(replacedContent).toEqual([
124117
'@username ',
125118
{ key: 'image', match: 'http://a_photo.jpg' },
126119
'',
@@ -130,7 +123,7 @@ test('Allows empty strings within results', t => {
130123
return { key: 'text', match };
131124
});
132125

133-
t.deepEqual(replacedContent, [
126+
expect(replacedContent).toEqual([
134127
'',
135128
{ key: 'text', match: 'username' },
136129
' ',
@@ -139,60 +132,60 @@ test('Allows empty strings within results', t => {
139132
]);
140133
});
141134

142-
test('Will not through if first element of input is empty string', t => {
135+
test('Will not throw if first element of input is empty string', () => {
143136
const string = 'http://a_photo.jpg some string';
144137
const replacedContent = replaceString(string, /(http?:\/\/.*\.(?:png|jpg))/g, match => {
145138
return { key: 'image', match };
146139
});
147140

148-
t.deepEqual(replacedContent, [
141+
expect(replacedContent).toEqual([
149142
'',
150143
{ key: 'image', match: 'http://a_photo.jpg' },
151144
' some string',
152145
]);
153146

154147
// This replacement would not actually give a new result from above, but it is
155148
// simply to test that passing in an empty string as the first arg is OK
156-
t.notThrows(() => {
149+
expect(() => {
157150
replaceString(replacedContent, /@(\w+)/g, match => {
158151
return { key: 'text', match };
159152
});
160-
});
153+
}).not.toThrow();
161154
});
162155

163-
test("Avoids undefined values due to regex", (t) => {
156+
test("Avoids undefined values due to regex", () => {
164157
const string = `hey you there`;
165158
const re = /(hey)|(you)/;
166159

167160
// Normal splits include undefined if you do this
168-
t.deepEqual(string.split(re), ["", "hey", undefined, " ", undefined, "you", " there"]);
161+
expect(string.split(re)).toEqual(["", "hey", undefined, " ", undefined, "you", " there"]);
169162

170-
t.notThrows(() => {
163+
expect(() => {
171164
replaceString(string, /(hey)|(you)/, x => x);
172-
});
165+
}).not.toThrow();
173166
});
174167

175-
test("Fixed number of string replacements", (t) => {
168+
test("Fixed number of string replacements", () => {
176169
const string = `Test hey test hey test`;
177170
const replacedContent = reactStringReplace(string, 'hey', match => {
178171
return 'lo';
179-
},1);
180-
t.deepEqual(replacedContent, [
172+
}, 1);
173+
expect(replacedContent).toEqual([
181174
'Test ',
182175
'lo',
183176
' test ',
184177
'hey',
185178
' test'
186-
])
179+
]);
187180
});
188181

189-
test("Indexes start at 0 and are contiguous", t => {
182+
test("Indexes start at 0 and are contiguous", () => {
190183
const string = 'Hello there general Kenobi';
191184
const re = /(\w+)/;
192185

193186
let expectedIndex = 0;
194187
replaceString(string, re, (match, index) => {
195-
t.deepEqual(expectedIndex, index);
188+
expect(index).toEqual(expectedIndex);
196189
expectedIndex++;
197190
});
198-
});
191+
});

0 commit comments

Comments
 (0)