@@ -263,15 +263,21 @@ const b: BookService = null as any;
263263
264264 const result = await organizeImportsViaVSCode ( input ) ;
265265
266- // Let's see what VS Code actually does!
267- // eslint-disable-next-line no-console
268- console . log ( '=== VS CODE OUTPUT ===' ) ;
269- // eslint-disable-next-line no-console
270- console . log ( result ) ;
271- // eslint-disable-next-line no-console
272- console . log ( '======================' ) ;
273-
274- // Check if there's a blank line between external and internal imports
266+ // Expected: VS Code sorts everything together alphabetically (no auto-grouping)
267+ const expected = `import { Component } from '@angular/core';
268+ import { Router } from '@angular/router';
269+ import { BookService } from './services/book';
270+ import { UserService } from './services/user';
271+
272+ const x: Component = null as any;
273+ const y: Router = null as any;
274+ const u: UserService = null as any;
275+ const b: BookService = null as any;
276+ ` ;
277+
278+ assert . strictEqual ( result , expected , 'VS Code should sort all imports together without auto-grouping' ) ;
279+
280+ // Verify no blank line exists between external and internal imports
275281 const lines = result . split ( '\n' ) ;
276282 const hasBlankLineBetweenGroups = lines . some ( ( line , i ) =>
277283 line === '' &&
@@ -280,11 +286,11 @@ const b: BookService = null as any;
280286 lines [ i + 1 ] ?. includes ( 'import' )
281287 ) ;
282288
283- // eslint-disable-next-line no-console
284- console . log ( 'Has blank line between import groups:' , hasBlankLineBetweenGroups ) ;
285-
286- // We'll update this assertion based on what we discover
287- assert . ok ( result . includes ( 'import' ) , 'Should have imports' ) ;
289+ assert . strictEqual (
290+ hasBlankLineBetweenGroups ,
291+ false ,
292+ 'Should have NO blank lines between imports (proves no automatic grouping)'
293+ ) ;
288294 } ) ;
289295
290296 test ( 'does NOT automatically create groups based on PATTERN MATCHING (like /^@angular/)' , async ( ) => {
@@ -304,18 +310,30 @@ const s = switchMap;
304310
305311 const result = await organizeImportsViaVSCode ( input ) ;
306312
307- // eslint-disable-next-line no-console
308- console . log ( '=== PATTERN TEST OUTPUT ===' ) ;
309- // eslint-disable-next-line no-console
310- console . log ( result ) ;
311- // eslint-disable-next-line no-console
312- console . log ( '===========================' ) ;
313+ // Expected: VS Code merges rxjs imports and sorts alphabetically
314+ // NO blank line separating Angular from RxJS (no pattern-based grouping)
315+ const expected = `import { Component } from '@angular/core';
316+ import { Router } from '@angular/router';
317+ import { map, switchMap } from 'rxjs/operators';
318+
319+ const x: Component = null as any;
320+ const y: Router = null as any;
321+ const m = map;
322+ const s = switchMap;
323+ ` ;
313324
314- // If pattern-based grouping worked, we'd see:
315- // @angular /core, @angular/router, then blank line, then rxjs
316- // Let's see what actually happens!
325+ assert . strictEqual (
326+ result ,
327+ expected ,
328+ 'VS Code should merge rxjs imports but NOT create separate groups for @angular vs rxjs'
329+ ) ;
317330
318- assert . ok ( result . includes ( 'import' ) , 'Should have imports' ) ;
331+ // Verify Angular and RxJS imports are NOT separated by blank line
332+ const importSection = result . split ( '\n\n' ) [ 0 ] ; // Get everything before first blank line
333+ assert . ok (
334+ importSection . includes ( '@angular/core' ) && importSection . includes ( 'rxjs/operators' ) ,
335+ 'Angular and RxJS imports should be in same group (no blank line between them)'
336+ ) ;
319337 } ) ;
320338
321339 test ( 'does NOT remove /index from paths' , async ( ) => {
@@ -382,15 +400,32 @@ const w: UserService = null as any;
382400
383401 const result = await organizeImportsViaVSCode ( input ) ;
384402
385- // eslint-disable-next-line no-console
386- console . log ( '=== COMMENTS TEST OUTPUT ===' ) ;
387- // eslint-disable-next-line no-console
388- console . log ( result ) ;
389- // eslint-disable-next-line no-console
390- console . log ( '============================' ) ;
403+ // Expected: Comment is preserved (important for documentation)
404+ const expected = `import { Component } from '@angular/core';
405+ import { Router } from '@angular/router';
406+ // This import is required for the payment gateway integration
407+ import { PaymentService } from './services/payment';
408+ import { UserService } from './services/user';
409+
410+ const x: Component = null as any;
411+ const y: Router = null as any;
412+ const z: PaymentService = null as any;
413+ const w: UserService = null as any;
414+ ` ;
391415
392- // Check if comment is preserved
393- assert . ok ( result . includes ( 'payment gateway' ) , 'Comment should be preserved' ) ;
416+ assert . strictEqual ( result , expected , 'VS Code should preserve comment between imports' ) ;
417+
418+ // Verify comment is preserved with exact text
419+ assert . ok ( result . includes ( 'payment gateway' ) , 'Comment text should be preserved exactly' ) ;
420+
421+ // Note: Comment acts as group separator - PaymentService and UserService stay below comment
422+ const lines = result . split ( '\n' ) ;
423+ const commentIndex = lines . findIndex ( l => l . includes ( 'payment gateway' ) ) ;
424+ const paymentIndex = lines . findIndex ( l => l . includes ( 'PaymentService' ) ) ;
425+ assert . ok (
426+ commentIndex >= 0 && paymentIndex > commentIndex ,
427+ 'Comment should appear before PaymentService import (acts as group separator)'
428+ ) ;
394429 } ) ;
395430
396431 test ( 'CRITICAL: Does VS Code handle mixed external/internal imports WITHOUT auto-grouping?' , async ( ) => {
@@ -461,16 +496,34 @@ const y: Router = null as any;
461496
462497 const result = await organizeImportsViaVSCode ( input ) ;
463498
464- // eslint-disable-next-line no-console
465- console . log ( '=== SIDE EFFECTS TEST OUTPUT ===' ) ;
466- // eslint-disable-next-line no-console
467- console . log ( result ) ;
468- // eslint-disable-next-line no-console
469- console . log ( '=================================' ) ;
499+ // Expected: Side-effect imports (string imports) sorted AFTER named imports
500+ const expected = `import { Component } from '@angular/core';
501+ import { Router } from '@angular/router';
502+ import 'zone.js';
503+ import './styles.css';
470504
471- // Check if side-effect imports are handled
472- assert . ok ( result . includes ( 'zone.js' ) , 'Should preserve side-effect imports' ) ;
473- assert . ok ( result . includes ( 'styles.css' ) , 'Should preserve CSS imports' ) ;
505+ const x: Component = null as any;
506+ const y: Router = null as any;
507+ ` ;
508+
509+ assert . strictEqual ( result , expected , 'VS Code should sort side-effect imports AFTER named imports' ) ;
510+
511+ // Verify side-effect imports are preserved
512+ assert . ok ( result . includes ( 'zone.js' ) , 'Should preserve zone.js side-effect import' ) ;
513+ assert . ok ( result . includes ( 'styles.css' ) , 'Should preserve CSS side-effect import' ) ;
514+
515+ // Verify side-effect imports come AFTER named imports
516+ const lines = result . split ( '\n' ) ;
517+ const namedImportLines = lines
518+ . map ( ( l , i ) => ( { line : l , index : i } ) )
519+ . filter ( ( { line } ) => line . includes ( 'import' ) && line . includes ( 'from' ) ) ;
520+ const lastNamedImportIndex = namedImportLines . length > 0 ? namedImportLines [ namedImportLines . length - 1 ] . index : - 1 ;
521+ const firstSideEffectIndex = lines . findIndex ( l => l . includes ( 'zone.js' ) ) ;
522+
523+ assert . ok (
524+ firstSideEffectIndex > lastNamedImportIndex ,
525+ 'Side-effect imports should appear AFTER all named imports'
526+ ) ;
474527 } ) ;
475528 } ) ;
476529
0 commit comments