1
1
import fs from "fs" ;
2
2
import path from "path" ;
3
3
import { test , expect } from "@playwright/test" ;
4
- import { setupDebugLog , setupProxy , resolveBinding } from "../support" ;
4
+ import {
5
+ setupDebugLog ,
6
+ setupProxy ,
7
+ setupUncaughtExceptionRejection ,
8
+ expectUncaughtException ,
9
+ resolveBinding ,
10
+ } from "../support" ;
5
11
6
12
if ( ! process . env . RUBY_NPM_PACKAGE_ROOT ) {
7
13
test . skip ( "skip" , ( ) => { } ) ;
8
14
} else {
9
- test . beforeEach ( async ( { context } ) => {
15
+ test . beforeEach ( async ( { context, page } ) => {
10
16
setupDebugLog ( context ) ;
11
- setupProxy ( context , ( route , relativePath , mockedPath ) => {
12
- if ( relativePath . match ( "fixtures" ) ) {
13
- route . fulfill ( {
14
- path : path . join ( "./test-e2e/integrations" , relativePath ) ,
15
- } ) ;
16
- } else if ( fs . existsSync ( mockedPath ) ) {
17
- route . fulfill ( {
18
- path : mockedPath ,
19
- } ) ;
20
- } else {
21
- route . fulfill ( {
22
- status : 404 ,
23
- } ) ;
24
- }
17
+ setupProxy ( context ) ;
18
+
19
+ context . route ( / f i x t u r e s / , ( route ) => {
20
+ const filename = path . basename ( route . request ( ) . url ( ) ) ;
21
+ route . fulfill ( {
22
+ path : path . join ( "./test-e2e/integrations/fixtures" , filename ) ,
23
+ } ) ;
24
+ } ) ;
25
+
26
+ context . route ( / n o t _ f o u n d / , ( route ) => {
27
+ route . fulfill ( {
28
+ status : 404 ,
29
+ } ) ;
25
30
} ) ;
31
+
32
+ setupUncaughtExceptionRejection ( page ) ;
26
33
} ) ;
27
34
28
35
test . describe ( "JS::RequireRemote#load" , ( ) => {
@@ -64,6 +71,8 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
64
71
test ( "JS::RequireRemote#load throws error when gem is not found" , async ( {
65
72
page,
66
73
} ) => {
74
+ expectUncaughtException ( page ) ;
75
+
67
76
// Opens the URL that will be used as the basis for determining the relative URL.
68
77
await page . goto (
69
78
"https://cdn.jsdelivr.net/npm/@ruby/head-wasm-wasi@latest/dist/" ,
@@ -73,12 +82,12 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
73
82
</script>
74
83
<script type="text/ruby" data-eval="async">
75
84
require 'js/require_remote'
76
- JS::RequireRemote.instance.load 'foo '
85
+ JS::RequireRemote.instance.load 'not_found '
77
86
</script>
78
87
` ) ;
79
88
80
89
const error = await page . waitForEvent ( "pageerror" ) ;
81
- expect ( error . message ) . toMatch ( / c a n n o t l o a d s u c h u r l - - .+ \/ f o o .r b / ) ;
90
+ expect ( error . message ) . toMatch ( / c a n n o t l o a d s u c h u r l - - .+ \/ n o t _ f o u n d .r b / ) ;
82
91
} ) ;
83
92
} ) ;
84
93
}
0 commit comments