Skip to content

Commit edc45f0

Browse files
ci: Experimental Bun test runner (#90)
* Experimental Bun test runner * Update default node version for codegen --------- Co-authored-by: Josh Mock <[email protected]>
1 parent f0ba994 commit edc45f0

File tree

8 files changed

+60
-28
lines changed

8 files changed

+60
-28
lines changed

.ci/make.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ product="elastic/elasticsearch-serverless-js"
3737
output_folder=".buildkite/output"
3838
codegen_folder=".buildkite/output"
3939
OUTPUT_DIR="$repo/${output_folder}"
40-
NODE_VERSION=18
40+
NODE_VERSION=22
4141
WORKFLOW=${WORKFLOW-staging}
4242
mkdir -p "$OUTPUT_DIR"
4343

.github/workflows/tests.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,33 @@ jobs:
7070
- name: License checker
7171
run: |
7272
npm run license-checker
73+
74+
test-bun:
75+
name: Test Bun
76+
runs-on: ${{ matrix.os }}
77+
needs: paths-filter
78+
# only run if code relevant to unit tests was changed
79+
if: needs.paths-filter.outputs.src-only == 'true'
80+
81+
strategy:
82+
fail-fast: false
83+
matrix:
84+
os: [ubuntu-latest, windows-latest, macOS-latest]
85+
86+
steps:
87+
- uses: actions/checkout@v4
88+
89+
- name: Use Bun
90+
uses: oven-sh/setup-bun@v2
91+
92+
- name: Install
93+
run: |
94+
bun install
95+
96+
- name: Lint
97+
run: |
98+
bun run lint
99+
100+
- name: Unit test
101+
run: |
102+
bun run test:unit-bun

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ lib
6666
yaml-rest-tests
6767
cloud.json
6868
junit-output
69+
bun.lockb
6970
rest-api-spec

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ CODE_OF_CONDUCT.md
7171
CONTRIBUTING.md
7272

7373
src
74+
bun.lockb

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"test:coverage-report": "npm run build && tap test/unit/{*,**/*}.test.ts --coverage && nyc report --reporter=text-lcov > coverage.lcov",
2121
"test:coverage-ui": "npm run build && tap test/unit/{*,**/*}.test.ts --coverage --coverage-report=html",
2222
"test:integration": "npm run build && node ./test/integration/index.js",
23-
"test:unit": "npm run build && tap test/unit/{*,**/*}.test.ts"
23+
"test:unit": "npm run build && tap test/unit/{*,**/*}.test.ts",
24+
"test:unit-bun": "bun run build && bunx tap"
2425
},
2526
"keywords": [
2627
"elasticsearch",
@@ -87,6 +88,7 @@
8788
"jsx": false,
8889
"flow": false,
8990
"coverage": false,
90-
"check-coverage": false
91+
"check-coverage": false,
92+
"files": "test/unit/{*,**/*}.test.ts"
9193
}
9294
}

