diff --git a/docs/api/index.md b/docs/api/index.md index f6a4f1a5a574..00438ed8fadf 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -296,6 +296,23 @@ You can use `bench.skip` syntax to skip running certain benchmarks. }) ``` +### bench.only + +- **Type:** `(name: string, fn: BenchFunction, options?: BenchOptions) => void` + +Use `bench.only` to only run certain benchmarks in a given suite. This is useful when debugging. + + ```ts + import { bench } from 'vitest' + + bench.only('normal sorting', () => { + const x = [1, 5, 4, 2, 3] + x.sort((a, b) => { + return a - b + }) + }) + ``` + ## describe When you use `test` or `bench` in the top level of file, they are collected as part of the implicit suite for it. Using `describe` you can define a new suite in the current context, as a set of related tests or benchmarks and other nested suites. A suite lets you organize your tests and benchmarks so reports are more clear. diff --git a/packages/vitest/src/runtime/run.ts b/packages/vitest/src/runtime/run.ts index 44e747b6b427..19b468eaa05e 100644 --- a/packages/vitest/src/runtime/run.ts +++ b/packages/vitest/src/runtime/run.ts @@ -238,8 +238,9 @@ export async function runSuite(suite: Suite) { else { try { const beforeAllCleanups = await callSuiteHook(suite, suite, 'beforeAll', [suite]) + if (isRunningInBenchmark()) { - await runBenchmarkSuit(suite) + await runBenchmarkSuite(suite) } else { for (let tasksGroup of partitionSuiteChildren(suite)) { @@ -301,13 +302,16 @@ function createBenchmarkResult(name: string): BenchmarkResult { } as BenchmarkResult } -async function runBenchmarkSuit(suite: Suite) { +async function runBenchmarkSuite(suite: Suite) { const { Task, Bench } = await importTinybench() const start = performance.now() const benchmarkGroup = [] const benchmarkSuiteGroup = [] for (const task of suite.tasks) { + if (task.mode !== 'run') + continue + if (task.type === 'benchmark') benchmarkGroup.push(task) else if (task.type === 'suite') @@ -315,7 +319,7 @@ async function runBenchmarkSuit(suite: Suite) { } if (benchmarkSuiteGroup.length) - await Promise.all(benchmarkSuiteGroup.map(subSuite => runBenchmarkSuit(subSuite))) + await Promise.all(benchmarkSuiteGroup.map(subSuite => runBenchmarkSuite(subSuite))) if (benchmarkGroup.length) { const defer = createDefer() diff --git a/packages/vitest/src/runtime/suite.ts b/packages/vitest/src/runtime/suite.ts index b373ed2d0a19..21dfc7498564 100644 --- a/packages/vitest/src/runtime/suite.ts +++ b/packages/vitest/src/runtime/suite.ts @@ -116,7 +116,7 @@ function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, m }) const benchmark = createBenchmark(function (name: string, fn = noop, options: BenchOptions) { - const mode = this.skip ? 'skip' : 'run' + const mode = this.only ? 'only' : this.skip ? 'skip' : 'run' if (!isRunningInBenchmark()) throw new Error('`bench()` is only available in benchmark mode. Run with `vitest bench` instead.') @@ -251,14 +251,14 @@ function createTest(fn: ( function createBenchmark(fn: ( ( - this: Record<'skip', boolean | undefined>, + this: Record<'skip' | 'only', boolean | undefined>, name: string, fn: BenchFunction, options: BenchOptions ) => void )) { const benchmark = createChainable( - ['skip'], + ['skip', 'only'], fn, ) as BenchmarkAPI diff --git a/packages/vitest/src/types/benchmark.ts b/packages/vitest/src/types/benchmark.ts index 01cb9adce672..a661ecd4e79a 100644 --- a/packages/vitest/src/types/benchmark.ts +++ b/packages/vitest/src/types/benchmark.ts @@ -53,7 +53,7 @@ export interface BenchmarkResult extends TinybenchResult { export type BenchFunction = (this: BenchFactory) => Promise | void export type BenchmarkAPI = ChainableFunction< -'skip', +'skip' | 'only', [name: string, fn: BenchFunction, options?: BenchOptions], void > & { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7e2d87b8db3d..1d42d38bef14 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3157,6 +3157,23 @@ packages: requiresBuild: true optional: true + /@eslint/eslintrc/1.3.1: + resolution: {integrity: sha512-OhSY22oQQdw3zgPOOwdoj01l/Dzl1Z+xyUP33tkSN+aqyEhymJCcPHyXt+ylW8FSe0TfRC2VG+ROQOapD0aZSQ==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dependencies: + ajv: 6.12.6 + debug: 4.3.4 + espree: 9.4.0 + globals: 13.17.0 + ignore: 5.2.0 + import-fresh: 3.3.0 + js-yaml: 4.1.0 + minimatch: 3.1.2 + strip-json-comments: 3.1.1 + transitivePeerDependencies: + - supports-color + dev: true + /@eslint/eslintrc/1.3.2: resolution: {integrity: sha512-AXYd23w1S/bv3fTs3Lz0vjiYemS08jWkI3hYyS9I1ry+0f+Yjs1wm+sU0BS8qDOPrBIkp4qHYC16I8uVtpLajQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -3337,7 +3354,7 @@ packages: dependencies: '@types/istanbul-lib-coverage': 2.0.4 '@types/istanbul-reports': 3.0.1 - '@types/node': 18.7.17 + '@types/node': 18.7.18 '@types/yargs': 15.0.14 chalk: 4.1.2 dev: true @@ -3349,7 +3366,7 @@ packages: '@jest/schemas': 29.0.0 '@types/istanbul-lib-coverage': 2.0.4 '@types/istanbul-reports': 3.0.1 - '@types/node': 18.7.17 + '@types/node': 18.7.18 '@types/yargs': 17.0.12 chalk: 4.1.2 dev: true @@ -3862,7 +3879,7 @@ packages: engines: {node: '>=14'} hasBin: true dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 playwright-core: 1.25.1 dev: true @@ -5050,7 +5067,7 @@ packages: '@babel/preset-env': 7.18.10_@babel+core@7.18.13 '@babel/types': 7.18.13 '@mdx-js/mdx': 1.6.22 - '@types/lodash': 4.14.185 + '@types/lodash': 4.14.184 js-string-escape: 1.0.1 loader-utils: 2.0.2 lodash: 4.17.21 @@ -5070,7 +5087,7 @@ packages: '@babel/types': 7.18.13 '@mdx-js/mdx': 1.6.22 '@mdx-js/react': 1.6.22_react@17.0.2 - '@types/lodash': 4.14.185 + '@types/lodash': 4.14.184 js-string-escape: 1.0.1 loader-utils: 2.0.2 lodash: 4.17.21 @@ -5627,7 +5644,7 @@ packages: /@types/cheerio/0.22.31: resolution: {integrity: sha512-Kt7Cdjjdi2XWSfrZ53v4Of0wG3ZcmaegFXjMmz9tfNrZSkzzo36G0AL1YqSdcIA78Etjt6E609pt5h1xnQkPUw==} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 dev: true /@types/codemirror/5.60.5: @@ -5639,7 +5656,7 @@ packages: /@types/concat-stream/1.6.1: resolution: {integrity: sha512-eHE4cQPoj6ngxBZMvVf6Hw7Mh4jMW4U9lpGmS5GBPB9RYxlFg+CHaVN7ErNY4W9XfLIEn20b4VDYaIrbq0q4uA==} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 dev: true /@types/cookie/0.4.1: @@ -5668,7 +5685,7 @@ packages: resolution: {integrity: sha512-xryQlOEIe1TduDWAOphR0ihfebKFSWOXpIsk+70JskCfRfW+xALdnJ0r1ZOTo85F9Qsjk6vtlU7edTYHbls9tA==} dependencies: '@types/cheerio': 0.22.31 - '@types/react': 18.0.19 + '@types/react': 18.0.20 dev: true /@types/eslint-scope/3.7.4: @@ -5699,33 +5716,33 @@ packages: /@types/form-data/0.0.33: resolution: {integrity: sha512-8BSvG1kGm83cyJITQMZSulnl6QV8jqAGreJsc5tPu1Jq0vTSOiY/k24Wx82JRpWwZSqrala6sd5rWi6aNXvqcw==} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 dev: true /@types/fs-extra/9.0.13: resolution: {integrity: sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 dev: true /@types/glob/7.2.0: resolution: {integrity: sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==} dependencies: '@types/minimatch': 5.1.1 - '@types/node': 18.7.17 + '@types/node': 18.7.18 dev: true /@types/glob/8.0.0: resolution: {integrity: sha512-l6NQsDDyQUVeoTynNpC9uRvCUint/gSUXQA2euwmTuWGvPY5LSDUu6tkCtJB2SvGQlJQzLaKqcGZP4//7EDveA==} dependencies: '@types/minimatch': 5.1.1 - '@types/node': 18.7.17 + '@types/node': 18.7.18 dev: true /@types/graceful-fs/4.1.5: resolution: {integrity: sha512-anKkLmZZ+xm4p8JWBf4hElkM4XR+EZeA2M9BAkkTldmcyDY4mbdIJnRghDJH3Ov5ooY7/UAoENtmdMSkaAd7Cw==} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 dev: true /@types/hast/2.3.4: @@ -5786,7 +5803,7 @@ packages: /@types/jsdom/20.0.0: resolution: {integrity: sha512-YfAchFs0yM1QPDrLm2VHe+WHGtqms3NXnXAMolrgrVP6fgBHHXy1ozAbo/dFtPNtZC/m66bPiCTWYmqp1F14gA==} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 '@types/tough-cookie': 4.0.2 parse5: 7.0.0 dev: true @@ -5799,6 +5816,10 @@ packages: resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} dev: true + /@types/lodash/4.14.184: + resolution: {integrity: sha512-RoZphVtHbxPZizt4IcILciSWiC6dcn+eZ8oX9IWEYfDMcocdd42f7NPI6fQj+6zI8y4E0L7gu2pcZKLGTRaV9Q==} + dev: true + /@types/lodash/4.14.185: resolution: {integrity: sha512-evMDG1bC4rgQg4ku9tKpuMh5iBNEwNa3tf9zRHdP1qlv+1WUg44xat4IxCE14gIpZRGUUWAx2VhItCZc25NfMA==} dev: true @@ -5830,7 +5851,7 @@ packages: /@types/node-fetch/2.6.2: resolution: {integrity: sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 form-data: 3.0.1 dev: true @@ -5854,10 +5875,6 @@ packages: resolution: {integrity: sha512-EQHhixfu+mkqHMZl1R2Ovuvn47PUw18azMJOTwSZr9/fhzHNGXAJ0ma0dayRVchprpCj0Kc1K1xKoWaATWF1qg==} dev: true - /@types/node/18.7.17: - resolution: {integrity: sha512-0UyfUnt02zIuqp7yC8RYtDkp/vo8bFaQ13KkSEvUAohPOAlnVNbj5Fi3fgPSuwzakS+EvvnnZ4x9y7i6ASaSPQ==} - dev: true - /@types/node/18.7.18: resolution: {integrity: sha512-m+6nTEOadJZuTPkKR/SYK3A2d7FZrgElol9UP1Kae90VVU4a6mxnPuLiIW1m4Cq4gZ/nWb9GrdVXJCoCazDAbg==} dev: true @@ -5915,7 +5932,7 @@ packages: /@types/react-is/17.0.3: resolution: {integrity: sha512-aBTIWg1emtu95bLTLx0cpkxwGW3ueZv71nE2YFBpL8k/z5czEW8yYpOo8Dp+UUAFAtKwNaOsh/ioSeQnWlZcfw==} dependencies: - '@types/react': 18.0.19 + '@types/react': 18.0.20 dev: false /@types/react-test-renderer/17.0.2: @@ -5927,7 +5944,7 @@ packages: /@types/react-transition-group/4.4.5: resolution: {integrity: sha512-juKD/eiSM3/xZYzjuzH6ZwpP+/lejltmiS3QEzV/vmb/Q8+HfDmxu+Baga8UEMGBqV88Nbg4l2hY/K2DkyaLLA==} dependencies: - '@types/react': 18.0.19 + '@types/react': 18.0.20 dev: false /@types/react/17.0.49: @@ -5938,25 +5955,17 @@ packages: csstype: 3.1.0 dev: true - /@types/react/18.0.19: - resolution: {integrity: sha512-BDc3Q+4Q3zsn7k9xZrKfjWyJsSlEDMs38gD1qp2eDazLCdcPqAT+vq1ND+Z8AGel/UiwzNUk8ptpywgNQcJ1MQ==} - dependencies: - '@types/prop-types': 15.7.5 - '@types/scheduler': 0.16.2 - csstype: 3.1.0 - /@types/react/18.0.20: resolution: {integrity: sha512-MWul1teSPxujEHVwZl4a5HxQ9vVNsjTchVA+xRqv/VYGCuKGAU6UhfrTdF5aBefwD1BHUD8i/zq+O/vyCm/FrA==} dependencies: '@types/prop-types': 15.7.5 '@types/scheduler': 0.16.2 csstype: 3.1.0 - dev: true /@types/resolve/1.17.1: resolution: {integrity: sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 dev: true /@types/scheduler/0.16.2: @@ -5965,7 +5974,7 @@ packages: /@types/set-cookie-parser/2.4.2: resolution: {integrity: sha512-fBZgytwhYAUkj/jC/FAV4RQ5EerRup1YQsXQCh8rZfiHkc4UahC192oH0smGwsXol3cL3A5oETuAHeQHmhXM4w==} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 dev: true /@types/sinonjs__fake-timers/8.1.1: @@ -6035,7 +6044,7 @@ packages: /@types/webpack-sources/3.2.0: resolution: {integrity: sha512-Ft7YH3lEVRQ6ls8k4Ff1oB4jN6oy/XmU6tQISKdhfh+1mR+viZFphS6WL0IrtDOzvefmJg5a0s7ZQoRXwqTEFg==} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 '@types/source-list-map': 0.1.2 source-map: 0.7.4 dev: true @@ -6043,7 +6052,7 @@ packages: /@types/webpack/4.41.32: resolution: {integrity: sha512-cb+0ioil/7oz5//7tZUSwbrSAN/NWHrQylz5cW8G0dWTcF/g+/dSdMlKVZspBYuMAN1+WnwHrkxiRrLcwd0Heg==} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 '@types/tapable': 1.0.8 '@types/uglify-js': 3.17.0 '@types/webpack-sources': 3.2.0 @@ -6054,7 +6063,7 @@ packages: /@types/ws/8.5.3: resolution: {integrity: sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 dev: true /@types/yargs-parser/21.0.0: @@ -6077,7 +6086,7 @@ packages: resolution: {integrity: sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==} requiresBuild: true dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 dev: true optional: true @@ -8667,7 +8676,7 @@ packages: dev: true /concat-map/0.0.1: - resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} /concat-stream/1.6.2: resolution: {integrity: sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==} @@ -10500,7 +10509,7 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} hasBin: true dependencies: - '@eslint/eslintrc': 1.3.2 + '@eslint/eslintrc': 1.3.1 '@humanwhocodes/config-array': 0.9.5 ajv: 6.12.6 chalk: 4.1.2 @@ -12886,7 +12895,7 @@ packages: dependencies: '@jest/types': 26.6.2 '@types/graceful-fs': 4.1.5 - '@types/node': 18.7.17 + '@types/node': 18.7.18 anymatch: 3.1.2 fb-watchman: 2.0.1 graceful-fs: 4.2.10 @@ -12954,7 +12963,7 @@ packages: resolution: {integrity: sha512-S5wqyz0DXnNJPd/xfIzZ5Xnp1HrJWBczg8mMfMpN78OJ5eDxXyf+Ygld9wX1DnUWbIbhM1YDY95NjR4CBXkb2g==} engines: {node: '>= 10.14.2'} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 graceful-fs: 4.2.10 dev: true @@ -12963,7 +12972,7 @@ packages: engines: {node: '>= 10.14.2'} dependencies: '@jest/types': 26.6.2 - '@types/node': 18.7.17 + '@types/node': 18.7.18 chalk: 4.1.2 graceful-fs: 4.2.10 is-ci: 2.0.0 @@ -12975,7 +12984,7 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@jest/types': 29.0.1 - '@types/node': 18.7.17 + '@types/node': 18.7.18 chalk: 4.1.2 ci-info: 3.3.2 graceful-fs: 4.2.10 @@ -12986,7 +12995,7 @@ packages: resolution: {integrity: sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ==} engines: {node: '>= 10.13.0'} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 merge-stream: 2.0.0 supports-color: 7.2.0 dev: true @@ -12995,7 +13004,7 @@ packages: resolution: {integrity: sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==} engines: {node: '>= 10.13.0'} dependencies: - '@types/node': 18.7.17 + '@types/node': 18.7.18 merge-stream: 2.0.0 supports-color: 8.1.1 dev: true @@ -17343,10 +17352,17 @@ packages: engines: {node: '>=8'} dev: true + /strip-literal/0.4.0: + resolution: {integrity: sha512-ql/sBDoJOybTKSIOWrrh8kgUEMjXMwRAkZTD0EwiwxQH/6tTPkZvMIEjp0CRlpi6V5FMiJyvxeRkEi1KrGISoA==} + dependencies: + acorn: 8.8.0 + dev: true + /strip-literal/0.4.1: resolution: {integrity: sha512-z+F/xmDM8GOdvA5UoZXFxEnxdvMOZ+XEBIwjfLfc8hMSuHpGxjXAUCfuEo+t1GOHSb8+qgI/IBRpxXVMaABYWA==} dependencies: acorn: 8.8.0 + dev: false /style-loader/1.3.0_webpack@4.46.0: resolution: {integrity: sha512-V7TCORko8rs9rIqkSrlMfkqA63DfoGBBJmK1kKGCcSi+BWb4cqz0SRsnp4l6rU5iwOEd0/2ePv68SV22VXon4Q==} @@ -18224,13 +18240,13 @@ packages: dependencies: '@rollup/pluginutils': 4.2.1 escape-string-regexp: 5.0.0 - fast-glob: 3.2.12 + fast-glob: 3.2.11 local-pkg: 0.4.2 magic-string: 0.26.3 mlly: 0.5.14 pathe: 0.3.5 scule: 0.3.2 - strip-literal: 0.4.1 + strip-literal: 0.4.0 unplugin: 0.9.5_rollup@2.79.0+vite@3.1.0 transitivePeerDependencies: - esbuild @@ -18244,13 +18260,13 @@ packages: dependencies: '@rollup/pluginutils': 4.2.1 escape-string-regexp: 5.0.0 - fast-glob: 3.2.12 + fast-glob: 3.2.11 local-pkg: 0.4.2 magic-string: 0.26.3 mlly: 0.5.14 pathe: 0.3.5 scule: 0.3.2 - strip-literal: 0.4.1 + strip-literal: 0.4.0 unplugin: 0.9.5_vite@3.1.0 transitivePeerDependencies: - esbuild @@ -18783,7 +18799,7 @@ packages: debug: 4.3.4 deep-equal: 2.0.5 extract-comments: 1.1.0 - fast-glob: 3.2.12 + fast-glob: 3.2.11 json5: 2.2.1 local-pkg: 0.4.2 picocolors: 1.0.0 diff --git a/test/benchmark/test.mjs b/test/benchmark/test.mjs index d46c0fea4a0b..e402b9964998 100644 --- a/test/benchmark/test.mjs +++ b/test/benchmark/test.mjs @@ -2,7 +2,7 @@ import { readFile } from 'fs/promises' import { execa } from 'execa' let error -await execa('npx', ['vitest', 'bench', 'base.bench', 'mode.bench'], { +await execa('npx', ['vitest', 'bench', 'base.bench', 'mode.bench', 'only.bench'], { env: { ...process.env, CI: 'true', @@ -18,6 +18,10 @@ const benchResult = await readFile('./bench.json', 'utf-8') if (benchResult.includes('skip')) process.exit(1) +const skippedBenches = ['s0', 's1', 's2', 's3', 'sb4', 's4'] +if (skippedBenches.some(b => benchResult.includes(b))) + process.exit(1) + if (error) { console.error(error) process.exit(1) diff --git a/test/benchmark/test/only.bench.ts b/test/benchmark/test/only.bench.ts new file mode 100644 index 000000000000..09bcee8e0218 --- /dev/null +++ b/test/benchmark/test/only.bench.ts @@ -0,0 +1,68 @@ +import assert from 'node:assert' +import { bench, describe, expect } from 'vitest' + +const run = [false, false, false, false, false] + +describe('a0', () => { + bench.only('0', () => { + run[0] = true + }) + bench('s0', () => { + expect(true).toBe(false) + }) +}) + +describe('a1', () => { + describe('b1', () => { + describe('c1', () => { + bench.only('1', () => { + run[1] = true + }) + }) + bench('s1', () => { + expect(true).toBe(false) + }) + }) +}) + +describe.only('a2', () => { + bench('2', () => { + run[2] = true + }) +}) + +bench('s2', () => { + expect(true).toBe(false) +}) + +describe.only('a3', () => { + describe('b3', () => { + bench('3', () => { + run[3] = true + }) + }) + bench.skip('s3', () => { + expect(true).toBe(false) + }) +}) + +describe('a4', () => { + describe.only('b4', () => { + bench('4', () => { + run[4] = true + }) + }) + describe('sb4', () => { + bench('s4', () => { + expect(true).toBe(false) + }) + }) +}) + +bench.only( + 'visited', + () => { + assert.deepEqual(run, [true, true, true, true, true]) + }, + { iterations: 1, time: 0 }, +) diff --git a/test/benchmark/vitest.config.ts b/test/benchmark/vitest.config.ts index 12a063a4dc15..457040d10279 100644 --- a/test/benchmark/vitest.config.ts +++ b/test/benchmark/vitest.config.ts @@ -3,6 +3,7 @@ import { defineConfig } from 'vitest/config' export default defineConfig({ test: { update: false, + allowOnly: true, benchmark: { outputFile: './bench.json', reporters: ['json'],