Skip to content

Commit b8e8d40

Browse files
committed
fix: remove 20 blind setTimeout delays from batch organizer tests
organizeFolder() and organizeWorkspace() already await all file saves before returning. The 500ms/1000ms delays after them were unnecessary and slowed the test suite by ~8-10 seconds. Config update() also resolves when the config is written, so no delay needed there either.
1 parent 47a8e67 commit b8e8d40

1 file changed

Lines changed: 2 additions & 45 deletions

File tree

tests/unit/commands/batch-organizer.integration.test.ts

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
125125
// CALL THE REAL METHOD!
126126
await organizer.organizeFolder(tempWs.rootUri);
127127

128-
// Wait for file system to flush
129-
await new Promise(resolve => setTimeout(resolve, 500));
130-
131128
// Check logs for errors
132129
const logs = logger.lines.join('');
133130

@@ -173,8 +170,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
173170
// CALL THE REAL METHOD!
174171
await organizer.organizeFolder(tempWs.rootUri);
175172

176-
await new Promise(resolve => setTimeout(resolve, 500));
177-
178173
// Read modified content
179174
const after = fs.readFileSync(tempWs.fileUris[0].fsPath, 'utf-8');
180175
assert.ok(!after.includes("from './unused'"), 'Should have removed unused import');
@@ -214,8 +209,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
214209
// CALL THE REAL METHOD!
215210
await organizer.organizeFolder(tempWs.rootUri);
216211

217-
await new Promise(resolve => setTimeout(resolve, 500));
218-
219212
// Verify all files were processed
220213
for (const fileUri of tempWs.fileUris) {
221214
const content = fs.readFileSync(fileUri.fsPath, 'utf-8');
@@ -252,8 +245,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
252245
// CALL THE REAL METHOD!
253246
await organizer.organizeFolder(tempWs.rootUri);
254247

255-
await new Promise(resolve => setTimeout(resolve, 500));
256-
257248
// Verify all files were organized (sorted)
258249
const after1 = fs.readFileSync(tempWs.fileUris[0].fsPath, 'utf-8');
259250
const after2 = fs.readFileSync(tempWs.fileUris[1].fsPath, 'utf-8');
@@ -294,8 +285,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
294285
// CALL THE REAL METHOD! (should not crash)
295286
await organizer.organizeFolder(tempWs.rootUri);
296287

297-
await new Promise(resolve => setTimeout(resolve, 500));
298-
299288
// Valid files should be organized
300289
const after1 = fs.readFileSync(tempWs.fileUris[0].fsPath, 'utf-8');
301290
const after3 = fs.readFileSync(tempWs.fileUris[2].fsPath, 'utf-8');
@@ -332,8 +321,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
332321
// CALL THE REAL METHOD!
333322
await organizer.organizeWorkspace();
334323

335-
await new Promise(resolve => setTimeout(resolve, 500));
336-
337324
// Verify files were organized
338325
const after1 = fs.readFileSync(tempWs.fileUris[0].fsPath, 'utf-8');
339326
const after2 = fs.readFileSync(tempWs.fileUris[1].fsPath, 'utf-8');
@@ -371,8 +358,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
371358
// CALL THE REAL METHOD!
372359
await organizer.organizeFolder(tempWs.rootUri);
373360

374-
await new Promise(resolve => setTimeout(resolve, 500));
375-
376361
// Verify src/app.ts was organized
377362
const appContent = fs.readFileSync(tempWs.fileUris[0].fsPath, 'utf-8');
378363
assert.ok(appContent.indexOf("from './a'") < appContent.indexOf("from './b'"), 'src/app.ts should be organized');
@@ -413,19 +398,14 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
413398
await workspace.getConfiguration('miniTypescriptHero.imports', tempWs.rootUri)
414399
.update('excludePatterns', ['**/generated/**'], 1); // ConfigurationTarget.Global
415400

416-
// Wait for config to propagate
417-
await new Promise(resolve => setTimeout(resolve, 1000));
418-
419-
// Verify config was set
401+
// Verify config was set (update() resolves when config is written)
420402
const verifyConfig = workspace.getConfiguration('miniTypescriptHero.imports', tempWs.rootUri)
421403
.get<string[]>('excludePatterns', []);
422404
assert.deepStrictEqual(verifyConfig, ['**/generated/**'], 'Config should be set');
423405

424406
// CALL THE REAL METHOD!
425407
await organizer.organizeFolder(tempWs.rootUri);
426408

427-
await new Promise(resolve => setTimeout(resolve, 500));
428-
429409
// Verify src/app.ts was organized
430410
const appContent = fs.readFileSync(tempWs.fileUris[0].fsPath, 'utf-8');
431411
assert.ok(appContent.indexOf("from './a'") < appContent.indexOf("from './b'"), 'src/app.ts should be organized');
@@ -467,8 +447,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
467447
// CALL THE REAL METHOD - organizeWorkspace() instead of organizeFolder()
468448
await organizer.organizeWorkspace();
469449

470-
await new Promise(resolve => setTimeout(resolve, 500));
471-
472450
// Verify src/app.ts was organized
473451
const appContent = fs.readFileSync(tempWs.fileUris[0].fsPath, 'utf-8');
474452
assert.ok(appContent.indexOf("from './a'") < appContent.indexOf("from './b'"), 'src/app.ts should be organized');
@@ -508,19 +486,14 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
508486
await workspace.getConfiguration('miniTypescriptHero.imports', tempWs.rootUri)
509487
.update('excludePatterns', ['**/generated/**'], 1); // ConfigurationTarget.Global
510488

511-
// Wait for config to propagate
512-
await new Promise(resolve => setTimeout(resolve, 1000));
513-
514-
// Verify config was set
489+
// Verify config was set (update() resolves when config is written)
515490
const actualPatterns = workspace.getConfiguration('miniTypescriptHero.imports', tempWs.rootUri)
516491
.get<string[]>('excludePatterns');
517492
assert.deepStrictEqual(actualPatterns, ['**/generated/**'], 'Config should be set');
518493

519494
// CALL THE REAL METHOD - organizeWorkspace() instead of organizeFolder()
520495
await organizer.organizeWorkspace();
521496

522-
await new Promise(resolve => setTimeout(resolve, 500));
523-
524497
// Verify src/app.ts was organized
525498
const appContent = fs.readFileSync(tempWs.fileUris[0].fsPath, 'utf-8');
526499
assert.ok(appContent.indexOf("from './a'") < appContent.indexOf("from './b'"), 'src/app.ts should be organized');
@@ -550,9 +523,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
550523
await workspace.updateWorkspaceFolders(0, originalCount);
551524
}
552525

