Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Apr 26, 2024
1 parent 0d27258 commit 6dbf85b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/browser/fixtures/benchmark/basic.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { bench, describe } from 'vitest'

describe('suite-a', () => {
bench('good', async () => {
await sleep(10)
}, options)

bench('bad', async () => {
await sleep(300)
}, options)
})

describe('suite-b', () => {
bench('good', async () => {
await sleep(25)
}, options)

describe('suite-b-nested', () => {
bench('good', async () => {
await sleep(50)
}, options)
})
})

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

const options = {
time: 0,
iterations: 2,
warmupIterations: 0,
warmupTime: 0,
}
17 changes: 17 additions & 0 deletions test/browser/fixtures/benchmark/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vitest/config'

const provider = process.env.PROVIDER || 'playwright'
const name =
process.env.BROWSER || (provider === 'playwright' ? 'chromium' : 'chrome')

export default defineConfig({
test: {
browser: {
enabled: true,
provider,
name,
},
},
cacheDir: fileURLToPath(new URL("./node_modules/.vite", import.meta.url)),
})
19 changes: 19 additions & 0 deletions test/browser/specs/benchmark.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import { startVitest } from 'vitest/node'

test('benchmark', async () => {
await fs.promises.rm('fixtures/benchmark/bench.json', { force: true })
await startVitest('benchmark', [], {
watch: false,
root: 'fixtures/benchmark',
browser: { headless: true },
benchmark: {
reporters: ['json'],
outputFile: 'bench.json',
},
})
const benchJson = JSON.parse(await fs.promises.readFile('fixtures/benchmark/bench.json', 'utf-8'))
assert.equal(benchJson.testResults['suite-a'][0].name, 'good')
})

0 comments on commit 6dbf85b

Please sign in to comment.