11import { stripAnsi } from '@socketsecurity/lib/ansi'
2+ import { CI } from '@socketsecurity/lib/env/ci'
23import {
34 applyShimmer ,
45 DIR_LTR ,
56 DIR_NONE ,
67 type ShimmerState ,
78} from '@socketsecurity/lib/effects/text-shimmer'
8- import { beforeEach , describe , expect , it , vi } from 'vitest'
9+ import { beforeEach , describe , expect , it } from 'vitest'
910
1011describe ( 'text-shimmer' , ( ) => {
1112 describe ( 'applyShimmer()' , ( ) => {
@@ -21,57 +22,64 @@ describe('text-shimmer', () => {
2122 } as ShimmerState
2223 } )
2324
24- describe ( 'CI environment' , ( ) => {
25- it ( 'should disable shimmer effect when CI is true' , async ( ) => {
26- // Mock CI environment
27- vi . doMock ( '#env/ci' , ( ) => ( { CI : true } ) )
28- const { applyShimmer : applyShimmerCI } = await import (
29- '@socketsecurity/lib/effects/text-shimmer'
30- )
31-
25+ describe ( 'CI environment behavior' , ( ) => {
26+ it ( 'should handle shimmer correctly in CI' , ( ) => {
3227 const text = 'Test text'
33- const result = applyShimmerCI ( text , state , {
28+ const result = applyShimmer ( text , state , {
3429 color : [ 140 , 82 , 255 ] as const ,
3530 direction : DIR_LTR ,
3631 } )
3732
38- // Result should be colored but not have shimmer animation codes
33+ // Result should be colored
3934 const stripped = stripAnsi ( result )
4035 expect ( stripped ) . toBe ( text )
4136
42- // Should contain color codes but not varying intensity
37+ // Should contain color codes
4338 expect ( result ) . toContain ( '\x1b[38;2;' )
4439 expect ( result ) . toContain ( '140;82;255' )
4540
46- vi . doUnmock ( '#env/ci' )
41+ // In CI: step should not advance (shimmer disabled)
42+ // In non-CI: step should advance (shimmer enabled)
43+ if ( CI ) {
44+ expect ( state . step ) . toBe ( 0 )
45+ } else {
46+ expect ( state . step ) . toBeGreaterThan ( 0 )
47+ }
4748 } )
4849
49- it ( 'should return static colored text in CI regardless of direction' , async ( ) => {
50- // Mock CI environment
51- vi . doMock ( '#env/ci' , ( ) => ( { CI : true } ) )
52- const { applyShimmer : applyShimmerCI } = await import (
53- '@socketsecurity/lib/effects/text-shimmer'
54- )
55-
50+ it ( 'should handle all directions correctly in CI' , ( ) => {
5651 const text = 'Test'
5752 const directions = [ DIR_LTR , 'rtl' , 'bi' , 'random' ] as const
5853
5954 for ( const dir of directions ) {
60- const result = applyShimmerCI ( text , state , {
55+ const testState : ShimmerState = {
56+ currentDir : DIR_LTR ,
57+ mode : DIR_LTR ,
58+ speed : 1 / 3 ,
59+ step : 0 ,
60+ }
61+
62+ const result = applyShimmer ( text , testState , {
6163 color : [ 255 , 0 , 0 ] as const ,
6264 direction : dir ,
6365 } )
6466
6567 const stripped = stripAnsi ( result )
6668 expect ( stripped ) . toBe ( text )
67- }
6869
69- vi . doUnmock ( '#env/ci' )
70+ // In CI: step should not advance (shimmer disabled)
71+ // In non-CI: step should advance (shimmer enabled)
72+ if ( CI ) {
73+ expect ( testState . step ) . toBe ( 0 )
74+ } else {
75+ expect ( testState . step ) . toBeGreaterThan ( 0 )
76+ }
77+ }
7078 } )
7179 } )
7280
73- describe ( 'non-CI environment ' , ( ) => {
74- it ( 'should apply shimmer effect when CI is false ' , ( ) => {
81+ describe ( 'shimmer animation behavior ' , ( ) => {
82+ it ( 'should apply color and respect CI environment ' , ( ) => {
7583 const text = 'Test'
7684 const result = applyShimmer ( text , state , {
7785 color : [ 140 , 82 , 255 ] as const ,
@@ -82,9 +90,17 @@ describe('text-shimmer', () => {
8290 expect ( result ) . toContain ( '\x1b[38;2;' )
8391 // Result should have the original text when stripped
8492 expect ( stripAnsi ( result ) ) . toBe ( text )
93+
94+ // In CI: step should not advance (shimmer disabled)
95+ // In non-CI: step should advance (shimmer enabled)
96+ if ( CI ) {
97+ expect ( state . step ) . toBe ( 0 )
98+ } else {
99+ expect ( state . step ) . toBeGreaterThan ( 0 )
100+ }
85101 } )
86102
87- it ( 'should animate shimmer position across frames ' , ( ) => {
103+ it ( 'should animate shimmer position based on environment ' , ( ) => {
88104 const text = 'Testing'
89105 const state1 : ShimmerState = {
90106 currentDir : DIR_LTR ,
@@ -98,19 +114,24 @@ describe('text-shimmer', () => {
98114 direction : DIR_LTR ,
99115 } )
100116
101- // Step should advance
102- expect ( state1 . step ) . toBe ( 1 )
117+ if ( CI ) {
118+ // In CI: step should not advance (shimmer disabled)
119+ expect ( state1 . step ) . toBe ( 0 )
120+ } else {
121+ // In non-CI: step should advance (shimmer enabled)
122+ expect ( state1 . step ) . toBe ( 1 )
103123
104- const result2 = applyShimmer ( text , state1 , {
105- color : [ 140 , 82 , 255 ] as const ,
106- direction : DIR_LTR ,
107- } )
124+ const result2 = applyShimmer ( text , state1 , {
125+ color : [ 140 , 82 , 255 ] as const ,
126+ direction : DIR_LTR ,
127+ } )
108128
109- // Step should advance again
110- expect ( state1 . step ) . toBe ( 2 )
129+ // Step should advance again
130+ expect ( state1 . step ) . toBe ( 2 )
111131
112- // Results should be different due to shimmer position change
113- expect ( result1 ) . not . toBe ( result2 )
132+ // Results should be different due to shimmer position change
133+ expect ( result1 ) . not . toBe ( result2 )
134+ }
114135 } )
115136 } )
116137
@@ -127,16 +148,29 @@ describe('text-shimmer', () => {
127148 expect ( stripAnsi ( result ) ) . toBe ( text )
128149 } )
129150
130- it ( 'should apply LTR direction shimmer' , ( ) => {
151+ it ( 'should apply LTR direction shimmer based on environment ' , ( ) => {
131152 const text = 'Test'
132- const result = applyShimmer ( text , state , {
153+ const testState : ShimmerState = {
154+ currentDir : DIR_LTR ,
155+ mode : DIR_LTR ,
156+ speed : 1 / 3 ,
157+ step : 0 ,
158+ }
159+
160+ const result = applyShimmer ( text , testState , {
133161 color : [ 140 , 82 , 255 ] as const ,
134162 direction : DIR_LTR ,
135163 } )
136164
137- // Step should advance
138- expect ( state . step ) . toBeGreaterThan ( 0 )
139165 expect ( stripAnsi ( result ) ) . toBe ( text )
166+
167+ // In CI: step should not advance (shimmer disabled)
168+ // In non-CI: step should advance (shimmer enabled)
169+ if ( CI ) {
170+ expect ( testState . step ) . toBe ( 0 )
171+ } else {
172+ expect ( testState . step ) . toBeGreaterThan ( 0 )
173+ }
140174 } )
141175 } )
142176
0 commit comments