Skip to content

test(*): code coverage improvements - #1826

Merged
kdinev merged 6 commits into
masterfrom
ipetrov/cli-code-coverage-improvements
Oct 1, 2026
Merged

kdinev merged 6 commits into
masterfrom
ipetrov/cli-code-coverage-improvements

Conversation

@ivanvpetrov

Copy link
Copy Markdown
Contributor

Description

Code coverage improvements and bug fixes. See Additional Context below for details.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring / code cleanup
  • Build / CI configuration change

Affected Packages

  • igniteui-cli (packages/cli)
  • @igniteui/cli-core (packages/core)
  • @igniteui/angular-templates (packages/igx-templates)
  • @igniteui/angular-schematics (packages/ng-schematics)
  • @igniteui/mcp-server (packages/igniteui-mcp)

Checklist

  • I have tested my changes locally (npm run test)
  • I have built the project successfully (npm run build)
  • I have run the linter (npm run lint)
  • I have added/updated tests as needed
  • My changes do not introduce new warnings or errors

Additional Context

Summary

Raises test coverage and fixes three bugs and one broken spec that the new tests exposed.

Coverage Before After
Lines 91.56% 96.73%
Branches 77.86% 84.67%
Functions 84.17% 93.82%

Full suite: 706 specs, 0 failures (2 pending specs, unchanged). Lint is clean.

Bug fixes

TypeScriptExpressionCollector: duplicate detection was wrong

collectUniqueExpressions is used when adding routes and providers to array literals. It had four problems:

  • Identifier values never matched. Any value that wasn't a literal made the objects compare as different, so { path: 'home', component: HomeComponent } was never treated as a duplicate.
  • Literal values were never compared. { a: 1 } and { a: 2 } were treated as equal, so one of them was dropped.
  • Arrays were compared only by their first object element. [{a: 1}, {b: 2}] matched [{a: 1}, {c: 3}].
  • String-literal keys skipped the name check. { 'a': 1 } matched { 'b': 1 }.

Property values and array elements are now compared recursively. The comparison also handles true, false and null, and requires literal kinds to match, so '1' no longer equals 1.

⚠️ Behavior change: adding a route or provider that already exists with the same identifier values is now skipped. Before this change it was added a second time.

cli-config schematic: crash when devDependencies is missing

getDependencyVersion read json.devDependencies[pkg] and json.peerDependencies[pkg] without checking that those fields exist. A package.json without them threw a TypeError instead of the intended DependencyNotFoundException.

Util.execSync: Ctrl+C detection never fired

error.stderr.toString().endsWith() === "^C" compared a boolean to a string, so it was always false. It is now .endsWith("^C"). Also removed the unused private Util.propertyByPath.

Test fixes

  • ng-schematics/src/component/index_spec.ts never checked its assertions. The spec didn't await runSchematic, so it finished before its expects ran. The schematic then failed in the background and the error was swallowed. The spec is rewritten so every case awaits the run.
  • spec/acceptance/new-spec.ts depended on the developer's global config. A customTemplates entry in ~/ignite-ui-cli.json caused an extra GoogleAnalytics.post call and failed two specs locally. The spec now stubs ProjectConfig.globalConfig, as add-spec already does.

New and extended specs

Area Spec Notes
TypeScriptExpressionCollector spec/unit/TypeScriptExpressionCollector-spec.ts (new) 21 cases; 9 fail on the old code
IgniteUIForWebComponentsTemplate spec/unit/IgniteUIForWebComponentsTemplate-spec.ts (new) generateConfig and registerInProject routes; 0% → 100%
component schematic component/index_spec.ts (rewritten) Command-line run, unknown template, package.json update and install task, prompt path; 38% → 92%
start schematic start/index_spec.ts (new) 0% → 100%
All template definitions spec/templates/template-contracts-spec.ts (new) One loop over every project and component template of jQuery, React, Web Components and Blazor
Template projects blazor-spec, jquery-spec, webcomponents-spec Blazor empty extra config and scaffold, jQuery empty themes and upgrade, Web Components _base
BaseProjectLibrary BaseProjectLibrary-spec registerTemplate, getComponentGroups, getComponentNamesByGroup, unknown project; → 100%
cli-config cli-config/index_spec Dependency lookup, DependencyNotFoundException, "none" agents and assistants
PackageManager packageManager-spec No upgradeable project, failed full-package install, package.json without dependencies
Util Util-spec merge, execSync interrupt handling, gitInit, truncate, createDirectory, formatChoices, getOSFriendlyName

Found but not changed (follow-ups)

  • Unused public API in @igniteui/cli-core: Util.getCurrentDirectoryBase and Util.formatAngularJsonOptions. They have no callers but are kept to avoid breaking consumers.
  • Unreachable code: the npm login branch in PackageManager.ensureRegistryUser never runs, because REGISTRY_ATTEMPT_LOGIN is hard-coded to false.
  • Template paths that don't exist: the Web Components and React base/empty projects list a files folder in templatePaths that isn't there.
  • Mismatched project type: the React ai-config partial declares projectType: "tsx" instead of "igr-ts". It is only looked up by ID, so this has no effect today.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 11:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unsupported object members can still be incorrectly treated as duplicates and discarded.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Improves test coverage across CLI, core, templates, and schematics while fixing dependency lookup, interrupt detection, and expression deduplication.

Changes:

  • Adds broad unit and template contract coverage.
  • Fixes optional dependency-section handling and Ctrl+C detection.
  • Recursively compares TypeScript literal structures for duplicate removal.
File Description
spec/​unit/​Util-spec.ts Expands utility coverage.
spec/​unit/​TypeScriptExpressionCollector-spec.ts Tests expression deduplication.
spec/​unit/​packageManager-spec.ts Covers package upgrade edge cases.
spec/​unit/​IgniteUIForWebComponentsTemplate-spec.ts Tests Web Components configuration and routing.
spec/​unit/​BaseProjectLibrary-spec.ts Expands project-library coverage.
spec/​templates/​webcomponents-spec.ts Tests Web Components base projects.
spec/​templates/​template-contracts-spec.ts Adds cross-framework template contracts.
spec/​templates/​jquery-spec.ts Tests jQuery project behavior.
spec/​templates/​blazor-spec.ts Tests Blazor configuration and scaffolding.
spec/​acceptance/​new-spec.ts Isolates tests from global configuration.
packages/​ng-schematics/​src/​start/​index_spec.ts Adds start-schematic coverage.
packages/​ng-schematics/​src/​component/​index_spec.ts Corrects and expands component tests.
packages/​ng-schematics/​src/​cli-config/​index.ts Safely reads optional dependency sections.
packages/​ng-schematics/​src/​cli-config/​index_spec.ts Covers dependency and AI configuration cases.
packages/​core/​util/​Util.ts Fixes Ctrl+C detection and removes dead code.
packages/​core/​typescript/​TypeScriptExpressionCollector.ts Adds recursive expression comparison.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/core/typescript/TypeScriptExpressionCollector.ts Outdated
@coveralls

coveralls commented Oct 1, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 94.559% (+5.5%) from 89.043% — ipetrov/cli-code-coverage-improvements into master

@kdinev
kdinev requested a balanced review from Copilot October 1, 2026 11:45
@kdinev kdinev added schematics templates component OR scenario template core @igniteui/cli-core package cli-package igniteui-cli package labels Oct 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Expression comparison can still discard semantically distinct objects, and interrupted commands currently exit successfully.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
Resolved since last review (1)

Comment thread packages/core/typescript/TypeScriptExpressionCollector.ts
Comment thread packages/core/util/Util.ts
ivanvpetrov and others added 2 commits October 1, 2026 15:06
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Computed property names can still cause distinct object expressions to be incorrectly deduplicated.

Review effort: Balanced
Findings: None

Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Computed property names incorrectly compare as equal

packages/​core/​typescript/​TypeScriptExpressionCollector.ts:102

Computed property names are collapsed to undefined, so distinct entries such as { [firstKey]: 1 } and { [secondKey]: 1 } compare equal and the latter can be dropped. Since computed names are outside getPropertyName's supported set, treat an undefined name as non-equal (except for two spread assignments, whose expressions are compared below).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The fixes are sound; remaining feedback is a non-blocking assertion gap.

Review effort: Balanced
Findings: None

Previously missed (1)

In code that hasn't changed since last review

Low severity Add assertion for SIGINT exit status 130

packages/​core/​util/​Util.ts:358

The new SIGINT exit status is not covered: the added spec only checks that process.exit was called, so changing this back to process.exit() (which can report success) would still pass. Please assert toHaveBeenCalledWith(130) in Util-spec.ts.

@kdinev
kdinev merged commit 13c584f into master Oct 1, 2026
5 checks passed
@kdinev
kdinev deleted the ipetrov/cli-code-coverage-improvements branch October 1, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli-package igniteui-cli package core @igniteui/cli-core package schematics templates component OR scenario template tests ✅ status: verified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants