forcedotcom / salesforcedx-vscode

Salesforce Extensions for VS Code
https://developer.salesforce.com/tools/vscode
BSD 3-Clause "New" or "Revised" License
953 stars 406 forks source link

Create Apex Unit Test Class command overwrites existing files with no warning #5837

Open pozil opened 1 month ago

pozil commented 1 month ago

Summary

When running the Create Apex Unit Test Class command with a right click on the project tree or from the command palette and specifying a class name that already exists, the command overwrites the existing file content with no warning.

Steps To Reproduce:

  1. Create a Sample class and put some random code in there or a comment.
  2. Run the Create Apex Unit Test Class command and enter Sample for the class name
  3. Notice that the content of Sample.cls is replaced with the placeholder test code

Expected result

Command throws an error when file exists or prompts to confirm override

Actual result

Original file content is lost

Additional information

Salesforce Extension Version in VS Code: Extension pack v61.12.0

Salesforce CLI Version: @salesforce/cli/2.58.7 darwin-arm64 node-v18.17.0

OS and version: macOs 14.6.1 (23G93)

VS Code version: Version: 1.93.0 (Universal) Commit: 4849ca9bdf9666755eb463db297b69e5385090e3 Date: 2024-09-04T13:02:38.431Z (1 wk ago) Electron: 30.4.0 ElectronBuildId: 10073054 Chromium: 124.0.6367.243 Node.js: 20.15.1 V8: 12.4.254.20-electron.0 OS: Darwin arm64 23.6.0

svc-idee-bot commented 1 month ago

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

svc-idee-bot commented 1 month ago

Hello @pozil :wave: It looks like you didn't provide all the required basic info in your issue.

If you haven't already, please provide the following info: Salesforce Extension Version in VS Code: Salesforce CLI Version: OS and version: VS Code version: Most recent version of the extensions where this was working:

Here's an example of a set of required info that will pass the validation: Salesforce Extension Version in VS Code: 60.13.0 Salesforce CLI Version: @salesforce/cli/2.42.6 darwin-arm64 node-v18.18.2 OS and version: MacOS Sonoma 14.5 VS Code version: 1.89.1 Most recent version of the extensions where this was working: 60.11.0

A few more things to check:

Thank you!

mingxuanzhangsfdx commented 1 month ago

Hi @pozil , when creating a apex unit test class with a duplicate name, are you able to see a prompt like this to confirm to overwrite the existing file? image

pozil commented 1 month ago

Nope, as you can see:

https://github.com/user-attachments/assets/fa9010db-2f5c-4cce-8302-1ba3338afcc7

diyer commented 1 month ago

Hi @pozil , we understand this is a bug (and we will consider fixing this) but as per Apex test naming conventions, the tests should have Test in their names as the suffix.

git2gus[bot] commented 1 month ago

This issue has been linked to a new work item: W-16736221

pozil commented 1 month ago

@diyer thanks. I know about the convention, I just made a silly copy/paste mistake and forgot to add the Test suffix. This is how I found the issue :)