Skip to content

test: add unit tests for project-utils utility functions#3322

Open
yogeshwaran-c wants to merge 1 commit intonestjs:masterfrom
yogeshwaran-c:test/add-project-utils-specs
Open

test: add unit tests for project-utils utility functions#3322
yogeshwaran-c wants to merge 1 commit intonestjs:masterfrom
yogeshwaran-c:test/add-project-utils-specs

Conversation

@yogeshwaran-c
Copy link
Copy Markdown

What kind of change does this PR introduce?

Test coverage improvement.

What is the current behavior?

The lib/utils/project-utils.ts file exports 6 utility functions that are used across multiple actions (generate, build, start) but has zero test coverage. These functions handle critical logic around:

  • Whether to prompt users for project selection in monorepo mode
  • Whether to generate spec files based on CLI flags and configuration hierarchy
  • Whether to generate flat file structures
  • Spec file suffix resolution
  • Project list ordering for interactive prompts
  • Option flag validation

What is the new behavior?

Adds a comprehensive test suite (test/lib/utils/project-utils.spec.ts) with 38 unit tests covering all 6 exported functions:

Function Tests Key scenarios
shouldAskForProject 9 All excluded schematics (app, sub-app, library, lib), undefined/empty projects, appName provided
shouldGenerateSpec 8 CLI priority (specPassedAsInput), boolean config, schematic-specific config objects, project-level fallback to global config
shouldGenerateFlat 4 CLI priority, configuration boolean, default false behavior
getSpecFileSuffix 4 CLI priority, config value, default "spec" fallback
moveDefaultProjectToStart 5 Project reordering, null/empty projects, sourceRoot-based filtering, defaultLabel stripping
hasValidOptionFlag 8 Boolean/string value matching, missing options, false value matching, empty arrays

All 38 tests pass. No existing tests are affected.

Additional context

  • Follows the existing test patterns used in extra-args-warning.spec.ts and get-value-or-default.spec.ts
  • Uses the same jest-config.json configuration
  • No mocks needed -- all tested functions are pure or use already-tested helpers

Add comprehensive test coverage for all pure utility functions
exported from lib/utils/project-utils.ts, which previously had
no test coverage. The new test suite covers:

- shouldAskForProject: 9 tests covering all schematic types
  (app, sub-app, library, lib) and edge cases (undefined/empty
  projects, appName provided)
- shouldGenerateSpec: 8 tests covering CLI priority, boolean
  config, schematic-specific config, project-specific config,
  and global fallback behavior
- shouldGenerateFlat: 4 tests covering CLI priority and
  configuration fallback
- getSpecFileSuffix: 4 tests covering CLI priority,
  configuration value, and default "spec" fallback
- moveDefaultProjectToStart: 5 tests covering project
  reordering, null projects, sourceRoot-based filtering,
  and defaultLabel stripping
- hasValidOptionFlag: 8 tests covering boolean/string matching,
  missing options, and empty arrays

Total: 38 new passing tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant