Skip to content

Commit a1deeba

Browse files
committed
test: Add comprehensive VS Code behavior tests with evidence-based proof
Implements 14 new tests that execute VS Code's ACTUAL organize imports command to document exactly what it can and cannot do. This provides executable proof for our marketing claims instead of speculation. Key findings and test coverage: - VS Code does NOT automatically separate external vs internal imports - Proven: Mixed @angular/* and ./services/* sorted together as ONE group - Comments within imports treated as group separators (edge case) - Side-effect imports (import 'zone.js') sorted to END - All duplicate merging and unused removal behaviors documented Technical implementation: - Execute real editor.action.organizeImports command (not mocked) - Create temp files in os.tmpdir() (VS Code can organize standalone files) - Requires 2-second delay for TypeScript language service analysis - Requires 1-second delay after command (async execution) - Total: ~3 seconds per test (acceptable for 14 tests) - Uses shared test helpers (createTempDocument, deleteTempDocument) Documentation improvements: - Rewrote README.md comparison section (removed duplicates) - Rewrote blog-post.md comparison section (clearer messaging) - Emphasized automatic external/internal grouping as primary value - Clarified pattern-based grouping is optional enhancement - Added concrete examples showing VS Code's flat alphabetical sort Updated audit documentation: - Added comprehensive VS Code behavior tests section - Documented test strategy, findings, and edge cases - Listed 6 questions for reviewer feedback - Included code examples and test evidence Cleanup: - Removed redundant onCommand activation events from package.json (VS Code auto-generates these from contributes.commands) - Kept only onLanguage activation events Test results: 309 tests passing (14 new), 0 failing This change provides verifiable proof that automatic external/internal import grouping is our #1 differentiator over VS Code's built-in feature.
1 parent cf51bdd commit a1deeba

23 files changed

Lines changed: 3239 additions & 309 deletions

