@@ -9,30 +9,108 @@ if (process.env.CHILD_PROCESS === 'true') {
99 assert . fail ( 'boom' ) ;
1010 } ) ;
1111
12- test ( 'fail with message object' , { expectFailure : { message : 'reason object' } } , ( ) => {
12+ test ( 'fail with label object' , { expectFailure : { label : 'reason object' } } , ( ) => {
1313 assert . fail ( 'boom' ) ;
1414 } ) ;
1515
16- test ( 'fail with validation regex' , { expectFailure : { with : / b o o m / } } , ( ) => {
16+ test ( 'fail with match regex' , { expectFailure : { match : / b o o m / } } , ( ) => {
1717 assert . fail ( 'boom' ) ;
1818 } ) ;
1919
20- test ( 'fail with validation object' , { expectFailure : { with : { message : 'boom' } } } , ( ) => {
20+ test ( 'fail with match object' , { expectFailure : { match : { message : 'boom' } } } , ( ) => {
2121 assert . fail ( 'boom' ) ;
2222 } ) ;
2323
24- test ( 'fail with validation class' , { expectFailure : { with : assert . AssertionError } } , ( ) => {
24+ test ( 'fail with match class' , { expectFailure : { match : assert . AssertionError } } , ( ) => {
2525 assert . fail ( 'boom' ) ;
2626 } ) ;
2727
28- test ( 'fail with validation error (wrong error)' , { expectFailure : { with : / b a n g / } } , ( ) => {
28+ test ( 'fail with match error (wrong error)' , { expectFailure : { match : / b a n g / } } , ( ) => {
2929 assert . fail ( 'boom' ) ; // Should result in real failure because error doesn't match
3030 } ) ;
3131
3232 test ( 'unexpected pass' , { expectFailure : true } , ( ) => {
3333 // Should result in real failure because it didn't fail
3434 } ) ;
3535
36+ test ( 'fail with empty string' , { expectFailure : '' } , ( ) => {
37+ assert . fail ( 'boom' ) ;
38+ } ) ;
39+
40+ // 1. Matcher: RegExp
41+ test ( 'fails with regex matcher' , { expectFailure : / e x p e c t e d e r r o r / } , ( ) => {
42+ throw new Error ( 'this is the expected error' ) ;
43+ } ) ;
44+
45+ test ( 'fails with regex matcher (mismatch)' , { expectFailure : / e x p e c t e d e r r o r / } , ( ) => {
46+ throw new Error ( 'wrong error' ) ; // Should fail the test
47+ } ) ;
48+
49+ // 2. Matcher: Class
50+ test ( 'fails with class matcher' , { expectFailure : RangeError } , ( ) => {
51+ throw new RangeError ( 'out of bounds' ) ;
52+ } ) ;
53+
54+ test ( 'fails with class matcher (mismatch)' , { expectFailure : RangeError } , ( ) => {
55+ throw new TypeError ( 'wrong type' ) ; // Should fail the test
56+ } ) ;
57+
58+ // 3. Matcher: Object (Properties)
59+ test ( 'fails with object matcher' , { expectFailure : { code : 'ERR_TEST' } } , ( ) => {
60+ const err = new Error ( 'boom' ) ;
61+ err . code = 'ERR_TEST' ;
62+ throw err ;
63+ } ) ;
64+
65+ test ( 'fails with object matcher (mismatch)' , { expectFailure : { code : 'ERR_TEST' } } , ( ) => {
66+ const err = new Error ( 'boom' ) ;
67+ err . code = 'ERR_WRONG' ;
68+ throw err ; // Should fail
69+ } ) ;
70+
71+ // 4. Configuration Object: Reason + Validation
72+ test ( 'fails with config object (label + match)' , {
73+ expectFailure : {
74+ label : 'Bug #124' ,
75+ match : / b o o m /
76+ }
77+ } , ( ) => {
78+ throw new Error ( 'boom' ) ;
79+ } ) ;
80+
81+ test ( 'fails with config object (label only)' , {
82+ expectFailure : { label : 'Bug #125' }
83+ } , ( ) => {
84+ throw new Error ( 'boom' ) ;
85+ } ) ;
86+
87+ test ( 'fails with config object (match only)' , {
88+ expectFailure : { match : / b o o m / }
89+ } , ( ) => {
90+ throw new Error ( 'boom' ) ;
91+ } ) ;
92+
93+ // 5. Edge Case: Empty Object (Should throw ERR_INVALID_ARG_VALUE during creation)
94+ try {
95+ test ( 'invalid empty object' , { expectFailure : { } } , ( ) => { } ) ;
96+ } catch ( e ) {
97+ console . log ( `CAUGHT_INVALID_ARG: ${ e . code } ` ) ;
98+ }
99+
100+ // 6. Primitives and Truthiness
101+ test ( 'fails with boolean true' , { expectFailure : true } , ( ) => {
102+ throw new Error ( 'any error' ) ;
103+ } ) ;
104+
105+ // 7. Unexpected Pass (Enhanced)
106+ test ( 'unexpected pass (reason string)' , { expectFailure : 'should fail' } , ( ) => {
107+ // Pass
108+ } ) ;
109+
110+ test ( 'unexpected pass (matcher)' , { expectFailure : / b o o m / } , ( ) => {
111+ // Pass
112+ } ) ;
113+
36114} else {
37115 const child = spawn ( process . execPath , [ '--test-reporter' , 'tap' , __filename ] , {
38116 env : { ...process . env , CHILD_PROCESS : 'true' } ,
@@ -47,10 +125,30 @@ if (process.env.CHILD_PROCESS === 'true') {
47125 // We expect exit code 1 because 'unexpected pass' and 'wrong error' should fail the test run
48126 assert . strictEqual ( code , 1 ) ;
49127
50- // Check outputs
51- assert . match ( stdout , / # E X P E C T E D F A I L U R E r e a s o n s t r i n g / ) ;
52- assert . match ( stdout , / # E X P E C T E D F A I L U R E r e a s o n o b j e c t / ) ;
53- assert . match ( stdout , / n o t o k \d + - f a i l w i t h v a l i d a t i o n e r r o r \( w r o n g e r r o r \) / ) ;
54- assert . match ( stdout , / n o t o k \d + - u n e x p e c t e d p a s s / ) ;
128+ assert . match ( stdout , / o k \d + - f a i l w i t h m e s s a g e s t r i n g # E X P E C T E D F A I L U R E r e a s o n s t r i n g / ) ;
129+ assert . match ( stdout , / o k \d + - f a i l w i t h l a b e l o b j e c t # E X P E C T E D F A I L U R E r e a s o n o b j e c t / ) ;
130+ assert . match ( stdout , / o k \d + - f a i l w i t h m a t c h r e g e x # E X P E C T E D F A I L U R E / ) ;
131+ assert . match ( stdout , / o k \d + - f a i l w i t h m a t c h o b j e c t # E X P E C T E D F A I L U R E / ) ;
132+ assert . match ( stdout , / o k \d + - f a i l w i t h m a t c h c l a s s # E X P E C T E D F A I L U R E / ) ;
133+ assert . match ( stdout , / n o t o k \d + - f a i l w i t h m a t c h e r r o r \( w r o n g e r r o r \) # E X P E C T E D F A I L U R E / ) ;
134+ assert . match ( stdout , / n o t o k \d + - u n e x p e c t e d p a s s # E X P E C T E D F A I L U R E / ) ;
135+ assert . match ( stdout , / o k \d + - f a i l w i t h e m p t y s t r i n g # E X P E C T E D F A I L U R E / ) ;
136+
137+ // New tests verification
138+ assert . match ( stdout , / o k \d + - f a i l s w i t h r e g e x m a t c h e r # E X P E C T E D F A I L U R E / ) ;
139+ assert . match ( stdout , / n o t o k \d + - f a i l s w i t h r e g e x m a t c h e r \( m i s m a t c h \) # E X P E C T E D F A I L U R E / ) ;
140+ assert . match ( stdout , / o k \d + - f a i l s w i t h c l a s s m a t c h e r # E X P E C T E D F A I L U R E / ) ;
141+ assert . match ( stdout , / n o t o k \d + - f a i l s w i t h c l a s s m a t c h e r \( m i s m a t c h \) # E X P E C T E D F A I L U R E / ) ;
142+ assert . match ( stdout , / o k \d + - f a i l s w i t h o b j e c t m a t c h e r # E X P E C T E D F A I L U R E / ) ;
143+ assert . match ( stdout , / n o t o k \d + - f a i l s w i t h o b j e c t m a t c h e r \( m i s m a t c h \) # E X P E C T E D F A I L U R E / ) ;
144+ assert . match ( stdout , / o k \d + - f a i l s w i t h c o n f i g o b j e c t \( l a b e l \+ m a t c h \) # E X P E C T E D F A I L U R E B u g \\ # 1 2 4 / ) ;
145+ assert . match ( stdout , / o k \d + - f a i l s w i t h c o n f i g o b j e c t \( l a b e l o n l y \) # E X P E C T E D F A I L U R E B u g \\ # 1 2 5 / ) ;
146+ assert . match ( stdout , / o k \d + - f a i l s w i t h c o n f i g o b j e c t \( m a t c h o n l y \) # E X P E C T E D F A I L U R E / ) ;
147+ assert . match ( stdout , / o k \d + - f a i l s w i t h b o o l e a n t r u e # E X P E C T E D F A I L U R E / ) ;
148+ assert . match ( stdout , / n o t o k \d + - u n e x p e c t e d p a s s \( r e a s o n s t r i n g \) # E X P E C T E D F A I L U R E s h o u l d f a i l / ) ;
149+ assert . match ( stdout , / n o t o k \d + - u n e x p e c t e d p a s s \( m a t c h e r \) # E X P E C T E D F A I L U R E / ) ;
150+
151+ // Empty object error
152+ assert . match ( stdout , / C A U G H T _ I N V A L I D _ A R G : E R R _ I N V A L I D _ A R G _ V A L U E / ) ;
55153 } ) ) ;
56154}
0 commit comments