Skip to content

Commit 3826941

Browse files
authoredJul 15, 2024··
fix: one-line environment options (#5105)
1 parent 81b8d67 commit 3826941

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed
 

‎packages/vitest/src/utils/test-helpers.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ export async function groupFilesByEnv(
5757
file,
5858
)
5959

60-
const envOptions = JSON.parse(
61-
code.match(/@(?:vitest|jest)-environment-options\s+?(.+)/)?.[1]
62-
|| 'null',
63-
)
60+
let envOptionsJson = code.match(/@(?:vitest|jest)-environment-options\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')
6467
const envKey = env === 'happy-dom' ? 'happyDOM' : env
6568
const environment: ContextTestEnvironment = {
6669
name: env as VitestEnvironment,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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/'))

0 commit comments

Comments
 (0)
Please sign in to comment.