Skip to content

Commit 3826941

Browse files
authored
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

Lines changed: 7 additions & 4 deletions
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,
Lines changed: 7 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy