|
1 | 1 | import * as assert from 'node:assert/strict'; |
2 | 2 | import { spawn } from 'node:child_process'; |
3 | 3 | import { EventEmitter } from 'node:events'; |
| 4 | +import * as fs from 'node:fs'; |
| 5 | +import * as os from 'node:os'; |
4 | 6 | import * as path from 'node:path'; |
5 | 7 | import * as sinon from 'sinon'; |
6 | 8 | import * as vscode from 'vscode'; |
@@ -133,16 +135,34 @@ suite('CLI Service Test Suite', () => { |
133 | 135 | test('CLI service performs a real search', async function () { |
134 | 136 | this.timeout(5000); // Increase timeout to 5 seconds |
135 | 137 |
|
136 | | - const service = new RenamifyCliService(); |
| 138 | + // Create a temporary test directory with a small file to search |
| 139 | + const testDir = path.join(os.tmpdir(), `renamify-test-${Date.now()}`); |
| 140 | + fs.mkdirSync(testDir, { recursive: true }); |
137 | 141 |
|
138 | | - // Test basic search with default case styles |
139 | | - const results = await service.search('test', { |
140 | | - caseStyles: ['original'], |
141 | | - }); |
| 142 | + // Create a test file with searchable content |
| 143 | + const testFile = path.join(testDir, 'test.txt'); |
| 144 | + fs.writeFileSync(testFile, 'This is a test file with test content'); |
| 145 | + |
| 146 | + // Change to test directory to limit search scope |
| 147 | + const originalCwd = process.cwd(); |
| 148 | + process.chdir(testDir); |
| 149 | + |
| 150 | + try { |
| 151 | + const service = new RenamifyCliService(); |
142 | 152 |
|
143 | | - // Results should be a Plan object |
144 | | - assert.ok(results.id, 'Plan should have an ID'); |
145 | | - assert.ok(Array.isArray(results.matches), 'Matches should be an array'); |
| 153 | + // Test basic search with default case styles |
| 154 | + const results = await service.search('test', { |
| 155 | + caseStyles: ['original'], |
| 156 | + }); |
| 157 | + |
| 158 | + // Results should be a Plan object |
| 159 | + assert.ok(results.id, 'Plan should have an ID'); |
| 160 | + assert.ok(Array.isArray(results.matches), 'Matches should be an array'); |
| 161 | + } finally { |
| 162 | + // Restore original directory and clean up |
| 163 | + process.chdir(originalCwd); |
| 164 | + fs.rmSync(testDir, { recursive: true, force: true }); |
| 165 | + } |
146 | 166 | }); |
147 | 167 |
|
148 | 168 | test('CLI service uses --only-styles argument correctly', async () => { |
|
0 commit comments