File tree 2 files changed +14
-4
lines changed
packages/vitest/src/utils
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -57,10 +57,13 @@ export async function groupFilesByEnv(
57
57
file ,
58
58
)
59
59
60
- const envOptions = JSON . parse (
61
- code . match ( / @ (?: v i t e s t | j e s t ) - e n v i r o n m e n t - o p t i o n s \s + ?( .+ ) / ) ?. [ 1 ]
62
- || 'null' ,
63
- )
60
+ let envOptionsJson = code . match ( / @ (?: v i t e s t | j e s t ) - e n v i r o n m e n t - o p t i o n s \s + ( .+ ) / ) ?. [ 1 ]
61
+ if ( envOptionsJson ?. endsWith ( '*/' ) ) {
62
+ // Trim closing Docblock characters the above regex might have captured
63
+ envOptionsJson = envOptionsJson . slice ( 0 , - 2 )
64
+ }
65
+
66
+ const envOptions = JSON . parse ( envOptionsJson || 'null' )
64
67
const envKey = env === 'happy-dom' ? 'happyDOM' : env
65
68
const environment : ContextTestEnvironment = {
66
69
name : env as VitestEnvironment ,
Original file line number Diff line number Diff line change
1
+ /** @vitest -environment jsdom */
2
+
3
+ /** @vitest -environment-options { "url": "https://example.com/" } */
4
+
5
+ import { expect , it } from 'vitest'
6
+
7
+ it ( 'parse single line environment options' , ( ) => expect ( location . href ) . toBe ( 'https://example.com/' ) )
You can’t perform that action at this time.
0 commit comments