-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vitest): pass correct mode in vitest config function (#4399)
- Loading branch information
1 parent
638c4fd
commit b8ca387
Showing
9 changed files
with
62 additions
and
6 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
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
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
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
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,23 @@ | ||
import { expect, test } from 'vitest' | ||
import * as testUtils from '../../test-utils' | ||
|
||
test.each([ | ||
{ expectedMode: 'test', command: ['run'] }, | ||
{ expectedMode: 'benchmark', command: ['bench', '--run'] }, | ||
])(`env.mode should have the $expectedMode value when running in $name mode`, async ({ command, expectedMode }) => { | ||
const { stdout } = await testUtils.runVitestCli(...(command), 'fixtures/mode', '-c', `fixtures/mode/vitest.${expectedMode}.config.ts`) | ||
|
||
expect(stdout).toContain(`✓ fixtures/mode/example.${expectedMode}.ts`) | ||
}) | ||
|
||
test.each([ | ||
{ expectedMode: 'test', command: ['bench', '--run'], actualMode: 'benchmark' }, | ||
{ expectedMode: 'benchmark', command: ['run'], actualMode: 'test' }, | ||
])(`should return error if actual mode $actualMode is different than expected mode $expectedMode`, async ({ command, expectedMode, actualMode }) => { | ||
const { stdout, stderr } = await testUtils.runVitestCli(...(command), 'fixtures/mode', '-c', `fixtures/mode/vitest.${expectedMode}.config.ts`) | ||
|
||
expect(stderr).toContain(`env.mode: ${actualMode}`) | ||
expect(stderr).toContain('⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯') | ||
expect(stderr).toContain(`Error: env.mode should be equal to "${expectedMode}"`) | ||
expect(stdout).toBe('') | ||
}) |