-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vitest): use development/production conditions when resolving ext…
…ernal modules (#4980)
- Loading branch information
1 parent
7d9f673
commit 8877e22
Showing
14 changed files
with
123 additions
and
3 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
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ packages: | |
- packages/* | ||
- examples/* | ||
- test/* | ||
- test/config/fixtures/conditions-pkg |
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 as condition } from 'subpackage' |
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,9 @@ | ||
{ | ||
"name": "conditions", | ||
"private": true, | ||
"type": "module", | ||
"main": "index.js", | ||
"dependencies": { | ||
"subpackage": "file:../conditions-subpackage" | ||
} | ||
} |
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 'custom' |
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 @@ | ||
throw new Error('Should not be imported') |
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 'development' |
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,13 @@ | ||
{ | ||
"name": "subpackage", | ||
"private": true, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"custom": "./custom.js", | ||
"development": "./development.js", | ||
"production": "./production.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 'production' |
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 '../conditions-pkg'; | ||
|
||
test('condition is correct', () => { | ||
expect(condition).toBe(TEST_CONDITION) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { expect, test } from 'vitest' | ||
import { runVitest } from '../../test-utils' | ||
|
||
test('correctly imports external dependencies with a development condition', async () => { | ||
// dev condition is the default | ||
const { stderr } = await runVitest({ | ||
root: 'fixtures/conditions-test', | ||
server: { | ||
deps: { | ||
external: [/conditions-pkg/], | ||
}, | ||
}, | ||
}, [], 'test', { | ||
define: { | ||
TEST_CONDITION: '"development"', | ||
}, | ||
}) | ||
|
||
expect(stderr).toBe('') | ||
}) | ||
|
||
test('correctly imports external dependencies with a production condition', async () => { | ||
// this is the only check in Vite for "isProduction" value | ||
process.env.NODE_ENV = 'production' | ||
|
||
const { stderr } = await runVitest({ | ||
root: 'fixtures/conditions-test', | ||
server: { | ||
deps: { | ||
external: [/conditions-pkg/], | ||
}, | ||
}, | ||
}, [], 'test', { | ||
define: { | ||
TEST_CONDITION: '"production"', | ||
}, | ||
}) | ||
|
||
expect(stderr).toBe('') | ||
}) | ||
|
||
test('correctly imports external dependencies with a custom condition', async () => { | ||
delete process.env.NODE_ENV | ||
|
||
const { stderr } = await runVitest({ | ||
root: 'fixtures/conditions-test', | ||
server: { | ||
deps: { | ||
external: [/conditions-pkg/], | ||
}, | ||
}, | ||
}, [], 'test', { | ||
resolve: { | ||
conditions: ['custom'], | ||
}, | ||
define: { | ||
TEST_CONDITION: '"custom"', | ||
}, | ||
}) | ||
|
||
expect(stderr).toBe('') | ||
}) |
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