Skip to content

Add a class to help mock child_process.spawn() and make "pub add" tests faster using it - #6166

Merged
DanTup merged 1 commit into
masterfrom
faster-pub-add-tests
Sep 5, 2026
Merged

DanTup merged 1 commit into
masterfrom
faster-pub-add-tests

Conversation

@DanTup

@DanTup DanTup commented Sep 4, 2026

Copy link
Copy Markdown
Member

See #6165

@DanTup DanTup added this to the v3.144.0 milestone Sep 4, 2026
@DanTup DanTup added the is testing Relates to the testing (either manual or automated) of Dart Code label Sep 4, 2026
@DanTup
DanTup requested a lite review from Copilot September 4, 2026 21:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new mocks include a type-invalid super(...) call and a stray ;; that will break type-check/lint, so the PR is not in a mergeable state yet.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR targets faster CI/test execution (Issue #6165) by avoiding real pub add/process execution in tests and instead verifying the extension attempted to spawn the expected processes.

Changes:

  • Added a reusable child_process.spawn() stub that captures/validates invocations and fakes immediate successful completion.
  • Updated Dart/Flutter pub add tests to assert spawned commands instead of waiting for real Pubspec mutations.
  • Moved/introduced a FakeProcessStdIOService under src/test/mocks and exported a couple of process helpers needed by the stub.
File summaries
File Description
src/test/mocks/fake_stdio_service.ts Adds a fake StdIOService for tests to feed stdout/stderr/exit/errors without spawning real processes.
src/test/mocks/child_process_spawn_stub.ts Introduces a child_process.spawn sinon stub for capturing/asserting spawned commands while faking completion.
src/test/flutter/pub/add.test.ts Switches Flutter pub add tests from asserting pubspec edits to asserting spawned flutter pub add calls.
src/test/flutter/device_manager.test.ts Updates import to the new FakeProcessStdIOService location.
src/test/dart/services/stdio_service.test.ts Updates import to the new FakeProcessStdIOService location.
src/test/dart/pub/add.test.ts Switches Dart pub add tests from asserting pubspec edits to asserting spawned dart pub ... calls.
src/shared/processes.ts Exports simpleCommandRegex and quoteAndEscapeArg for reuse in test stubs.
Review details
  • Files reviewed: 6/7 changed files
  • Comments generated: 2
  • Review effort level: Lite

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

Comment thread src/test/mocks/child_process_spawn_stub.ts
Comment thread src/test/mocks/child_process_spawn_stub.ts
@codecov

codecov Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.82%. Comparing base (1534c2f) to head (fddeeb8).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6166      +/-   ##
==========================================
- Coverage   70.85%   70.82%   -0.04%     
==========================================
  Files         170      170              
  Lines       13157    13158       +1     
  Branches     2649     2649              
==========================================
- Hits         9323     9319       -4     
- Misses       3315     3319       +4     
- Partials      519      520       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DanTup
DanTup force-pushed the faster-pub-add-tests branch from e62635e to fddeeb8 Compare September 5, 2026 10:05
@DanTup
DanTup merged commit 3c54102 into master Sep 5, 2026
24 checks passed
@DanTup
DanTup deleted the faster-pub-add-tests branch September 5, 2026 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

is testing Relates to the testing (either manual or automated) of Dart Code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants