diff --git a/.github/workflows/other-runtime-unit-test.yml b/.github/workflows/other-runtime-unit-test.yml index d4325b9ea..5bdd886d5 100644 --- a/.github/workflows/other-runtime-unit-test.yml +++ b/.github/workflows/other-runtime-unit-test.yml @@ -52,3 +52,39 @@ jobs: ${{ runner.os }}-deno-${{ inputs.package }} - name: Deno Unit Test run: yarn test:deno-unit --cache-dir=".turbo" --filter=./packages/${{ inputs.package }} + bun-unit-test: + name: Bun Unit Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - uses: oven-sh/setup-bun@v1 + with: + bun-version: "1.0.6" + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - run: yarn install --immutable + - name: Turbo Cache + id: turbo-cache + uses: actions/cache@v3 + with: + path: .turbo + key: ${{ runner.os }}-turbo-test:bun-unit-${{ inputs.package }}-${{ github.sha }} + - name: Build dist cache + if: steps.turbo-cache.outputs.cache-hit != 'true' + uses: actions/cache@v3 + with: + path: .turbo + key: ${{ runner.os }}-turbo-build-${{ github.sha }} + - name: Bun Unit Test + run: yarn test:bun-unit --cache-dir=".turbo" --filter=./packages/${{ inputs.package }} + timeout-minutes: 1 diff --git a/.gitignore b/.gitignore index b24f7d638..c32191f36 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ coverage # build dist denoTestsDist +bunTestsDist benchDist out build diff --git a/package.json b/package.json index a56735777..b8c51f2f4 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "test:unit": "turbo run test:unit", "test:integration": "turbo run test:integration", "test:deno-unit": "turbo run test:deno-unit", + "test:bun-unit": "turbo run test:bun-unit", "test:e2e": "turbo run test:e2e", "test:test-type": "turbo run test:test-type", "format": "prettier --write \"**/*.{ts,tsx,md}\"", diff --git a/packages/rest/package.json b/packages/rest/package.json index 5baafb685..06d22000e 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -18,6 +18,7 @@ "test:unit-coverage": "c8 mocha --no-warnings 'tests/unit/**/*.spec.ts'", "test:unit": "c8 --r lcov mocha --no-warnings 'tests/unit/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js rest", "test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist/unit", + "test:bun-unit": "node ../../scripts/fixBunTestExtension.js && bun test bunTestsDist/unit", "test:e2e": "c8 --r lcov mocha --exit --no-warnings --jobs 1 --t 30000 'tests/e2e/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js rest", "test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/unit/**/*.spec.ts'", "test:type": "tsc --noEmit", diff --git a/packages/utils/package.json b/packages/utils/package.json index aa97eaa0c..84d2c9d04 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -18,6 +18,7 @@ "test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'", "test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js utils", "test:deno-unit": "swc tests --delete-dir-on-start -C jsc.minify.mangle=false --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist", + "test:bun-unit": "node ../../scripts/fixBunTestExtension.js && bun test bunTestsDist", "test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'", "test:type": "tsc --noEmit", "test:test-type": "tsc --project tsconfig.test.json" diff --git a/packages/utils/tests/bucket.spec.ts b/packages/utils/tests/bucket.spec.ts index 98ac27037..9a5afee77 100644 --- a/packages/utils/tests/bucket.spec.ts +++ b/packages/utils/tests/bucket.spec.ts @@ -15,12 +15,14 @@ describe('bucket.ts', () => { let clock: sinon.SinonFakeTimers beforeEach(() => { + console.log('before') clock = sinon.useFakeTimers() }) afterEach(() => { sinon.restore() clock.restore() + console.log('after') }) describe('LeakyBucket function', () => { diff --git a/scripts/fixBunTestExtension.js b/scripts/fixBunTestExtension.js new file mode 100644 index 000000000..b0373e6a9 --- /dev/null +++ b/scripts/fixBunTestExtension.js @@ -0,0 +1,21 @@ +import fs from 'node:fs' + +const dirs = [''] +try { + fs.rmSync('bunTestsDist', { recursive: true, force: true }) +} catch { + // +} +for await (const dir of dirs) { + await Promise.all( + fs.readdirSync(`tests${dir}`).map(async (file) => { + if (!file.endsWith('.ts') && !file.includes('.')) { + dirs.push(`${dir}/${file}`) + return + } + const content = await fs.promises.readFile(`tests${dir}/${file}`, 'utf-8') + fs.mkdirSync(`bunTestsDist${dir}`, { recursive: true }) + fs.promises.writeFile(`bunTestsDist${dir}/${file}`, content.replace(/'mocha'/g, "'bun:test'")) + }), + ) +} diff --git a/turbo.json b/turbo.json index 20215e33e..a712ff0fe 100644 --- a/turbo.json +++ b/turbo.json @@ -32,6 +32,14 @@ "dependsOn": ["build", "^build"], "outputs": ["denoTestsDist/**"] }, + "test:bun-unit": { + "dependsOn": [ + "^build" + ], + "outputs": [ + "bunTestsDist/**" + ] + }, "test:e2e": { "dependsOn": ["^build"], "outputs": ["coverage/**"]