-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(vite-node): externalize network imports #4987
Merged
sheremet-va
merged 9 commits into
vitest-dev:main
from
hi-ogawa:fix-vite-node-externalize-network-imports
Jan 17, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cfdb38d
fix(vite-node): externalize network imports
hi-ogawa eb2f72a
ci: tweak playwright
hi-ogawa aa0d036
test: add network-imports test
hi-ogawa 3c99b8a
Revert "ci: tweak playwright"
hi-ogawa 74cce1f
test: tweak
hi-ogawa ab91ffc
test: use local server instead of esm.sh
hi-ogawa 3f934c8
Merge branch 'main' into fix-vite-node-externalize-network-imports
hi-ogawa e56382b
test: test forks + skip vmThreads
hi-ogawa 587b2bf
Merge remote-tracking branch 'origin/fix-vite-node-externalize-networ…
hi-ogawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ export default antfu( | |
'test/core/src/self', | ||
'test/workspaces/results.json', | ||
'test/reporters/fixtures/with-syntax-error.test.js', | ||
'test/network-imports/public/[email protected]', | ||
'examples/**/mockServiceWorker.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
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,11 @@ | ||
{ | ||
"name": "@vitest/test-network-imports", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest" | ||
}, | ||
"devDependencies": { | ||
"vitest": "workspace:*" | ||
} | ||
} |
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,11 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
// @ts-expect-error network imports | ||
import slash from 'http://localhost:9602/[email protected]' | ||
|
||
// test without local server | ||
// import slash from 'https://esm.sh/[email protected]' | ||
|
||
test('network imports', () => { | ||
expect(slash('foo\\bar')).toBe('foo/bar') | ||
}) |
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,24 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: { | ||
poolOptions: { | ||
threads: { | ||
execArgv: ['--experimental-network-imports'], | ||
}, | ||
forks: { | ||
execArgv: ['--experimental-network-imports'], | ||
}, | ||
// not supported? | ||
// FAIL test/basic.test.ts [ test/basic.test.ts ] | ||
// Error: ENOENT: no such file or directory, open 'http://localhost:9602/[email protected]' | ||
// ❯ Object.openSync node:fs:596:3 | ||
// ❯ readFileSync node:fs:464:35 | ||
vmThreads: { | ||
execArgv: ['--experimental-network-imports'], | ||
}, | ||
}, | ||
// let vite serve public/[email protected] | ||
api: 9602, | ||
}, | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it's not working on vmThreads. I'll investigate further to see if it's simply NodeJS limitation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think every import is delegated to our VM implementation, and it just doesn't support
http
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the hint! I haven't had a chance to look at how vmThreads works yet, so I'll look around a bit to get the idea.
I suppose it's still okay even if it doesn't work on vmThreads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can disable this test for vm threads/forks for now.
I think it's a separate feature request (maybe create an issue for it). Shouldn't be hard to implement.