test/unit/api.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ test('With generic document', async t => {
211211
}
212212

213213
const Connection = connection.buildMockConnection({
214-
onRequest (opts) {
214+
onRequest (_opts) {
215215
return {
216216
statusCode: 200,
217217
body: {

test/unit/helpers/msearch.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import FakeTimers from '@sinonjs/fake-timers'
2424

2525
test('Basic', async t => {
2626
const MockConnection = connection.buildMockConnection({
27-
onRequest (params) {
27+
onRequest (_params) {
2828
return {
2929
body: {
3030
responses: [{
@@ -78,7 +78,7 @@ test('Multiple searches (inside async iterator)', t => {
7878
t.plan(4)
7979

8080
const MockConnection = connection.buildMockConnection({
81-
onRequest (params) {
81+
onRequest (_params) {
8282
return {
8383
body: {
8484
responses: [{
@@ -161,7 +161,7 @@ test('Multiple searches (async iterator exits)', t => {
161161
t.plan(4)
162162

163163
const MockConnection = connection.buildMockConnection({
164-
onRequest (params) {
164+
onRequest (_params) {
165165
return {
166166
body: {
167167
responses: [{
@@ -242,7 +242,7 @@ test('Multiple searches (async iterator exits)', t => {
242242

243243
test('Stop a msearch processor (promises)', async t => {
244244
const MockConnection = connection.buildMockConnection({
245-
onRequest (params) {
245+
onRequest (_params) {
246246
return { body: {} }
247247
}
248248
})
@@ -272,7 +272,7 @@ test('Bad header', t => {
272272
t.plan(1)
273273

274274
const MockConnection = connection.buildMockConnection({
275-
onRequest (params) {
275+
onRequest (_params) {
276276
return { body: {} }
277277
}
278278
})
@@ -297,7 +297,7 @@ test('Bad body', t => {
297297
t.plan(1)
298298

299299
const MockConnection = connection.buildMockConnection({
300-
onRequest (params) {
300+
onRequest (_params) {
301301
return { body: {} }
302302
}
303303
})
@@ -321,7 +321,7 @@ test('Bad body', t => {
321321
test('Retry on 429', async t => {
322322
let count = 0
323323
const MockConnection = connection.buildMockConnection({
324-
onRequest (params) {
324+
onRequest (_params) {
325325
if (count++ === 0) {
326326
return {
327327
body: {
@@ -384,7 +384,7 @@ test('Retry on 429', async t => {
384384

385385
test('Single search errors', async t => {
386386
const MockConnection = connection.buildMockConnection({
387-
onRequest (params) {
387+
onRequest (_params) {
388388
return {
389389
body: {
390390
responses: [{
@@ -419,7 +419,7 @@ test('Entire msearch fails', t => {
419419
t.plan(2)
420420

421421
const MockConnection = connection.buildMockConnection({
422-
onRequest (params) {
422+
onRequest (_params) {
423423
return {
424424
statusCode: 500,
425425
body: {
@@ -454,7 +454,7 @@ test('Resolves the msearch helper', t => {
454454
t.plan(1)
455455

456456
const MockConnection = connection.buildMockConnection({
457-
onRequest (params) {
457+
onRequest (_params) {
458458
return { body: {} }
459459
}
460460
})
@@ -470,17 +470,17 @@ test('Resolves the msearch helper', t => {
470470

471471
m.then(
472472
() => t.pass('called'),
473-
e => t.fail('Should not fail')
473+
_e => t.fail('Should not fail')
474474
)
475475

476-
m.catch(e => t.fail('Should not fail'))
476+
m.catch(_e => t.fail('Should not fail'))
477477
})
478478

479479
test('Stop the msearch helper with an error', t => {
480480
t.plan(3)
481481

482482
const MockConnection = connection.buildMockConnection({
483-
onRequest (params) {
483+
onRequest (_params) {
484484
return { body: {} }
485485
}
486486
})
@@ -511,7 +511,7 @@ test('Multiple searches (concurrency = 1)', t => {
511511
t.plan(4)
512512

513513
const MockConnection = connection.buildMockConnection({
514-
onRequest (params) {
514+
onRequest (_params) {
515515
return {
516516
body: {
517517
responses: [{
@@ -587,7 +587,7 @@ test('Flush interval', t => {
587587
t.teardown(() => clock.uninstall())
588588

589589
const MockConnection = connection.buildMockConnection({
590-
onRequest (params) {
590+
onRequest (_params) {
591591
return {
592592
body: {
593593
responses: [{
@@ -640,7 +640,7 @@ test('Flush interval - early stop', t => {
640640
t.plan(2)
641641

642642
const MockConnection = connection.buildMockConnection({
643-
onRequest (params) {
643+
onRequest (_params) {
644644
return {
645645
body: {
646646
responses: [{
@@ -684,7 +684,7 @@ test('Stop should resolve the helper', t => {
684684
t.plan(1)
685685

686686
const MockConnection = connection.buildMockConnection({
687-
onRequest (params) {
687+
onRequest (_params) {
688688
return {
689689
body: {
690690
responses: []
@@ -709,7 +709,7 @@ test('Stop should resolve the helper (error)', t => {
709709
t.plan(3)
710710

711711
const MockConnection = connection.buildMockConnection({
712-
onRequest (params) {
712+
onRequest (_params) {
713713
return {
714714
body: {
715715
responses: []

test/unit/helpers/scroll.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ test('Scroll search (retry throws and maxRetries)', async t => {
199199
const expectedAttempts = maxRetries + 1
200200
let count = 0
201201
const MockConnection = connection.buildMockConnection({
202-
onRequest (params) {
202+
onRequest (_params) {
203203
count += 1
204204
return { body: {}, statusCode: 429 }
205205
}
@@ -220,8 +220,7 @@ test('Scroll search (retry throws and maxRetries)', async t => {
220220
})
221221

222222
try {
223-
// @ts-expect-error
224-
for await (const result of scrollSearch) { // eslint-disable-line
223+
for await (const _result of scrollSearch) { // eslint-disable-line
225224
t.fail('we should not be here')
226225
}
227226
} catch (err: any) {
@@ -349,7 +348,7 @@ test('Should not retry if maxRetries = 0', async t => {
349348
const expectedAttempts = 1
350349
let count = 0
351350
const MockConnection = connection.buildMockConnection({
352-
onRequest (params) {
351+
onRequest (_params) {
353352
count += 1
354353
return { body: {}, statusCode: 429 }
355354
}
@@ -370,8 +369,7 @@ test('Should not retry if maxRetries = 0', async t => {
370369
})
371370

372371
try {
373-
// @ts-expect-error
374-
for await (const result of scrollSearch) { // eslint-disable-line
372+
for await (const _result of scrollSearch) { // eslint-disable-line
375373
t.fail('we should not be here')
376374
}
377375
} catch (err: any) {

0 commit comments

Comments
 (0)