.claude/settings.local.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
{
22
"permissions": {
33
"allow": [
4-
"Bash(node -e \"\nconst { Project } = require(''ts-morph'');\nconst project = new Project({ useInMemoryFileSystem: true });\nconst sf = project.createSourceFile(''test.ts'', \\`import data from ''./data.json'' with { type: ''json'' };\\`);\nconst imp = sf.getImportDeclarations()[0];\nconst allMethods = Object.getOwnPropertyNames(Object.getPrototypeOf(imp));\nconst attributeMethods = allMethods.filter(m => m.toLowerCase().includes(''assert'') || m.toLowerCase().includes(''attribute'') || m.toLowerCase().includes(''with''));\nconsole.log(''Import Attribute Related Methods:'', attributeMethods);\nconsole.log(''\\nAll methods count:'', allMethods.length);\nconsole.log(''Sample methods:'', allMethods.slice(0, 30));\n\")"
4+
"Bash(npm run compile)",
5+
"Bash(find src/test -name \"*.test.ts\" -exec sed -i '' 's/public insertSemicolons(_resource: Uri): boolean {/public async insertSemicolons(_resource: Uri): Promise<boolean> {/g' {} ;)",
6+
"Bash(find src/test -name \"*.test.ts\" -exec sed -i '' 's/public stringQuoteStyle(_resource: Uri): .* {/public async stringQuoteStyle(_resource: Uri): Promise<\"\"\\\"\"\"\" | \"\"'\"''\"'\"\"> {/g' {} ;)",
7+
"Bash(find src/test -name \"*.test.ts\" -exec sed -i '' 's/return this.overrides.get(.insertSemicolons.)/return Promise.resolve(this.overrides.get(''''insertSemicolons''''))/g' {} ;)",
8+
"Bash(find src/test -name \"*.test.ts\" -exec sed -i '' 's/return this.overrides.get(.stringQuoteStyle.)/return Promise.resolve(this.overrides.get(''''stringQuoteStyle''''))/g' {} ;)",
9+
"Bash(npm test)",
10+
"WebSearch",
11+
"Bash(npm test -- --grep \"VS Code Organize Imports Behavior\")",
12+
"Bash(npm test -- --grep \"preserves blank lines between import groups\")",
13+
"Bash(npm test -- --grep \"does NOT automatically create groups based on patterns\")",
14+
"Bash(npm test -- --grep \"INVESTIGATION\")",
15+
"Bash(npm test -- --grep \"does NOT automatically create groups based on PATTERN MATCHING\")",
16+
"Bash(npm test -- --grep \"sorts alphabetically by module path\")",
17+
"Bash(npm test -- --grep \"PROOF\")",
18+
"Bash(npm run compile-tests)",
19+
"Bash(npm test -- --grep \"Edge Cases - Comments and Real-World Scenarios\")",
20+
"SlashCommand(/git-quick)"
521
],
622
"deny": [],
723
"ask": []

CHANGELOG.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
# Changelog
22

3-
## [4.0.0-rc.0] - 2025-10-06
3+
## [4.0.0-rc.0]
44

5-
### Release Candidate
5+
**Initial release** of Mini TypeScript Hero
66

7-
This is the first release candidate for Mini TypeScript Hero v4.0.0.
8-
9-
**Testing Period:** Please test this RC version and report any issues before the final 4.0.0 release.
10-
11-
**Read the announcement:** [TypeScript Hero is dead (is yet another VS Code extension gone forever?)](https://angular.schule/blog/2025-10-mini-typescript-hero)
12-
13-
## [4.0.0] - TBD
14-
15-
### Added
16-
17-
- **Initial release** of Mini TypeScript Hero
187
- Organize imports command (`Ctrl+Alt+O` / `Cmd+Alt+O`)
198
- Automatic removal of unused imports
209
- Intelligent import sorting (by module path or first specifier)
@@ -32,6 +21,11 @@ This is the first release candidate for Mini TypeScript Hero v4.0.0.
3221
- Ignored imports (never removed)
3322
- Disable sorting option
3423
- Disable removal option
24+
- **Configuration Priority Order** - Respects `.editorconfig` and VSCode settings before extension settings
25+
- **Commands:**
26+
- `Mini TS Hero: Organize imports` - Sort and remove unused imports (the main command)
27+
- `Mini TS Hero: Check for configuration conflicts` - Detect if multiple tools would organize imports
28+
- `Mini TS Hero: Toggle legacy mode` - Switch between modern and legacy behavior
3529
- Modern implementation using ts-morph (v27)
3630
- Built with esbuild for optimal performance
3731

CLAUDE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
## 🎯 Project Goal
2121

2222
Extract and modernize the "Sort and organize your imports" feature with:
23-
-**Comprehensive backward compatibility** with TypeScript Hero settings (verified across 370+ test scenarios)
23+
-**Comprehensive backward compatibility** with TypeScript Hero settings
2424
-**Modern 2025 tech stack** (ts-morph, esbuild, TypeScript 5.7)
2525
-**No dependencies on deprecated libraries** (typescript-parser is 7 years old!)
2626
-**Simplified architecture** (no InversifyJS DI container overkill)
@@ -162,7 +162,7 @@ mini-typescript-hero/ ← Project root
162162
│ ├── configuration/
163163
│ │ ├── imports-config.ts ← 13 config options wrapper
164164
│ │ └── settings-migration.ts ← Migrates old TypeScript Hero settings
165-
│ └── test/ ← General extension tests (215 tests)
165+
│ └── test/ ← General extension tests
166166
│ ├── imports/import-manager.test.ts
167167
│ ├── imports/blank-lines.test.ts
168168
│ └── configuration/settings-migration.test.ts
@@ -171,7 +171,7 @@ mini-typescript-hero/ ← Project root
171171
│ ├── old-extension/adapter.ts ← Adapter for old TypeScript Hero
172172
│ ├── new-extension/adapter.ts ← Adapter for new Mini TypeScript Hero
173173
│ ├── old-typescript-hero/ ← Git submodule (original extension)
174-
│ └── test-cases/*.test.ts ← 129 comparison tests
174+
│ └── test-cases/*.test.ts ← Comparison tests
175175
176176
├── manual-test-cases/ ← Manual testing scenarios
177177
├── package.json ← Extension manifest, config schema

CLAUDE_TODO.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5051,3 +5051,209 @@ Changes to commit:
50515051
- M src/imports/import-manager.ts (keep LAST default)
50525052
- M src/test/import-manager.test.ts (test 63 updated)
50535053

5054+
5055+
---
5056+
5057+
## Session: 2025-11-07 - VS Code Behavior Documentation & Marketing Clarity
5058+
5059+
### 1. Current Work Status
5060+
5061+
#### ✅ Completed Tasks
5062+
5063+
1. **Created Comprehensive VS Code Behavior Tests**
5064+
- Added 14 new tests in `src/test/vscode-organize-imports-behavior.test.ts`
5065+
- Tests execute REAL `editor.action.organizeImports` command (not mocked)
5066+
- Proves exactly what VS Code can/cannot do with executable evidence
5067+
- All 309 tests passing
5068+
5069+
2. **Discovered Critical Timing Requirement**
5070+
- VS Code's organize imports requires 2-second delay for TypeScript language service
5071+
- Must wait 1 additional second after command (async execution)
5072+
- Files can be in os.tmpdir() (VS Code CAN organize standalone files!)
5073+
5074+
3. **Confirmed #1 Selling Point with 100% Certainty**
5075+
- VS Code does NOT automatically separate external (node_modules) vs internal (local) imports
5076+
- Test proves: Mixed `@angular/*` and `./services/*` imports sorted together as ONE group
5077+
- Mini TypeScript Hero automatically creates blank lines between external/internal groups
5078+
5079+
4. **Discovered Edge Cases**
5080+
- Comments WITHIN imports are preserved but treated as group separators
5081+
- Side-effect imports (`import 'zone.js'`) sorted to END by VS Code
5082+
- VS Code merges duplicate imports from same module
5083+
5084+
5. **Cleaned Up Documentation**
5085+
- README.md: Rewrote "Why Use This Instead of VS Code's Built-in?" section
5086+
- blog-post.md: Rewrote "Wait, Doesn't VS Code Already Have This?" section
5087+
- Removed duplicate explanations
5088+
- Emphasized external/internal grouping as main value (90% use case)
5089+
- Clarified pattern-based grouping (e.g., `/^@angular/`) is optional enhancement
5090+
5091+
6. **Updated Audit Documentation**
5092+
- Added comprehensive section to REQUEST_FOR_AUDIT.md
5093+
- Documented test strategy, findings, edge cases
5094+
- Added 6 questions for reviewer feedback
5095+
5096+
#### 🚫 No In-Progress or Blocked Items
5097+
All tasks completed successfully.
5098+
5099+
---
5100+
5101+
### 2. Technical Context
5102+
5103+
#### Files Created
5104+
5105+
1. **`src/test/vscode-organize-imports-behavior.test.ts`** (NEW - 309 total tests)
5106+
- 14 comprehensive tests documenting VS Code's actual behavior
5107+
- 3 test suites: Group Preservation, Duplicate Merging, Basic Features
5108+
- 4 tests proving VS Code limitations (our differentiators)
5109+
- 3 edge case tests (comments, mixed imports, side-effects)
5110+
5111+
#### Files Modified
5112+
5113+
1. **`README.md`**
5114+
- Rewrote "Why Use This Instead of VS Code's Built-in?" section
5115+
- Removed duplicate explanations about groups
5116+
- Updated example to show default grouping (`["Modules", "Workspace"]`)
5117+
- Emphasized automatic external/internal separation as primary value
5118+
5119+
2. **`blog-post.md`**
5120+
- Rewrote "Wait, Doesn't VS Code Already Have This?" section
5121+
- Removed redundant explanations
5122+
- Added real-world impact example
5123+
- Emphasized zero-configuration benefit
5124+
5125+
3. **`REQUEST_FOR_AUDIT.md`**
5126+
- Added new section: "VS CODE BEHAVIOR DOCUMENTATION TESTS"
5127+
- Documented test strategy, coverage, findings
5128+
- Listed interesting edge cases discovered
5129+
- Added 6 questions for reviewer
5130+
5131+
4. **`.vscode-test.mjs`**
5132+
- Briefly added workspace folder to launchArgs (later reverted)
5133+
- Final version uses default (no workspace needed)
5134+
5135+
#### Temporary Files (Deleted During Session)
5136+
5137+
- `src/test/vscode-tmp-test.test.ts` - Created to prove os.tmpdir() works, then deleted
5138+
- `out/test/vscode-tmp-test.test.js` - Compiled version, manually deleted
5139+
5140+
---
5141+
5142+
### 3. Important Decisions
5143+
5144+
#### Architecture Choices
5145+
5146+
1. **Use Real VS Code APIs for Testing**
5147+
- Execute actual `editor.action.organizeImports` command
5148+
- Create real temp files in os.tmpdir()
5149+
- Use shared test helpers (`createTempDocument`, `deleteTempDocument`)
5150+
- **Rationale**: Provides executable proof, not speculation
5151+
5152+
2. **Marketing Messaging: Focus on Default Behavior**
5153+
- Primary value: Automatic external/internal separation (covers 90% of use cases)
5154+
- Secondary value: Optional pattern-based grouping (e.g., `/^@angular/`)
5155+
- **Rationale**: User feedback - "grouping by internal/external usually does the job"
5156+
5157+
3. **Test Timing Strategy**
5158+
- 2-second delay before executing organize imports command
5159+
- 1-second delay after command execution
5160+
- Total: ~3 seconds per test (acceptable for 14 tests)
5161+
- **Rationale**: TypeScript language service needs time to analyze file
5162+
5163+
#### Key Findings
5164+
5165+
1. **VS Code Does NOT Auto-Group External/Internal**
5166+
```typescript
5167+
// VS Code output (everything mixed):
5168+
import { Component } from '@angular/core'; // external
5169+
import { Router } from '@angular/router'; // external
5170+
import { BookService } from './services/book'; // internal
5171+
import { UserService } from './services/user'; // internal
5172+
// NO blank line between external and internal!
5173+
```
5174+
5175+
2. **Comments Treated as Group Separators**
5176+
- VS Code preserves comments but treats them like blank lines
5177+
- Creates separate groups around commented imports
5178+
5179+
3. **Side-Effect Imports Sorted to End**
5180+
- `import 'zone.js'` moves AFTER named imports
5181+
- VS Code has special sorting for string-only imports
5182+
5183+
---
5184+
5185+
### 4. Next Steps
5186+
5187+
#### Immediate TODO
5188+
5189+
1. **Review Test Coverage** (Optional Enhancement)
5190+
- Consider testing more edge cases based on reviewer feedback
5191+
- Potential additions: namespace imports, type-only imports, import attributes
5192+
5193+
2. **Monitor Test Performance**
5194+
- Current: 14 tests × 3 seconds = ~42 seconds
5195+
- If test suite grows, consider parallelization or optimization
5196+
5197+
3. **Update CHANGELOG.md** (Before Release)
5198+
- Document new VS Code behavior tests
5199+
- Mention documentation improvements
5200+
5201+
#### Testing Needed
5202+
5203+
✅ All tests passing (309 tests, 0 failures)
5204+
✅ ESLint clean
5205+
✅ TypeScript compilation successful
5206+
5207+
#### Documentation Updates
5208+
5209+
✅ README.md updated
5210+
✅ blog-post.md updated
5211+
✅ REQUEST_FOR_AUDIT.md updated
5212+
5213+
**Future Considerations**:
5214+
- Add section to README about side-effect imports behavior?
5215+
- Document comment-as-separator edge case?
5216+
5217+
---
5218+
5219+
### 5. Open Questions for Reviewer (from REQUEST_FOR_AUDIT.md)
5220+
5221+
1. **Test coverage**: Have we covered all relevant edge cases? Any other VS Code behaviors to test?
5222+
5223+
2. **Marketing claims**: Are our claims in README/blog accurate based on test evidence?
5224+
5225+
3. **Selling points**: Is "automatic external/internal grouping" our clearest differentiator?
5226+
5227+
4. **Edge cases**: Should we document the "comments as group separators" behavior in README?
5228+
5229+
5. **Performance**: 3 seconds per test (14 tests = ~42s) - acceptable or too slow?
5230+
5231+
6. **Side-effect imports**: Should we test/document how Mini TS Hero handles `import 'zone.js'` vs VS Code?
5232+
5233+
---
5234+
5235+
### 6. Test Evidence Summary
5236+
5237+
**Before This Session**: "VS Code can't automatically create groups" (speculation)
5238+
5239+
**After This Session**: "VS Code can't automatically create groups" (proven by 14 executable tests)
5240+
5241+
**Key Test**: `INVESTIGATION: Does VS Code automatically separate external vs internal imports?`
5242+
- Input: Mixed `@angular/*` and `./services/*` imports
5243+
- Output: All sorted together alphabetically (NO blank line between external/internal)
5244+
- Result: `Has blank line between import groups: false`
5245+
5246+
**Proof Location**: `src/test/vscode-organize-imports-behavior.test.ts:264-283`
5247+
5248+
---
5249+
5250+
### 7. Session Metrics
5251+
5252+
- **Tests Added**: 14 new tests
5253+
- **Total Tests**: 309 passing
5254+
- **Files Modified**: 4
5255+
- **Files Created**: 1
5256+
- **Test Time**: ~60 seconds (full suite)
5257+
- **Session Duration**: ~2 hours
5258+
- **Lines of Test Code**: ~476 lines
5259+

0 commit comments

Comments
 (0)