test: bun test (#2798)

* test: bun test

* Update package.json

* ci: update bun version

* Update package.json

* Update package.json

* test

* ci: update bun

* chore(ci): update bun version

---------

Co-authored-by: H01001000 <heiheiho000@gmail.com>
This commit is contained in:
Skillz4Killz
2023-10-28 07:52:58 -05:00
committed by GitHub
parent 1bd75d5914
commit 914dc30396
8 changed files with 71 additions and 0 deletions
@@ -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
+1
View File
@@ -31,6 +31,7 @@ coverage
# build
dist
denoTestsDist
bunTestsDist
benchDist
out
build
+1
View File
@@ -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}\"",
+1
View File
@@ -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",
+1
View File
@@ -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"
+2
View File
@@ -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', () => {
+21
View File
@@ -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'"))
}),
)
}
+8
View File
@@ -32,6 +32,14 @@
"dependsOn": ["build", "^build"],
"outputs": ["denoTestsDist/**"]
},
"test:bun-unit": {
"dependsOn": [
"^build"
],
"outputs": [
"bunTestsDist/**"
]
},
"test:e2e": {
"dependsOn": ["^build"],
"outputs": ["coverage/**"]