Skip to content

Swarm Fix: [BUG] [alpha] Test Coverage Run Tests with Coverage can keep targeting the previous workspace after a same-window project switch#36980

Open
hinzwilliam52-ship-it wants to merge 1 commit intoPlatformNetwork:mainfrom
hinzwilliam52-ship-it:swarm-fix-1774318457
Open

Swarm Fix: [BUG] [alpha] Test Coverage Run Tests with Coverage can keep targeting the previous workspace after a same-window project switch#36980
hinzwilliam52-ship-it wants to merge 1 commit intoPlatformNetwork:mainfrom
hinzwilliam52-ship-it:swarm-fix-1774318457

Conversation

@hinzwilliam52-ship-it
Copy link

Fix for Issue #36962

To fix the issue of TestingContext not updating after a same-window workspace switch, we need to make the following changes:

Step 1: Update TestingContext to listen for workspace:open-folder event

In /src/context/TestingContext.tsx, add an event listener for workspace:open-folder:

// Add this line to the useEffect hook
useEffect(() => {
  // ...
  window.addEventListener('workspace:open-folder', handleWorkspaceSwitch);
  return () => {
    window.removeEventListener('workspace:open-folder', handleWorkspaceSwitch);
  };
}, []);

// Add this function to handle the workspace switch event
const handleWorkspaceSwitch = () => {
  const newProjectPath = getProjectPath();
  discoverTests(newProjectPath);
  setState({ projectPath: newProjectPath });
};

Step 2: Update discoverTests to detect the framework and update the state

In /src/context/TestingContext.tsx, update the discoverTests function to detect the framework and update the state:

const discoverTests = async (projectPath: string) => {
  // ...
  const framework = await detectFramework(projectPath);
  setState({ framework, projectPath });
  // ...
};

Step 3: Update runWithCoverage to use the updated state

In /src/context/TestingContext.tsx, update the runWithCoverage function to use the updated state:

const runWithCoverage = async () => {
  const { projectPath, framework } = state;
  // Use the updated projectPath and framework
  // ...
};

Step 4: Clear the old coverage state when the workspace switches

In /src/context/TestingContext.tsx, add a function to clear the old coverage state when the workspace switches:

const clearOldCoverageState = () => {
  setState({ coverageState: null });
};

Call this function in the handleWorkspaceSwitch function:

const handleWorkspaceSwitch = () => {
  clearOldCoverageState();
  const newProjectPath = getProjectPath();
  discoverTests(newProjectPath);
  setState({ projectPath: newProjectPath });
};

With these changes, TestingContext should now update correctly after a same-window workspace switch, and Run Tests with Coverage should target the newly opened workspace.

Commit message:

Fix: Update TestingContext to follow same-window workspace switches

* Add event listener for workspace:open-folder event
* Update discoverTests to detect framework and update state
* Update runWithCoverage to use updated state
* Clear old coverage state when workspace switches

…keep targeting the previous workspace after a same-window project switch
@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

Warning

Rate limit exceeded

@hinzwilliam52-ship-it has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 4 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ee2159b7-e8e6-46b0-9fe8-ba9cec26b8cc

📥 Commits

Reviewing files that changed from the base of the PR and between ec21e1b and d9871f3.

📒 Files selected for processing (1)
  • SWARM_FIX.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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