File tree 2 files changed +21
-1
lines changed
packages/vitest/src/node/plugins
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import type { Plugin } from 'vite'
2
2
import MagicString from 'magic-string'
3
3
import { getCallLastIndex } from '../../utils'
4
4
5
- const hoistRegexp = / ^ * \b ( (?: v i t e s t | v i ) \s * .\s * ( m o c k | u n m o c k ) \( [ " ` ' \s ] + ( .* [ @ \w _ - ] + ) [ " ` ' \s ] + ) [ ) , ] { 1 } ; ? / gm
5
+ const hoistRegexp = / ^ [ \t ] * \b ( (?: v i t e s t | v i ) \s * .\s * ( m o c k | u n m o c k ) \( [ " ` ' \s ] + ( .* [ @ \w _ - ] + ) [ " ` ' \s ] + ) [ ) , ] { 1 } ; ? / gm
6
6
const vitestRegexp = / i m p o r t { [ ^ } ] * } .* (? = [ " ' ` ] v i t e s t [ " ` ' ] ) .* / gm
7
7
8
8
export function hoistMocks ( code : string ) {
Original file line number Diff line number Diff line change
1
+ /* eslint-disable eslint-comments/no-unlimited-disable */
2
+ /* eslint-disable */
3
+ import { expect , test , vi } from 'vitest'
4
+ import { join as joinPath } from 'node:path'
5
+
6
+ const helloWorld = ( ) => {
7
+ return joinPath ( 'hello' , 'world' )
8
+ }
9
+
10
+ test ( 'Are you mocking me?' , ( ) => {
11
+ // note there are NO indents in this file
12
+ // except the next line
13
+ // test pass with spaces, test fails with tab
14
+ vi . mock ( 'node:path' , ( ) => {
15
+ return {
16
+ join : vi . fn ( ) . mockReturnValue ( 'goodbye world' )
17
+ }
18
+ } )
19
+ expect ( helloWorld ( ) ) . toBe ( 'goodbye world' )
20
+ } )
You can’t perform that action at this time.
0 commit comments