diff --git a/.ci/make.sh b/.ci/make.sh index a22ec43..a694cfe 100755 --- a/.ci/make.sh +++ b/.ci/make.sh @@ -37,7 +37,7 @@ product="elastic/elasticsearch-serverless-js" output_folder=".buildkite/output" codegen_folder=".buildkite/output" OUTPUT_DIR="$repo/${output_folder}" -NODE_VERSION=18 +NODE_VERSION=22 WORKFLOW=${WORKFLOW-staging} mkdir -p "$OUTPUT_DIR" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 42a7f77..d20585e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -70,3 +70,33 @@ jobs: - name: License checker run: | npm run license-checker + + test-bun: + name: Test Bun + runs-on: ${{ matrix.os }} + needs: paths-filter + # only run if code relevant to unit tests was changed + if: needs.paths-filter.outputs.src-only == 'true' + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + + steps: + - uses: actions/checkout@v4 + + - name: Use Bun + uses: oven-sh/setup-bun@v2 + + - name: Install + run: | + bun install + + - name: Lint + run: | + bun run lint + + - name: Unit test + run: | + bun run test:unit-bun diff --git a/.gitignore b/.gitignore index 0a6814d..1cbb440 100644 --- a/.gitignore +++ b/.gitignore @@ -66,4 +66,5 @@ lib yaml-rest-tests cloud.json junit-output +bun.lockb rest-api-spec diff --git a/.npmignore b/.npmignore index f79bbf2..7eb76f3 100644 --- a/.npmignore +++ b/.npmignore @@ -71,3 +71,4 @@ CODE_OF_CONDUCT.md CONTRIBUTING.md src +bun.lockb diff --git a/package.json b/package.json index 928471a..10aaa1c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "test:coverage-report": "npm run build && tap test/unit/{*,**/*}.test.ts --coverage && nyc report --reporter=text-lcov > coverage.lcov", "test:coverage-ui": "npm run build && tap test/unit/{*,**/*}.test.ts --coverage --coverage-report=html", "test:integration": "npm run build && node ./test/integration/index.js", - "test:unit": "npm run build && tap test/unit/{*,**/*}.test.ts" + "test:unit": "npm run build && tap test/unit/{*,**/*}.test.ts", + "test:unit-bun": "bun run build && bunx tap" }, "keywords": [ "elasticsearch", @@ -85,6 +86,7 @@ "jsx": false, "flow": false, "coverage": false, - "check-coverage": false + "check-coverage": false, + "files": "test/unit/{*,**/*}.test.ts" } } diff --git a/test/unit/api.test.ts b/test/unit/api.test.ts index 18abe38..6c3aebb 100644 --- a/test/unit/api.test.ts +++ b/test/unit/api.test.ts @@ -211,7 +211,7 @@ test('With generic document', async t => { } const Connection = connection.buildMockConnection({ - onRequest (opts) { + onRequest (_opts) { return { statusCode: 200, body: { diff --git a/test/unit/helpers/msearch.test.ts b/test/unit/helpers/msearch.test.ts index f0290d3..e80c597 100644 --- a/test/unit/helpers/msearch.test.ts +++ b/test/unit/helpers/msearch.test.ts @@ -24,7 +24,7 @@ import FakeTimers from '@sinonjs/fake-timers' test('Basic', async t => { const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: { responses: [{ @@ -78,7 +78,7 @@ test('Multiple searches (inside async iterator)', t => { t.plan(4) const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: { responses: [{ @@ -161,7 +161,7 @@ test('Multiple searches (async iterator exits)', t => { t.plan(4) const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: { responses: [{ @@ -242,7 +242,7 @@ test('Multiple searches (async iterator exits)', t => { test('Stop a msearch processor (promises)', async t => { const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: {} } } }) @@ -272,7 +272,7 @@ test('Bad header', t => { t.plan(1) const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: {} } } }) @@ -297,7 +297,7 @@ test('Bad body', t => { t.plan(1) const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: {} } } }) @@ -321,7 +321,7 @@ test('Bad body', t => { test('Retry on 429', async t => { let count = 0 const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { if (count++ === 0) { return { body: { @@ -384,7 +384,7 @@ test('Retry on 429', async t => { test('Single search errors', async t => { const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: { responses: [{ @@ -419,7 +419,7 @@ test('Entire msearch fails', t => { t.plan(2) const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { statusCode: 500, body: { @@ -454,7 +454,7 @@ test('Resolves the msearch helper', t => { t.plan(1) const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: {} } } }) @@ -470,17 +470,17 @@ test('Resolves the msearch helper', t => { m.then( () => t.pass('called'), - e => t.fail('Should not fail') + _e => t.fail('Should not fail') ) - m.catch(e => t.fail('Should not fail')) + m.catch(_e => t.fail('Should not fail')) }) test('Stop the msearch helper with an error', t => { t.plan(3) const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: {} } } }) @@ -511,7 +511,7 @@ test('Multiple searches (concurrency = 1)', t => { t.plan(4) const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: { responses: [{ @@ -587,7 +587,7 @@ test('Flush interval', t => { t.teardown(() => clock.uninstall()) const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: { responses: [{ @@ -640,7 +640,7 @@ test('Flush interval - early stop', t => { t.plan(2) const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: { responses: [{ @@ -684,7 +684,7 @@ test('Stop should resolve the helper', t => { t.plan(1) const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: { responses: [] @@ -709,7 +709,7 @@ test('Stop should resolve the helper (error)', t => { t.plan(3) const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { return { body: { responses: [] diff --git a/test/unit/helpers/scroll.test.ts b/test/unit/helpers/scroll.test.ts index 11ac5e5..72f0883 100644 --- a/test/unit/helpers/scroll.test.ts +++ b/test/unit/helpers/scroll.test.ts @@ -199,7 +199,7 @@ test('Scroll search (retry throws and maxRetries)', async t => { const expectedAttempts = maxRetries + 1 let count = 0 const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { count += 1 return { body: {}, statusCode: 429 } } @@ -220,8 +220,7 @@ test('Scroll search (retry throws and maxRetries)', async t => { }) try { - // @ts-expect-error - for await (const result of scrollSearch) { // eslint-disable-line + for await (const _result of scrollSearch) { // eslint-disable-line t.fail('we should not be here') } } catch (err: any) { @@ -349,7 +348,7 @@ test('Should not retry if maxRetries = 0', async t => { const expectedAttempts = 1 let count = 0 const MockConnection = connection.buildMockConnection({ - onRequest (params) { + onRequest (_params) { count += 1 return { body: {}, statusCode: 429 } } @@ -370,8 +369,7 @@ test('Should not retry if maxRetries = 0', async t => { }) try { - // @ts-expect-error - for await (const result of scrollSearch) { // eslint-disable-line + for await (const _result of scrollSearch) { // eslint-disable-line t.fail('we should not be here') } } catch (err: any) {