File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,16 @@ export class WebContainer extends FileSystem {
1616 constructor ( ) {
1717 super ( ) ;
1818
19- this . _isReady = WebContainerApi . boot ( { } ) . then ( ( instance ) => {
20- this . _instancePromise = instance ;
19+ this . _isReady = new Promise ( ( resolve , reject ) => {
20+ const timeout = setTimeout ( ( ) => {
21+ reject ( new Error ( "WebContainer boot timed out in 30s" ) ) ;
22+ } , 30_000 ) ;
23+
24+ WebContainerApi . boot ( { } ) . then ( ( instance ) => {
25+ clearTimeout ( timeout ) ;
26+ this . _instancePromise = instance ;
27+ resolve ( ) ;
28+ } ) ;
2129 } ) ;
2230 }
2331
Original file line number Diff line number Diff line change 1+ import { WebContainer as WebContainerApi } from "@webcontainer/api" ;
2+ import { expect , test , vi } from "vitest" ;
3+
4+ import { WebContainer } from "../src/fixtures/webcontainer" ;
5+
6+ test ( "throws when WebContainer boot timeouts" , async ( ) => {
7+ vi . spyOn ( WebContainerApi , "boot" ) . mockReturnValue ( new Promise ( ( ) => null ) ) ;
8+ vi . useFakeTimers ( ) ;
9+
10+ const webcontainer = new WebContainer ( ) ;
11+ vi . advanceTimersByTime ( 30_000 ) ;
12+
13+ await expect ( webcontainer . wait ( ) ) . rejects . toThrowErrorMatchingInlineSnapshot (
14+ `[Error: WebContainer boot timed out in 30s]` ,
15+ ) ;
16+ } ) ;
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ export default defineConfig({
55 plugins : [ vitestWebcontainers ( ) ] ,
66
77 test : {
8+ reporters : "verbose" ,
9+
810 browser : {
911 enabled : true ,
1012 provider : "playwright" ,
You can’t perform that action at this time.
0 commit comments