forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: re-apply default conditions if using vite 6 or later (vitest-dev…
…#7071) Co-authored-by: thebanjomatic <[email protected]> Co-authored-by: Hiroshi Ogawa <[email protected]>
- Loading branch information
1 parent
b526896
commit 84287fc
Showing
13 changed files
with
83 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as vite from 'vite' | ||
|
||
type Vite6Options = typeof vite & Partial<{ | ||
defaultServerConditions?: string[] | ||
}> | ||
|
||
/** | ||
* In Vite 6+, providing a value for resolve.conditions overrides the defaults | ||
* In Vite 5, passing ["node"] will be merged with the defaults | ||
* | ||
* @returns the appropriate conditions array depending on the vite version | ||
* | ||
*/ | ||
export function getDefaultServerConditions() { | ||
return (vite as Vite6Options).defaultServerConditions ?? ['node'] | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
export default 'default' |
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 @@ | ||
export default 'module' |
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 @@ | ||
export default 'node' |
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,12 @@ | ||
{ | ||
"name": "@vitest/test-dep-conditions", | ||
"type": "module", | ||
"private": true, | ||
"exports": { | ||
".": { | ||
"module": "./module.js", | ||
"node": "./node.js", | ||
"default": "./default.js" | ||
} | ||
} | ||
} |
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 @@ | ||
export default 'module' |
6 changes: 6 additions & 0 deletions
6
test/config/fixtures/default-conditions/default-conditions.test.js
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,6 @@ | ||
import { test, expect } from 'vitest'; | ||
import condition from '@vitest/test-dep-conditions'; | ||
|
||
test('condition is correct', () => { | ||
expect(condition).toBe('module') | ||
}) |
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,3 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({}) |
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,23 @@ | ||
import { expect, test } from 'vitest' | ||
import { runVitest } from '../../test-utils' | ||
|
||
test('"module" condition for external dep', async () => { | ||
const { stderr } = await runVitest({ | ||
root: 'fixtures/default-conditions', | ||
}) | ||
|
||
expect(stderr).toBe('') | ||
}) | ||
|
||
test('"module" condition for inline dep', async () => { | ||
const { stderr } = await runVitest({ | ||
root: 'fixtures/default-conditions', | ||
server: { | ||
deps: { | ||
inline: ['@vitest/test-dep-conditions'], | ||
}, | ||
}, | ||
}) | ||
|
||
expect(stderr).toBe('') | ||
}) |