Skip to content

Commit 6900b82

Browse files
committed
test: add comprehensive integration tests for ImportManager (Phase 9.5)
- Created 20 integration tests covering all import organization features - Fixed critical bug: usage detection was skipping identifiers in variable initializers - Fixed sorting disabled mode: groups were still sorting internally - All 21 tests passing (20 ImportManager + 1 sample test) Test coverage includes: - Remove unused imports and specifiers - Keep excluded libraries (ignoredFromRemoval) - Type-only imports - Local shadowing - Aliased imports - Namespace imports - Default imports - Mixed default + named imports - Import grouping (Plains -> Modules -> Workspace) - Alphabetical sorting - Quote style configuration - Semicolons configuration - Space in braces configuration - Blank lines between groups - Trailing /index removal - Disable removal option - Disable sorting option - String-only imports Added GitHub Actions workflow to test on Linux/macOS/Windows with xvfb support
1 parent 0a4e012 commit 6900b82

6 files changed

Lines changed: 659 additions & 15 deletions

File tree

.claude/settings.local.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
"Bash(npm install:*)",
1010
"Bash(npm run compile:*)",
1111
"WebFetch(domain:buehler.github.io)",
12-
"Bash(git log:*)"
12+
"Bash(git log:*)",
13+
"Bash(git rev-parse:*)",
14+
"Bash(mkdir:*)",
15+
"Bash(npm run compile-tests:*)",
16+
"Bash(npm test)",
17+
"WebFetch(domain:code.visualstudio.com)"
1318
],
1419
"deny": [],
1520
"ask": []

.github/workflows/test.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Test Mini TypeScript Hero
2+
3+
on:
4+
push:
5+
branches: [main, master, second-try]
6+
pull_request:
7+
branches: [main, master]
8+
9+
jobs:
10+
test:
11+
strategy:
12+
matrix:
13+
os: [macos-latest, ubuntu-latest, windows-latest]
14+
runs-on: ${{ matrix.os }}
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '18.x'
24+
25+
- name: Install dependencies
26+
run: npm install
27+
working-directory: ./mini-typescript-hero
28+
29+
- name: Run tests (Linux with xvfb)
30+
if: runner.os == 'Linux'
31+
run: xvfb-run -a npm test
32+
working-directory: ./mini-typescript-hero
33+
34+
- name: Run tests (macOS/Windows)
35+
if: runner.os != 'Linux'
36+
run: npm test
37+
working-directory: ./mini-typescript-hero

mini-typescript-hero/dist/extension.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240696,7 +240696,22 @@ var ImportManager = class {
240696240696
continue;
240697240697
}
240698240698
const parent = identifier.getParent();
240699-
if (import_ts_morph.Node.isClassDeclaration(parent) || import_ts_morph.Node.isInterfaceDeclaration(parent) || import_ts_morph.Node.isTypeAliasDeclaration(parent) || import_ts_morph.Node.isFunctionDeclaration(parent) || import_ts_morph.Node.isEnumDeclaration(parent) || import_ts_morph.Node.isVariableDeclaration(parent)) {
240699+
if (import_ts_morph.Node.isClassDeclaration(parent) && identifier === parent.getNameNode()) {
240700+
continue;
240701+
}
240702+
if (import_ts_morph.Node.isInterfaceDeclaration(parent) && identifier === parent.getNameNode()) {
240703+
continue;
240704+
}
240705+
if (import_ts_morph.Node.isTypeAliasDeclaration(parent) && identifier === parent.getNameNode()) {
240706+
continue;
240707+
}
240708+
if (import_ts_morph.Node.isFunctionDeclaration(parent) && identifier === parent.getNameNode()) {
240709+
continue;
240710+
}
240711+
if (import_ts_morph.Node.isEnumDeclaration(parent) && identifier === parent.getNameNode()) {
240712+
continue;
240713+
}
240714+
if (import_ts_morph.Node.isVariableDeclaration(parent) && identifier === parent.getNameNode()) {
240700240715
continue;
240701240716
}
240702240717
if (localDeclarations.has(identifierText)) {
@@ -240800,11 +240815,13 @@ var ImportManager = class {
240800240815
);
240801240816
edits.push(import_vscode2.TextEdit.delete(range));
240802240817
const importLines = [];
240818+
const useSorting = !this.config.disableImportsSorting(this.document.uri);
240803240819
for (const group of importGroups) {
240804240820
if (group.imports.length === 0) {
240805240821
continue;
240806240822
}
240807-
const groupLines = group.sortedImports.map((imp) => this.generateImportStatement(imp));
240823+
const importsToUse = useSorting ? group.sortedImports : group.imports;
240824+
const groupLines = importsToUse.map((imp) => this.generateImportStatement(imp));
240808240825
importLines.push(...groupLines);
240809240826
importLines.push("");
240810240827
}

mini-typescript-hero/dist/extension.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mini-typescript-hero/src/imports/import-manager.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,24 @@ export class ImportManager {
172172
continue;
173173
}
174174

175-
// Skip if this identifier IS the declaration site itself
175+
// Skip if this identifier IS the name being declared (not usages in the declaration)
176176
const parent = identifier.getParent();
177-
if (
178-
Node.isClassDeclaration(parent) ||
179-
Node.isInterfaceDeclaration(parent) ||
180-
Node.isTypeAliasDeclaration(parent) ||
181-
Node.isFunctionDeclaration(parent) ||
182-
Node.isEnumDeclaration(parent) ||
183-
Node.isVariableDeclaration(parent)
184-
) {
185-
// This is the declaration site, skip it
177+
if (Node.isClassDeclaration(parent) && identifier === parent.getNameNode()) {
178+
continue;
179+
}
180+
if (Node.isInterfaceDeclaration(parent) && identifier === parent.getNameNode()) {
181+
continue;
182+
}
183+
if (Node.isTypeAliasDeclaration(parent) && identifier === parent.getNameNode()) {
184+
continue;
185+
}
186+
if (Node.isFunctionDeclaration(parent) && identifier === parent.getNameNode()) {
187+
continue;
188+
}
189+
if (Node.isEnumDeclaration(parent) && identifier === parent.getNameNode()) {
190+
continue;
191+
}
192+
if (Node.isVariableDeclaration(parent) && identifier === parent.getNameNode()) {
186193
continue;
187194
}
188195

@@ -333,13 +340,16 @@ export class ImportManager {
333340

334341
// Generate new import text
335342
const importLines: string[] = [];
343+
const useSorting = !this.config.disableImportsSorting(this.document.uri);
336344

337345
for (const group of importGroups) {
338346
if (group.imports.length === 0) {
339347
continue;
340348
}
341349

342-
const groupLines = group.sortedImports.map(imp => this.generateImportStatement(imp));
350+
// Use sortedImports only if sorting is enabled
351+
const importsToUse = useSorting ? group.sortedImports : group.imports;
352+
const groupLines = importsToUse.map(imp => this.generateImportStatement(imp));
343353
importLines.push(...groupLines);
344354

345355
// Add blank line between groups

0 commit comments

Comments
 (0)