553-
// Wait for workspace to update
554-
await new Promise(resolve => setTimeout(resolve, 300));
555-
556526
// Verify no workspace folders
557527
assert.strictEqual(workspace.workspaceFolders?.length || 0, 0, 'Should have no workspace folders');
558528

@@ -604,8 +574,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
604574
// Call organizeWorkspace - should show info message and return (no TS/JS files to process)
605575
await organizer.organizeWorkspace();
606576

607-
await new Promise(resolve => setTimeout(resolve, 300));
608-
609577
// REAL validation: Verify files were NOT modified (mtime unchanged)
610578
const readmeMtimeAfter = fs.statSync(tempWs.fileUris[0].fsPath).mtimeMs;
611579
const jsonMtimeAfter = fs.statSync(tempWs.fileUris[1].fsPath).mtimeMs;
@@ -658,8 +626,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
658626
// Call organizeWorkspace - should continue despite syntax error in middle file
659627
await organizer.organizeWorkspace();
660628

661-
await new Promise(resolve => setTimeout(resolve, 500));
662-
663629
// Verify valid files were organized
664630
const valid1Content = fs.readFileSync(tempWs.fileUris[0].fsPath, 'utf-8');
665631
const valid2Content = fs.readFileSync(tempWs.fileUris[2].fsPath, 'utf-8');
@@ -730,8 +696,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
730696
{ uri: symlinkUri, name: 'SymlinkWorkspace' }
731697
);
732698

733-
await new Promise(resolve => setTimeout(resolve, 500));
734-
735699
// Try to organize folder using the REAL path (not symlink)
736700
// VS Code bug: getWorkspaceFolder(realPath) returns undefined
737701
// Our code's findTargetFilesInFolder() will throw "Folder is not in workspace"
@@ -740,8 +704,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
740704
// The function should complete without throwing (error handled internally)
741705
await organizer.organizeFolder(tempWs.rootUri); // Use REAL path, not symlink
742706

743-
await new Promise(resolve => setTimeout(resolve, 300));
744-
745707
// REAL validation: Verify file was NOT modified (error prevented processing)
746708
const fileContent = fs.readFileSync(tempWs.fileUris[0].fsPath, 'utf-8');
747709
assert.strictEqual(
@@ -794,13 +756,10 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
794756
{ uri: tempWs2.rootUri, name: 'Root2' }
795757
);
796758

797-
await new Promise(resolve => setTimeout(resolve, 500));
798-
799759
// Both roots use default excludePatterns (includes **/dist/**)
800760
// This tests that each root's patterns are applied correctly to its own files
801761

802762
await organizer.organizeWorkspace();
803-
await new Promise(resolve => setTimeout(resolve, 500));
804763

805764
// Verify files were organized correctly
806765
// Root1: src/app.ts should be organized, dist/auto.ts should NOT (excluded by default)
@@ -904,8 +863,6 @@ suite('BatchOrganizer - REAL Integration (calls actual methods!)', () => {
904863
);
905864
}
906865

907-
await new Promise(resolve => setTimeout(resolve, 300));
908-
909866
// REAL validation: Verify ALL files remain unchanged (cancellation prevented modifications)
910867
tempWs.fileUris.forEach((uri, i) => {
911868
const currentContent = fs.readFileSync(uri.fsPath, 'utf-8');

0 commit comments

Comments
 (0)