-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
feat: browserIssues and PRs related to the browser runnerIssues and PRs related to the browser runnerp2-nice-to-haveNot breaking anything but nice to have (priority)Not breaking anything but nice to have (priority)
Description
Describe the bug
Need the importmap available for non-js resources like SVG and HTML to be resolved natively by import.meta.resolve( path ).
For some reasin in vitest browser runner the usual plugin with transformIndexHtml to inject importmap script manually does not work.
Advised in vitejs/vite#2483 method of injecting script via browser.testerScripts is not applicable as a) import maps requires script type="importmap", b) it is injected after stateScript which causes "import maps injected after module use" error. Following request, openingthe bug on vitest.
Root cause:
- Declarative Custom Element is HTML-centric and needs support for
importmapfor use byimport.meta.resolve( path )API. Vitest in browser does not support import maps. - vitest browser run uses static HTML instead of loading by
vitebuild and altering it afterwards - using vitest to run the StoryBook interactive tests for TDD on visual components (React and Web Components). The StoryBook is not supported by vitest browser run, had to do a bit of tricks.
Solving on any level from $subj to root causes, better all, would be beneficial for frameworks and reusable libs authors.
Reproduction
<script type="importmap">
{
"imports": {
"embed-lib": "./demo/lib-dir/embed-lib.html"
}
}
</script>const url = import.meta.resolve( 'embed-lib' );
expect( url ).to.include( 'embed-lib.html' );System Info
System:
OS: Windows 11 10.0.22621
CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-1260P
Memory: 1.31 GB / 15.69 GB
Binaries:
Node: 20.8.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD
npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
pnpm: 9.0.6 - C:\Program Files\nodejs\pnpm.CMD
Browsers:
Edge: Chromium (127.0.2651.74)
Internet Explorer: 11.0.22621.3527
npmPackages:
@vitest/browser: ^1.6.0 => 1.6.0
@vitest/coverage-istanbul: ^1.6.0 => 1.6.0
vite: ^5.3.1 => 5.3.1
vitest: ^1.6.0 => 1.6.0Used Package Manager
yarn
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feat: browserIssues and PRs related to the browser runnerIssues and PRs related to the browser runnerp2-nice-to-haveNot breaking anything but nice to have (priority)Not breaking anything but nice to have (priority)
Type
Projects
Status
Approved