@@ -80,8 +80,12 @@ describe('respectLatest functionality', () => {
80
80
expect ( shouldRespectVersion ( '^1.0.0' ) ) . toBe ( false )
81
81
} )
82
82
83
- it ( 'should test dependency file respectLatest logic' , async ( ) => {
84
- // Create test deps.yaml with dynamic versions
83
+ it ( 'should test dependency file respectLatest logic' , async ( ) => {
84
+ // Test the dependency file respectLatest logic directly without file system operations
85
+ // This avoids the file corruption issue in GitHub Actions environment
86
+ const { updateDependencyFile, isDependencyFile } = await import ( '../src/utils/dependency-file-parser' )
87
+
88
+ // Create test deps.yaml content
85
89
const depsYaml = `dependencies:
86
90
python.org: "*"
87
91
node: "latest"
@@ -93,27 +97,7 @@ devDependencies:
93
97
prettier: "^3.0.0"
94
98
`
95
99
96
- const depsPath = path . join ( testDir , 'deps.yaml' )
97
-
98
- // Ensure no composer.json exists in the test directory
99
- const composerPath = path . join ( testDir , 'composer.json' )
100
- if ( fs . existsSync ( composerPath ) ) {
101
- fs . rmSync ( composerPath , { force : true } )
102
- }
103
-
104
- // Write the file and ensure it's synced
105
- fs . writeFileSync ( depsPath , depsYaml )
106
- fs . fsyncSync ( fs . openSync ( depsPath , 'r' ) )
107
-
108
- // Small delay to ensure file system operations complete
109
- await new Promise ( resolve => setTimeout ( resolve , 10 ) )
110
-
111
- // Ensure the file was written correctly and verify content
112
- const actualFileContent = fs . readFileSync ( depsPath , 'utf-8' )
113
- expect ( actualFileContent ) . toBe ( depsYaml ) // Verify file content is correct
114
-
115
- // Test the dependency file respectLatest logic
116
- const { updateDependencyFile, isDependencyFile } = await import ( '../src/utils/dependency-file-parser' )
100
+ const depsPath = 'deps.yaml' // Use relative path for testing
117
101
118
102
// Verify file detection works correctly
119
103
expect ( isDependencyFile ( depsPath ) ) . toBe ( true )
@@ -138,44 +122,9 @@ devDependencies:
138
122
} ,
139
123
]
140
124
141
- // Debug info for CI troubleshooting - Check before calling updateDependencyFile
142
- console . log ( '🔍 Test setup verification:' )
143
- console . log ( ' - File path:' , depsPath )
144
- console . log ( ' - File exists:' , fs . existsSync ( depsPath ) )
145
- console . log ( ' - Original content preview:' , actualFileContent . substring ( 0 , 100 ) )
146
- console . log ( ' - isDependencyFile result:' , isDependencyFile ( depsPath ) )
147
- console . log ( ' - Content is YAML format:' , ! actualFileContent . trim ( ) . startsWith ( '{' ) )
148
-
149
125
// Test that dynamic versions are respected (not updated)
150
- // Use the verified file content directly to avoid any file reading issues
151
- const updatedContent = await updateDependencyFile ( depsPath , actualFileContent , updates )
152
-
153
- // Debug info for CI troubleshooting
154
- if ( ! updatedContent . includes ( 'python.org: "*"' ) ) {
155
- console . log ( '🚨 Expected deps.yaml format, but got different format:' )
156
- console . log ( 'Input content length:' , actualFileContent . length )
157
- console . log ( 'Input content preview:' , actualFileContent . substring ( 0 , 200 ) )
158
- console . log ( 'Output content length:' , updatedContent . length )
159
- console . log ( 'Output content preview:' , updatedContent . substring ( 0 , 500 ) )
160
- console . log ( 'Content types match:' , typeof actualFileContent , typeof updatedContent )
161
-
162
- // Check if the file path is being resolved correctly
163
- const absolutePath = path . resolve ( depsPath )
164
- console . log ( 'Absolute path:' , absolutePath )
165
- console . log ( 'Working directory:' , process . cwd ( ) )
166
-
167
- // Check if there are any interfering files
168
- console . log ( 'Files in test directory:' )
169
- const testDirFiles = fs . readdirSync ( testDir )
170
- testDirFiles . forEach ( f => console . log ( ` - ${ f } ` ) )
171
-
172
- // Check if there are any composer files in the working directory
173
- const workingDirFiles = fs . readdirSync ( process . cwd ( ) )
174
- const composerFiles = workingDirFiles . filter ( f => f . includes ( 'composer' ) )
175
- if ( composerFiles . length > 0 ) {
176
- console . log ( 'Composer files in working directory:' , composerFiles )
177
- }
178
- }
126
+ // Pass the content directly to avoid file system corruption
127
+ const updatedContent = await updateDependencyFile ( depsPath , depsYaml , updates )
179
128
180
129
// python.org should not be updated because it uses "*"
181
130
expect ( updatedContent ) . toContain ( 'python.org: "*"' )
0 commit comments