-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(vitest): add mode in config tests
- Loading branch information
1 parent
b1ebcb3
commit 51b3c43
Showing
5 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { bench, describe } from 'vitest' | ||
|
||
describe('example', () => { | ||
bench('simple', () => { | ||
let _ = 0 | ||
_ += 1 | ||
}, { iterations: 1, time: 1, warmupIterations: 0, warmupTime: 0 }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
test('should pass', () => { | ||
expect(1).toBe(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig((env) => { | ||
if (env.mode !== 'benchmark') { | ||
console.error('env.mode: ', env.mode) | ||
throw new Error('env.mode should be equal to "benchmark"') | ||
} | ||
|
||
return ({}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig((env) => { | ||
if (env.mode !== 'test') { | ||
console.error('env.mode: ', env.mode) | ||
throw new Error('env.mode should be equal to "test"') | ||
} | ||
|
||
return ({}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import * as testUtils from '../../test-utils' | ||
|
||
describe.each([ | ||
{ mode: 'test', name: 'test' }, | ||
{ mode: 'bench', name: 'benchmark' }, | ||
] as const)('checking mode: $mode', ({ mode, name }) => { | ||
test(`env.mode should have the ${mode} value when running in ${name} mode`, async () => { | ||
const { stdout } = await testUtils.runVitestCli(...(mode === 'test' ? ['run'] : ['bench', '--run']), 'fixtures/mode', '-c', `fixtures/mode/vitest.${name}.config.ts`) | ||
|
||
expect(stdout).toContain(`✓ fixtures/mode/example.${mode}.ts`) | ||
}) | ||
|
||
test(`should return error when running vitest ${mode === 'test' ? 'bench' : 'run'}`, async () => { | ||
const { stdout, stderr } = await testUtils.runVitestCli(...(mode === 'bench' ? ['run'] : ['bench', '--run']), 'fixtures/mode', '-c', `fixtures/mode/vitest.${name}.config.ts`) | ||
|
||
expect(stderr).toContain(`env.mode: ${name === 'test' ? 'benchmark' : 'test'}`) | ||
expect(stderr).toContain('⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯') | ||
expect(stderr).toContain(`Error: env.mode should be equal to "${name}"`) | ||
expect(stdout).toBe('') | ||
}) | ||
}) |