@@ -10,6 +10,17 @@ export type { MailpitClient }
1010
1111type Message = Awaited < ReturnType < MailpitClient [ 'getMessageSummary' ] > >
1212
13+ function resolveAgainstPlaywrightBaseUrl ( url : string ) : string {
14+ const baseUrl = process . env . PLAYWRIGHT_BASE_URL
15+ if ( ! baseUrl ) {
16+ return url
17+ }
18+
19+ const parsedUrl = new URL ( url )
20+ const targetUrl = new URL ( `${ parsedUrl . pathname } ${ parsedUrl . search } ${ parsedUrl . hash } ` , baseUrl )
21+ return targetUrl . toString ( )
22+ }
23+
1324/** Creates a MailpitClient using MAILPIT_URL (default: http://localhost:8025). */
1425export function createMailpitClient ( ) : MailpitClient {
1526 const defaultUrl = existsSync ( '/.dockerenv' )
@@ -65,7 +76,12 @@ export async function waitForEmailTo(
6576/** Extracts a LibreSign sign link from an email body matching /p/sign/{uuid}. */
6677export function extractSignLink ( body : string ) : string | null {
6778 const match = body . match ( / \S + \/ p \/ s i g n \/ [ \w - ] + / )
68- return match ? match [ 0 ] : null
79+ if ( ! match ) {
80+ return null
81+ }
82+
83+ const parsedUrl = new URL ( match [ 0 ] )
84+ return `${ parsedUrl . pathname } ${ parsedUrl . search } ${ parsedUrl . hash } `
6985}
7086
7187/** Extracts a numeric token from an email body. Default pattern: 4-8 digit sequence. */
@@ -80,5 +96,5 @@ export function extractTokenFromEmail(
8096/** Extracts the first URL from an email body (email.Text). */
8197export function extractLinkFromEmail ( body : string ) : string | null {
8298 const match = body . match ( / h t t p s ? : \/ \/ \S + / )
83- return match ? match [ 0 ] : null
99+ return match ? resolveAgainstPlaywrightBaseUrl ( match [ 0 ] ) : null
84100}
0 commit comments