1- import { Client } from '../src/index.js'
1+ /**
2+ * End-to-end gauntlet: send every message type to one recipient and print a
3+ * pass/fail report. Useful for smoke-testing a build against a real account.
4+ *
5+ * Run: TO=628xxxx@s.whatsapp.net GAP_MS=1500 bun run examples/e2e-gauntlet.ts
6+ */
27import type { WAMessageKey } from 'baileys'
8+ import { Client } from '../src/index.js'
39
4- const TARGET = process . env [ 'GAUNTLET_TO ' ] ?? ''
5- const GAP_MS = Number ( process . env [ 'GAUNTLET_GAP ' ] ?? 1500 )
10+ const TO = process . env [ 'TO ' ] ?? ''
11+ const GAP_MS = Number ( process . env [ 'GAP_MS ' ] ?? 1500 )
612
7- if ( ! TARGET ) {
8- console . error ( 'Set GAUNTLET_TO to a recipient jid , e.g. GAUNTLET_TO =628xxxx@s.whatsapp.net bun run examples/e2e-gauntlet.ts' )
13+ if ( ! TO ) {
14+ console . error ( 'Set TO , e.g. TO =628xxxx@s.whatsapp.net bun run examples/e2e-gauntlet.ts' )
915 process . exit ( 1 )
1016}
1117
@@ -41,8 +47,10 @@ const results: Result[] = []
4147
4248const client = new Client ( { ignoreMe : true } )
4349
50+ client . on ( 'qr' , ( { qrString } ) => console . log ( 'Scan QR:' , qrString ) )
51+
4452client . on ( 'connect' , async ( { me } ) => {
45- console . log ( ' Connected as' , me . id , '\n=== E2E gauntlet -> ' , TARGET , '===\n' )
53+ console . log ( ` Connected as ${ me . id } — running E2E gauntlet against ${ TO } \n` )
4654
4755 const video = await fetchBuf ( 'https://www.w3schools.com/html/mov_bbb.mp4' )
4856 const audio = await fetchBuf ( 'https://www.w3schools.com/html/horse.mp3' )
@@ -54,59 +62,59 @@ client.on('connect', async ({ me }) => {
5462 const run = async ( feature : string , fn : ( ) => unknown , skip = false ) : Promise < void > => {
5563 if ( skip ) {
5664 results . push ( { feature, status : 'SKIP' , detail : 'asset unavailable' } )
57- console . log ( `SKIP ${ feature } (asset unavailable)` )
65+ console . log ( `– ${ feature } (asset unavailable)` )
5866 return
5967 }
6068 try {
6169 const key = ( await ( fn ( ) as unknown as Promise < WAMessageKey | void > ) ) as WAMessageKey | undefined
6270 const id = key && typeof key === 'object' && 'id' in key ? String ( key . id ) : 'ok'
6371 results . push ( { feature, status : 'OK' , detail : id } )
64- console . log ( `OK ${ feature } ( ${ id } ) ` )
72+ console . log ( `✓ ${ feature } → ${ id } ` )
6573 } catch ( e ) {
66- const msg = e instanceof Error ? e . message : String ( e )
67- results . push ( { feature, status : 'FAIL' , detail : msg } )
68- console . log ( `FAIL ${ feature } -> ${ msg } ` )
74+ const detail = e instanceof Error ? e . message : String ( e )
75+ results . push ( { feature, status : 'FAIL' , detail } )
76+ console . log ( `✗ ${ feature } → ${ detail } ` )
6977 }
7078 await sleep ( GAP_MS )
7179 }
7280
7381 await run ( 'text' , async ( ) => {
74- anchor = await client . send ( TARGET ) . text ( 'zaileys e2e: text ✅' )
82+ anchor = await client . send ( TO ) . text ( 'zaileys e2e: text ✅' )
7583 return anchor
7684 } )
77- await run ( 'text + mentions' , ( ) => client . send ( TARGET ) . text ( 'zaileys e2e: mentions ✅' ) . mentions ( [ TARGET ] ) )
85+ await run ( 'text + mentions' , ( ) => client . send ( TO ) . text ( 'zaileys e2e: mentions ✅' ) . mentions ( [ TO ] ) )
7886 await run ( 'reply (quote)' , async ( ) => {
7987 if ( ! anchor ) throw new Error ( 'no anchor' )
8088 const full = await client . store . getMessage ( anchor )
81- return client . send ( TARGET ) . text ( 'zaileys e2e: reply ✅' ) . reply ( full ?? anchor )
89+ return client . send ( TO ) . text ( 'zaileys e2e: reply ✅' ) . reply ( full ?? anchor )
8290 } )
8391 await run ( 'react 👍' , ( ) => ( anchor ? client . react ( anchor , '👍' ) : Promise . reject ( new Error ( 'no anchor' ) ) ) )
84- await run ( 'image (real png)' , ( ) => client . send ( TARGET ) . image ( realImage , { caption : 'zaileys e2e: image ✅' } ) )
85- await run ( 'sticker (real webp)' , ( ) => client . send ( TARGET ) . sticker ( realSticker ) )
86- await run ( 'document (txt inline)' , ( ) => client . send ( TARGET ) . document ( DOC_BYTES , { fileName : 'zaileys-e2e.txt' , mimetype : 'text/plain' , caption : 'doc ✅' } ) )
87- await run ( 'video (fetched mp4)' , ( ) => client . send ( TARGET ) . video ( video as Buffer , { caption : 'zaileys e2e: video ✅' } ) , video === null )
88- await run ( 'gif (video gifPlayback)' , ( ) => client . send ( TARGET ) . video ( video as Buffer , { caption : 'gif ✅' , gifPlayback : true } ) , video === null )
89- await run ( 'audio (fetched mp3)' , ( ) => client . send ( TARGET ) . audio ( audio as Buffer ) , audio === null )
90- await run ( 'voice note (ptt)' , ( ) => client . send ( TARGET ) . audio ( audio as Buffer , { ptt : true } ) , audio === null )
91- await run ( 'album (2 images)' , ( ) => client . send ( TARGET ) . album ( [
92+ await run ( 'image (real png)' , ( ) => client . send ( TO ) . image ( realImage , { caption : 'zaileys e2e: image ✅' } ) )
93+ await run ( 'sticker (real webp)' , ( ) => client . send ( TO ) . sticker ( realSticker ) )
94+ await run ( 'document (txt inline)' , ( ) => client . send ( TO ) . document ( DOC_BYTES , { fileName : 'zaileys-e2e.txt' , mimetype : 'text/plain' , caption : 'doc ✅' } ) )
95+ await run ( 'video (fetched mp4)' , ( ) => client . send ( TO ) . video ( video as Buffer , { caption : 'zaileys e2e: video ✅' } ) , video === null )
96+ await run ( 'gif (video gifPlayback)' , ( ) => client . send ( TO ) . video ( video as Buffer , { caption : 'gif ✅' , gifPlayback : true } ) , video === null )
97+ await run ( 'audio (fetched mp3)' , ( ) => client . send ( TO ) . audio ( audio as Buffer ) , audio === null )
98+ await run ( 'voice note (ptt)' , ( ) => client . send ( TO ) . audio ( audio as Buffer , { ptt : true } ) , audio === null )
99+ await run ( 'album (2 images)' , ( ) => client . send ( TO ) . album ( [
92100 { type : 'image' , src : realImage , caption : 'album 1' } ,
93101 { type : 'image' , src : realImage , caption : 'album 2' } ,
94102 ] ) )
95- await run ( 'location' , ( ) => client . send ( TARGET ) . location ( - 6.2 , 106.816666 , { name : 'Jakarta' , address : 'Indonesia' } ) )
96- await run ( 'contact (vcard)' , ( ) => client . send ( TARGET ) . contact ( VCARD ) )
97- await run ( 'poll' , ( ) => client . send ( TARGET ) . poll ( 'zaileys e2e poll?' , [ 'A' , 'B' , 'C' ] , { multipleChoice : false } ) )
98- await run ( 'buttons' , ( ) => client . send ( TARGET ) . buttons ( [ { id : 'b1' , text : 'Yes' } , { id : 'b2' , text : 'No' } ] , { text : 'zaileys e2e: buttons' , footer : 'pick one' } ) )
99- await run ( 'list' , ( ) => client . send ( TARGET ) . list ( {
103+ await run ( 'location' , ( ) => client . send ( TO ) . location ( - 6.2 , 106.816666 , { name : 'Jakarta' , address : 'Indonesia' } ) )
104+ await run ( 'contact (vcard)' , ( ) => client . send ( TO ) . contact ( VCARD ) )
105+ await run ( 'poll' , ( ) => client . send ( TO ) . poll ( 'zaileys e2e poll?' , [ 'A' , 'B' , 'C' ] , { multipleChoice : false } ) )
106+ await run ( 'buttons' , ( ) => client . send ( TO ) . buttons ( [ { id : 'b1' , text : 'Yes' } , { id : 'b2' , text : 'No' } ] , { text : 'zaileys e2e: buttons' , footer : 'pick one' } ) )
107+ await run ( 'list' , ( ) => client . send ( TO ) . list ( {
100108 title : 'zaileys e2e list' , description : 'choose' , buttonText : 'Open' , footerText : 'footer' ,
101109 sections : [ { title : 'Section' , rows : [ { id : 'r1' , title : 'Row 1' , description : 'first' } , { id : 'r2' , title : 'Row 2' } ] } ] ,
102110 } ) )
103- await run ( 'forward' , ( ) => ( anchor ? client . forward ( anchor , TARGET ) : Promise . reject ( new Error ( 'no anchor' ) ) ) )
111+ await run ( 'forward' , ( ) => ( anchor ? client . forward ( anchor , TO ) : Promise . reject ( new Error ( 'no anchor' ) ) ) )
104112 await run ( 'edit' , async ( ) => {
105113 if ( ! anchor ) throw new Error ( 'no anchor' )
106114 await client . edit ( anchor ) . text ( 'zaileys e2e: text ✅ (edited)' )
107115 } )
108116 await run ( 'delete (for everyone)' , async ( ) => {
109- const k = await client . send ( TARGET ) . text ( 'zaileys e2e: this will be deleted' )
117+ const k = await client . send ( TO ) . text ( 'zaileys e2e: this will be deleted' )
110118 await sleep ( 800 )
111119 await client . delete ( k )
112120 } )
0 commit comments