Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 17, 2025

The interpretTaskModes function was hard to read with complex conditional logic and performed redundant iterations by calling someTasksAreOnly multiple times on the same suites.

Changes

Performance

  • Cache someTasksAreOnly results in a Map per suite traversal instead of recomputing recursively
  • Use Set for testLocations lookup (O(1) vs O(n) array search)

Readability

  • Merge duplicate skipAllTasks/todoAllTasks into single setModeForAllTasks(suite, mode)
  • Restructure conditionals into clear sequential sections with comments
  • Use nullish coalescing (??, ??=) for defaults
  • Add default parameters to inner traverseSuite function

Testing

  • Add 29 unit tests covering: basic modes, .only handling, name pattern filtering, location filtering, allowOnly errors, and nested suite scenarios
// Before: someTasksAreOnly called multiple times per task
const hasSomeTasksOnly = onlyMode && suite.tasks.some(
  t => t.mode === 'only' || (t.type === 'suite' && someTasksAreOnly(t)),
)
const includeTask = hasSomeTasksOnly
  ? (t.mode === 'only' || (t.type === 'suite' && someTasksAreOnly(t)))  // redundant call
  : ...

// After: pre-compute once per suite
let hasOnlyChild: Map<Suite, boolean> | undefined
if (onlyMode) {
  hasOnlyChild = new Map()
  for (const task of suite.tasks) {
    if (task.type === 'suite') {
      hasOnlyChild.set(task, someTasksAreOnly(task))
    }
  }
}
Original prompt

interpretTaskModes seems to be very complicated.

  1. it's hard to read
  2. it does a lot of extra iterations
    Rewrite it to be more performant and readable. Create integration tests first and validate the tests pass, and then start refactoring.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@netlify
Copy link

netlify bot commented Dec 17, 2025

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit cd55187
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6942a478f3d35f00081d8d42
😎 Deploy Preview https://deploy-preview-9283--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI and others added 3 commits December 17, 2025 12:44
Co-authored-by: sheremet-va <16173870+sheremet-va@users.noreply.github.com>
Co-authored-by: sheremet-va <16173870+sheremet-va@users.noreply.github.com>
…lt parameters

Co-authored-by: sheremet-va <16173870+sheremet-va@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor interpretTaskModes for better performance and readability Refactor interpretTaskModes for better readability and performance Dec 17, 2025
Copilot AI requested a review from sheremet-va December 17, 2025 13:00
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.

2 participants