Git Product home page Git Product logo

salesforcedx-apex's Introduction

Salesforce Apex Library

License Commitizen friendly

Introduction

Typescript library to support the Apex plugin and Salesforce Extensions for VS Code.

Note: Please report any issues via the Issues tab.


Getting Started

If you're interested in contributing, take a look at the CONTRIBUTING guide.

If you're interested in building the plugin and library locally, take a look at the Developing doc.

salesforcedx-apex's People

Contributors

ananyajha avatar cristicanizales avatar daphne-sfdc avatar gbockus-sf avatar hanelliot-sfdc avatar jag-j avatar jeffb-sfdc avatar klewis-sfdc avatar lcampos avatar mdonnalley avatar mingxuanzhangsfdx avatar mshanemc avatar murilokakazu avatar peternhale avatar randi274 avatar rcoringrato-sfdc avatar ritamagrawal avatar sfsholden avatar shetzel avatar smitshah2531 avatar svc-cli-bot avatar svc-idee-bot avatar tideteam-sf avatar willieruemmele avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

salesforcedx-apex's Issues

Handle errors when providing invalid test result id

Summary

Provide better error messages when a user provides an invalid id for force:apex:test:report

Steps To Reproduce:

  1. Provide an invalid Id to the test report command e.g. sfdx force:apex:test:report -i 7075A0000BiWZjxx -r human
  2. Returns an unhandled query error:
ERROR running force:apex:test:report:  
UserId FROM ApexTestRunResult WHERE AsyncApexJobId = '7075A0000BiWZjxx'
                                    ^
ERROR at Row:1:Column:150
invalid ID field: 7075A0000BiWZjxx

Expected result

The command should return a clear error message letting the user know the provided data is invalid.

Class names returned for a namespaced package are in the format of `namespace__classname`. They should be `namespace.classname`

Summary

Class names returned for a namespaced package are in the format of namespace__classname. They should be namespace.classname

Steps To Reproduce:

  1. Create a Salesforce DX Unlocked package with Namespace
  2. Create a Test class and run the tests

Expected result

Class names with Namespace should be listed as namespace.classname

Actual result

Class names with Namespace are listed as namespace__classname

Additional information

image

å
Apex library Version:1.1.0

OS and version: macOs Monterey 12.4

Provide clear error message when user has no access to Apex code

Summary

The force:apex:test:run command does not provide a useful error message when the user does not have access to running Apex code.

Steps To Reproduce:

  1. Create a user with a profile that does not provide access to Apex e.g. Work.com Only User
  2. Run force:apex:test:run e.g. sfdx force:apex:test:run -t "TestPermSetAssignment,TestPermstachioConfig" -r human
  3. It does not thrown an error the is consistent with the rest of the command error handling and that tells the user they do not have the correct access needed to run tests.
sfdx force:apex:test:run -d "./.sfdx/tools/customresultsv5" -t "TestPermSetAssignment,TestPermstachioConfig" -r json
Listening for streaming state changes...
Error encountered during test update: 403::User not enabled for streaming
ERROR running force:apex:test:run:  ; nested exception is: 
        common.exception.ApiException: sObject type 'ApexClass' is not supported.

Expected result

A clear error message that lets the user know they do not have the access needed to run Apex tests.

Test id no longer being reported for current version of Apex Plugin

Summary

Note originally reported in slack.

Hi Team,
When we run the test class (sfdx force:apex:test:run -l RunLocalTests -u [email protected] -w 60 --json) with the CLI version 7.114.0 and earlier, we are getting the result as below while the test execution is happening at back-end:
{
"status":0,
"result": {
"testRunId": "thisIsTheTestId"
}
}
Here we are getting the Job ID and we can later find the report using the JOb ID (sfdx force:apex:test:report --testrunid thisIsTheTestId )
But in the CLI version 7.172.0 and latest this same command is not returning any Job ID/testRunId, and it seems that it is returning once the test execution is completed (which is not feasible if the customer's test classes ran for hours, since the customer will not be able to do anything else until test execution is completed)
Is there anything changed on this command with the latest CLI versions?
Any insight on this will be really helpful !

plugins info for working and non-working versions

SFDX Version 7.114.0 (WORKING) output:
% sfdx plugins --core
› Warning: sfdx-cli update available from 7.114.0 to 7.172.0.
@oclif/plugin-autocomplete 0.3.0 (core)
@oclif/plugin-commands 1.3.0 (core)
@oclif/plugin-help 3.3.1 (core)
@oclif/plugin-not-found 1.2.6 (core)
@oclif/plugin-plugins 1.10.11 (core)
@oclif/plugin-update 1.4.0-3 (core)
@oclif/plugin-warn-if-update-available 1.7.3 (core)
@oclif/plugin-which 1.0.4 (core)
[@Salesforce](https://salesforce-internal.slack.com/team/WPB0BC065)
/sfdx-plugin-lwc-test 0.1.7 (core)
[@Salesforce](https://salesforce-internal.slack.com/team/WPB0BC065)
/sfdx-trust 3.6.0 (core)
alias 1.1.10 (core)
apex 0.2.7 (core)
auth 1.7.1 (core)
config 1.2.23 (core)
custom-metadata 1.0.12 (core)
data 0.6.0 (core)
generator 1.2.2 (core)
limits 1.2.1 (core)
org 1.6.9 (core)
salesforce-alm 52.2.5 (core)
schema 1.0.8 (core)
sfdx-cli 7.114.0 (core)
source 1.0.9 (core)
telemetry 1.2.3 (core)
templates 52.1.0 (core)
user 1.4.0 (core)
************************************************************************************************
sfdx version 7.174.0 (Non Working )Output
@oclif/plugin-autocomplete 1.3.1 (core)
@oclif/plugin-commands 2.2.0 (core)
@oclif/plugin-help 5.1.14 (core)
@oclif/plugin-not-found 2.3.3 (core)
@oclif/plugin-plugins 2.1.1 (core)
@oclif/plugin-update 3.0.2 (core)
@oclif/plugin-version 1.1.2 (core)
@oclif/plugin-warn-if-update-available 2.0.6 (core)
@oclif/plugin-which 2.1.0 (core)
[@Salesforce](https://salesforce-internal.slack.com/team/WPB0BC065)
/sfdx-plugin-lwc-test 1.0.1 (core)
alias 2.1.5 (core)
apex 1.3.0 (core)
auth 2.2.15 (core)
community 2.0.10 (core)
config 1.4.21 (core)
custom-metadata 2.0.2 (core)
data 2.1.4 (core)
generator 2.0.7 (core)
info 2.2.0 (core)
limits 2.0.5 (core)
org 2.2.9 (core)
packaging 1.9.4 (core)
salesforce-alm 54.8.3 (core)
schema 2.1.10 (core)
sfdx-cli 7.174.0 (core)
signups 1.2.8 (core)
source 2.0.25 (core)
telemetry 2.0.2 (core)
templates 55.1.0 (core)
trust 2.0.4 (core)
user 2.1.13 (core) (edited)

Expected result

Should return test id for querying the test run.

Actual result

No Test id is returned.

Possible incorrect namespace formatting on test name

Summary

If a scratch org has a namespace when running a test class the output class name will have the namespace prefixed as mynamespace__myclass instead of mynamespace.myclass. I am happy to fix this but I wanted to check this was not intentional and is actually a bug before I do.

e.g output is like this

=== Test Results
TEST NAME                                                      OUTCOME          MESSAGE         RUNTIME (MS)
─────────────────────  ───────  ───────  ────────────
mynamespace__MyTestClass.myTestMethod             Pass                                               9      

instead of

=== Test Results
TEST NAME                                                        OUTCOME          MESSAGE         RUNTIME (MS)
─────────────────────  ───────  ───────  ────────────
mynamespace.MyTestClass.myTestMethod             Pass                                               9      

Steps To Reproduce:

  1. Create a scratch org with namespace
  2. Push a simple test class
  3. Run the test from vscode
  4. output panel will show namespace with underscores instead of .

Expected result

In the test result output, I think we should see mynamespace.MyClass.myTestMethod

Actual result

Instead of mynamespace__MyClass.myTestMethod

Additional information

Apex library Version: apex 0.2.1

OS and version: macOS Big Sur 11.4

Test results not output by default for `force:apex:test:run`

Summary

When executing tests with force:apex:test:run the test results are not output to screen by default after command completes.

Steps To Reproduce:

MyTest.cls

@IsTest(isParallel = true)
class MyTest {
    @IsTest
    static void test1() {
        Assert.equals(1, 1 + 1);
    }

    @IsTest
    static void test2() {
        Assert.equals(2, 1 + 1);
    }

    @IsTest
    static void test3() {
        Assert.equals(3, 2 + 1);
    }
}

Given the test class MyTest exists in the Org.

$ sfdx force:apex:test:run -t MyTest

Expected result

Expected test methods of MyTest would be executed and the results written to standard output in human format, as was the behaviour in previous versions of sfdx.

Actual result

Instead of the results being written to the standard output, a message is output with instructions on how to retrieve the test results.

$ sfdx force:apex:test:run -t MyTest
Run "sfdx force:apex:test:report -i 7071F000020fQZj -u [email protected]" to retrieve test results

Specifying -w, --wait does not change the outcome

$ sfdx force:apex:test:run -t MyTest -w 500
Run "sfdx force:apex:test:report -i 7071F000020fQgJ -u [email protected]" to retrieve test results                                                          

Additional information

Running the same command but specifying a result format explicitly then the results get output to screen as expected:

$ sfdx force:apex:test:run -t MyTest -r human
=== Test Summary                                                                                                                                                               
NAME                 VALUE                               
───────────────────  ────────────────────────────────────
Outcome              Failed                              
Tests Ran            2                                   
Pass Rate            50%                                 
Fail Rate            50%                                 
Skip Rate            0%                                  
Test Run Id          7071F000020fRIW                     
Test Execution Time  41 ms                               
Org Id               00D1F000000YO2SUAW                  
Username             [email protected]


=== Test Results
TEST NAME          OUTCOME  MESSAGE                                                               RUNTIME (MS)
─────────────────  ───────  ────────────────────────────────────────────────────────────────────  ────────────
MyTest.shouldFail  Fail     System.AssertException: Assertion Failed: Expected: <1>, Actual: <2>  
                            Class.Assert.fail: line 95, column 1                                  
                            Class.Assert.failNotEquals: line 145, column 1                        
                            Class.Assert.equals: line 127, column 1                               
                            Class.Assert.equals: line 108, column 1                               
                            Class.MyTest.shouldFail: line 5, column 1                                         
MyTest.shouldPass  Pass                                                                           23          

This works for formats human, tap, and json but not junit, due to another issue reported here: forcedotcom/salesforcedx-vscode#3359

SFDX CLI Version(to find the version of the CLI engine run sfdx --version):sfdx-cli/7.107.0 linux-x64 node-v14.17.1

SFDX plugin Version(to find the version of the CLI plugin run sfdx plugins --core)

$ sfdx plugins --core                                                                                                                                                                               
@alan-morey/sfdx-plugin 0.0.0 (link) /home/alan/repos/alan-morey-sfdx-plugin                                                                                                   
@oclif/plugin-autocomplete 0.3.0                                                                                                                                               
@oclif/plugin-commands 1.3.0 (core)                                                                                                                                            
@oclif/plugin-help 3.2.2 (core)                                                                                                                                                
@oclif/plugin-not-found 1.2.4 (core)                                                                                                                                           
@oclif/plugin-plugins 1.10.0 (core)                                                                                                                                            
@oclif/plugin-update 1.4.0-3 (core)                                                                                                                                            
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-diff 0.0.6
@salesforce/sfdx-plugin-lwc-test 0.1.7 (core)
@salesforce/sfdx-scanner 2.9.2
@salesforce/sfdx-trust 3.6.0 (core)
alias 1.1.10 (core)
apex 0.2.2 (core)
apexlink 1.3.2
auth 1.6.1 (core)
config 1.2.8 (core)
custom-metadata 1.0.12 (core)
data 0.4.12 (core)
generator 1.1.7 (core)
gr-sfdx-plugin 0.0.0 (link) /home/alan/repos/salesforce/gr-sfdx-plugin
limits 1.2.1 (core)
org 1.6.7 (core)
salesforce-alm 52.0.2 (core)                                                                                                                                                   
schema 1.0.7 (core)                                                                                                                                                            
sfdx-cli 7.107.0 (core)
telemetry 1.2.2 (core)
templates 52.0.0 (core)
user 1.3.0 (core)

OS and version: Ubuntu 18.04.5 LTS

"Always provide a classes, suites, tests, or testLevel property." when running `sfdx force:apex:test:run -l RunLocalTests` on a project with no tests

Summary

SFDX exits with the following error when running sfdx force:apex:test:run -l RunLocalTests on a project with no tests:

ERROR running force:apex:test:run: Always provide a classes, suites, tests, or testLevel property.

Since -l sets the testLevel property, the error message is wrong (testLevel was provided). In the case where there are no local tests and RunLocalTests is set as test level, the call should just complete without doing anything.

Steps To Reproduce:

  1. Run sfdx force:apex:test:run -l RunLocalTests in a DX project that has no tests, with the scratch org already created and set as the default username.

Expected result

All local tests are run (which is no tests in an org with no local tests).

Actual result

ERROR running force:apex:test:run:  Always provide a classes, suites, tests, or testLevel property.

error is returned.

System Information

{
	"cliVersion": "sfdx-cli/7.123.0",
	"architecture": "darwin-x64",
	"nodeVersion": "node-v14.18.1",
	"pluginVersions": [
		"@assisisolutions/sfdx-ci-plugin 1.0.1",
		"@oclif/plugin-autocomplete 0.3.0 (core)",
		"@oclif/plugin-commands 1.3.0 (core)",
		"@oclif/plugin-help 3.2.3 (core)",
		"@oclif/plugin-not-found 1.2.4 (core)",
		"@oclif/plugin-plugins 1.10.1 (core)",
		"@oclif/plugin-update 1.5.0 (core)",
		"@oclif/plugin-warn-if-update-available 1.7.0 (core)",
		"@oclif/plugin-which 1.0.3 (core)",
		"alias 1.1.22 (core)",
		"auth 1.7.3 (core)",
		"config 1.2.41 (core)",
		"generator 1.2.0 (core)",
		"salesforcedx 52.0.0",
		"├─ data 0.4.11",
		"├─ apex 0.2.2",
		"├─ schema 1.0.7",
		"├─ custom-metadata 1.0.12",
		"├─ templates 51.5.0",
		"├─ org 1.6.6",
		"├─ limits 1.2.1",
		"├─ user 1.3.0",
		"├─ salesforce-alm 52.0.0",
		"└─ @salesforce/sfdx-plugin-lwc-test 0.1.7",
		"sfdx-cli 7.123.0 (core)",
		"source 1.2.4 (core)",
		"telemetry 1.2.8 (core)",
		"texei-sfdx-plugin 1.11.1",
		"trust 1.0.8 (core)"
	],
	"osVersion": "Darwin 19.6.0"
}

Additional information

N/A

Support retrieving logs via date range

Is your feature request related to a problem? Please describe.

Sometimes, when there is an intermittent issue, I have to set up debug logs for 24h and hope that the issue occurs. Once I identify the approximate time at which the issue occurs, I then have to download and review many log files for that time period (say, 45m). This can take a long time downloading each log individually - the current alternative is to download the last (say) 1000 logs just to get the 100 I'm interested in.

Describe the solution you'd like
As a developer, I want to be able to download all the logs for a specified time period rather than downloading them one-by-one.

Describe alternatives you've considered
I've used sfdx force:apex:log:list to spit out the logs, then pasted the output into vscode and used the multiline editing feature to put together a script to dump the logs each into separate files one-by-one. This is quicker than downloading one-at-a-time, but is still more labour intensive than I'd like, especially getting the filename format correct such that the OS doesn't complain of invalid characters or non-existant directories.

What is the formal specification for the output files generated by force:apex:test:run ?

Is your feature request related to a problem? Please describe.
sfdx force:apex:test:run -r junitgenerates output files described in here (https://developer.salesforce.com/blogs/2021/04/clearer-apex-commands) to describe test results and code coverage.
What is the formal specification for these files ?
Where are their schemas defined ?
Are these compatible with test summary tools and code coverage report solutions which expect JUnit input format files ?

What are you trying to do
I'm trying to consume the output of sfdx force:apex:test:run -r junit to display Github Checks displayed by solutions such as Code Coverage or JUnit Coverage Report (https://github.com/marketplace/actions/junit-coverage-report)

Describe the solution you'd like
I would like to be able to generate output files which adhere to a standard, in this case the JUnit XML schema, and a code coverage format such as Cobertura XML, Jacoco XML.

Describe alternatives you've considered
None.

Additional context
I'm looking to inject results into Github Actions CI, so :

  • produce a summary compatible with Github Checks to display in a PR
  • add Github Annotations to code to point out lines of code covered/uncovered by tests

Colourful output for human resultformat

Is your feature request related to a problem? Please describe.
I want the human output to be easier to find the failing tests so they can be fixed.
Right now that involves scrolling a mixed list of passing and failing tests in the output.
This can be hard to do if the list is long or there is already other output in the terminal.

It can also be difficult to spot which tests have a fail status when there is a long list of tests, I often resort to searching the terminal output for "fail" but this matches tests names with fail in them.
It can be especially difficult if you use a narrow terminal and the text has wrapped or long test names caused the outcome column to be pushed far across.

Summary section is output first which means a lot of scrolling back up the terminal output to find out if the long list of tests has any failing ones you need to worry about.

Describe the solution you'd like
Test Results

  • Pass tests outcomes shown as a green pass badge.
  • Fail tests outcome shown as a red pass badge.
  • Stack trace shown below the test name, in the same column.
    Easier to follow + parse and takes up less width in the terminal output.
  • Coverage shown in green if 75 or over, red otherwise

Summary

  • Summary moved to bottom of output with new Failed tests section below that.
    Allows user to determine if errors exists without scrolling to top for a long time. Useful if terminal has lots of previous output.
  • passed, failed + skipped figures show in green, red + yellow.
  • passed, failed + skipped values show as a number with the rate in brackets.
  • Coverage shown in green if 75 or over, red otherwise

Failed Tests
-New section in the Human Report which shows only the failed test at the bottom of the terminal output in the same format as Test Results section (if any exist).

I have already implemented the above feature in the related pull request.
It also makes two other changes

  • handle spaces between tests
    e.g
    --classnames=" ATest , SecondTest " is valid and not just
    --classnames="ATest,SecondTest"
  • column after multi row cell now aligned at top e.g
col 1               |  col2
------------  |  ---------
Some multi   | more text
row text        |

instead of

col 1               |  col2
------------  |  ---------
Some multi   | 
row text        | more text

Additional context
Here is the output that will now be displayed with the changes in the related PR.

Screenshot 2021-06-29 at 09 46 16

Human formatted Apex test report shouldn't display individual PASSING test methods

Some of our projects have upwards of 2000 test methods. When we run force:apex:test:run -w 50 -r human in our CI/CI scripts and there is a single failed test method, we see 1999 lines of "Pass" and we have to painfully try to hunt down the single test method with the Fail status.

In a prior version of the CLI, it would only report test failures which meant that for a 100% successful test run, it would only print the summary block with the outcome of the test run -- there's no need to print 2000 lines of noise in the log file telling me that each test method was successful

Something changed at some point within the past few months (basically at the point where passing -r human was required in order to see the detail of the test failures)

Solution 1 - silence test methods that Pass by default

Pros: This is the way it should be and the way just about every other test reporter I've ever seen in my life has worked. Users that want all Passing test methods to be enumerated can use the --verbose existing command line argument to enable.

Cons: This will change existing behavior

Solution 2 - Add a command line argument (eg. --not-so-verbose) to silence Pass test methods from the output

Pros: Preserves existing behavior

Cons: Requires updating existing CI/CD scripts to pass this new flag. Also, documenting and naming the flag to make it somehow compatible with the --verbose documentation could be challenging.

Additional context
Also, it should be noted that in the Summary table, the "Pass rate" is a whole number (presumably using half-up rounding logic) which results in incongruous outcome:

=== Test Summary
NAME                 VALUE
───────────────────  ──────────────────────────
Outcome              Failed
Tests Ran            870
Pass Rate            100%
Fail Rate            0%
Skip Rate            0%
Test Run Id          7071F0000279qGm
Test Execution Time  280082 ms
Org Id               00D1F000000aI3mUAE
Username             [email protected]

Which is it? A failure or 100% pass? What actually happened is one test method failed but that still resulted in the "99.9%" getting rounded up to 100%

Version that I'm running

@oclif/plugin-autocomplete 0.3.0 (core)
@oclif/plugin-commands 1.3.0 (core)
@oclif/plugin-help 3.2.2 (core)
@oclif/plugin-not-found 1.2.4 (core)
@oclif/plugin-plugins 1.10.1 (core)
@oclif/plugin-update 1.4.0-3 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-plugin-lwc-test 0.1.7 (core)
@salesforce/sfdx-trust 3.6.0 (core)
alias 1.1.10 (core)
apex 0.2.8 (core)
auth 1.7.1 (core)
config 1.2.24 (core)
custom-metadata 1.0.12 (core)
data 0.6.1 (core)
etcopydata 0.6.4-Beta (beta)
generator 1.1.7 (core)
limits 1.2.1 (core)
org 1.7.0 (core)
salesforce-alm 52.3.1 (core)
schema 1.0.8 (core)
sfdx-cli 7.116.2 (core)
shane-sfdx-plugins 4.43.0
├─ @mshanemc/plugin-streaming 1.1.7
└─ @mshanemc/sfdx-sosl 1.1.0
source 1.0.12 (core)
telemetry 1.2.3 (core)
templates 52.1.0 (core)
user 1.4.0 (core)

Invalid XML structure in jUnit with constructor stack trace

Summary

Test command generates invalid XML structure for jUnit when one of the tests results in a exception that generates a stack trace that includes a constructor. The constructor will be listed as ClassName. in the failure message attribute which is not valid for XML.

Validation error:
The value of attribute "message" associated with an element type "failure" must not contain the '<' character.xml(LessthanInAttValue)

<testcase name="TestMethodName" classname="ClassName" time="1.12">
            <failure message="System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ClassName: execution of BeforeInsert
caused by: jException: No Salesforce profile for ProfileX

Class.Class1.Method: line 20, column 1
Class.Class2.<init>: line 158, column 1
Class.Class3: line 528, column 1
Class.Class3: line 344, column 1
Class.Class4: line 23, column 1
Class.Class5.execute: line 105, column 1
Trigger.Class6: line 3, column 1: []"><![CDATA[Class.ClassName.TestMethodName: line 20, column 1]]></failure>
        </testcase>

Steps To Reproduce:

  1. Make a test class that tests code that somewhere hits a constructor and hits an exception after.
  2. run sfdx force:apex:test:report -i [testid] -u [OrgAlias] -r junit -d [locationFile]
  3. View Junit

Expected result

Perhaps it would make more sense to have the stack trace as part of the value of the failure element in the CDATA block and the message be more only of a description.

Actual result

Stack Trace in Message attribute of the failure element. Causing invalid XML structure

Additional information

Mac BigSur 11.4
sfdx-cli/7.110.0 darwin-x64 node-v14.17.3

Also Bitbucket pipelines in SalesforceDX docker container https://hub.docker.com/r/salesforce/salesforcedx/ tag:latest-slim

sfdx force:apex:log:tail -d DEBUGLEVEL ignores the specified debug level

Summary

sfdx force:apex:log:tail -d DEBUGLEVEL IGNORES the specified debug level. I've done countless tests of this over weeks and can confirm that the above command will NOT use the debug level specified. The command will ONLY use the SFDC_DevConsole debug level. This is not optimal as the settings on that debug level aren't "sticky" resulting in too much data that a developer did not ask for in the logs.

Steps To Reproduce:

  1. Issue sfdx force:data:record:create -s DebugLevel -t -v "DeveloperName=SFDX_Logging MasterLabel=SFDX_Logging Database=INFO Workflow=NONE Validation=NONE Callout=INFO ApexCode=DEBUG ApexProfiling=NONE Visualforce=INFO System=NONE Nba=NONE Wave=NONE" to create a Debug Level
  2. Issue sfdx force:apex:log:tail -d SFDX_Logging to start logging
  3. Perform any action in Salesforce that will produce logs

Expected result

The log levels should 100% match the log levels associated with the named DEBUGLEVEL passed to force:apex:log:tail

Actual result

The log levels used appear to be the levels associated with the SFDC_DevConsole Debug Level.

System Information

  • Which shell/terminal are you using? bash

  • If you are using sfdx

    • Run sfdx version --verbose --json
  • If you are using sf

    • Run sf version --verbose --json
  • Paste the output here

Additional information

{
  "cliVersion": "sfdx-cli/7.169.1",
  "architecture": "darwin-x64",
  "nodeVersion": "node-v16.17.0",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 1.3.0 (core)",
    "@oclif/plugin-commands 2.2.0 (core)",
    "@oclif/plugin-help 5.1.12 (core)",
    "@oclif/plugin-not-found 2.3.1 (core)",
    "@oclif/plugin-plugins 2.1.0 (core)",
    "@oclif/plugin-update 3.0.0 (core)",
    "@oclif/plugin-version 1.1.2 (core)",
    "@oclif/plugin-warn-if-update-available 2.0.4 (core)",
    "@oclif/plugin-which 2.1.0 (core)",
    "alias 2.1.0 (core)",
    "apex 1.2.0 (core)",
    "auth 2.2.5 (core)",
    "community 2.0.1 (core)",
    "config 1.4.19 (core)",
    "custom-metadata 2.0.0 (core)",
    "data 2.1.2 (core)",
    "generator 2.0.2 (core)",
    "info 2.1.0 (core)",
    "limits 2.0.1 (core)",
    "org 2.2.3 (core)",
    "packaging 1.9.1 (core)",
    "schema 2.1.3 (core)",
    "signups 1.2.0 (core)",
    "source 2.0.13 (core)",
    "telemetry 2.0.0 (core)",
    "templates 55.1.0 (core)",
    "trust 2.0.4 (core)",
    "user 2.1.2 (core)",
    "@salesforce/sfdx-plugin-lwc-test 1.0.1 (core)",
    "salesforce-alm 54.8.1 (core)"
  ],
  "osVersion": "Darwin 21.6.0",
  "shell": "bash",
  "rootPath": "/Users/a0702866/.local/share/sfdx/client/7.169.1-15b850c"
}

Feel free to attach a screenshot.

The new code coverage formats also for force:apex:test:*

I think the new --coverageformatters option is a valuable addition to the SFDX cli. But it would be really nice to also add it to force:apex:test:*

For example:


sfdx force:apex:test:run --coverageformatters cobertura

This would be valuable to scratch org build deployments in pipelines. So you can forward the code coverage to your CI/CD system of choice.

feat: Support readablestream for getLogs in the logservice

Is your feature request related to a problem? Please describe.
Just so we can have improved performance and memory management.
Basically they are more efficient for larger datasets and we can pipe the chunk to a write stream.

Describe the solution you'd like
getLogs would return a Result with a readablestream to read the log content.

Describe alternatives you've considered

Additional context

force:apex:test:run does not seem to take the wait parameter into account

Summary

We have an old organization with a lot of integration tests that take a while to execute (say between 40' and 60' on the main org). We have set up a Continuous Integration process based on the Saleforce CLI so that these tests are executed (on a Scratch Org) every time a commit is pushed to our repository. As our tests take a long time we use the wait parameter on the force:apex:test:run command to avoid a timeout (-w120 so that we have some leeway).

Lately (but I sadly cannot pinpoint from when exactly) our tests have been failing consistently:

  • the message for failure is "Your request exceeded the time limit for processing. connection was cancelled here" on ~80% of the failing tests.
  • the execution time of the force:apex:test:run command is exactly 60' every time.

We have tried to set a much larger value to the wait parameter but the tests get cancelled at the same point. We have tried to set the wait parameter to a very short value (1') and the command still seems to execute for a very long time.

Steps To Reproduce:

  1. Set up a Scratch Org with tests.
  2. Execute the tests on the Scratch Org: sfdx force:apex:test:run -w1 -lRunLocalTests

Expected result

  • sfdx force:apex:test:run -w1 -lRunLocalTests should cancel the run after ~1'.
  • sfdx force:apex:test:run -w120 -lRunLocalTests should execute all tests.

Actual result

The tests execute for what seems to be a default amount of time (60') whatever the value of wait.

Additional information

Apex library Version:

{
        "cliVersion": "sfdx-cli/7.131.0",
        "architecture": "linux-x64",
        "nodeVersion": "node-v16.13.1",
        "pluginVersions": [
                "@oclif/plugin-autocomplete 0.3.0 (core)",
                "@oclif/plugin-commands 1.3.0 (core)",
                "@oclif/plugin-help 3.2.10 (core)",
                "@oclif/plugin-not-found 1.2.4 (core)",
                "@oclif/plugin-plugins 1.10.10 (core)",
                "@oclif/plugin-update 1.5.0 (core)",
                "@oclif/plugin-warn-if-update-available 1.7.3 (core)",
                "@oclif/plugin-which 1.0.3 (core)",
                "@salesforce/sfdx-plugin-lwc-test 0.1.7 (core)",
                "alias 1.2.0 (core)",
                "apex 0.5.0 (core)",
                "auth 1.8.0 (core)",
                "config 1.3.2 (core)",
                "custom-metadata 1.0.12 (core)",
                "data 0.6.6 (core)",
                "generator 1.2.1 (core)",
                "info 1.1.4 (core)",
                "limits 1.3.0 (core)",
                "org 1.11.0 (core)",
                "salesforce-alm 53.6.0 (core)",
                "schema 1.1.0 (core)",
                "sfdx-cli 7.131.0 (core)",
                "source 1.6.2 (core)",
                "telemetry 1.4.0 (core)",
                "templates 52.6.0 (core)",
                "trust 1.1.0 (core)",
                "user 1.7.0 (core)"
        ],
        "osVersion": "Linux 5.8.0-1043-azure"
}

OS and version:

Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal

No detailed code coverage when using junit output format

Summary

When using the junit output format, only the aggregated code coverage is printed, even if the flag --detailed-coverage is used.

Steps To Reproduce:

  1. sf apex run test --test-level RunSpecifiedTests --tests MyClass1,MyClass2 --code-coverage --detailed-coverage --result-format junit --target-org MyOrg

Expected result

Have the code coverage per class anywhere in the result.

Actual result

Only aggregated code coverage :

<testsuite name="force.apex" ... >

...





Additional information

Feel free to attach a screenshot.
å
Apex library Version: 3.0.2

OS and version: MacOs Ventura 13.5 (22G74)

Support maxFailedTests in force:apex:test:run

Is your feature request related to a problem? Please describe.
My current Apex Suite is not the fasts of suites. So for CI it would be really great if SFDX also supported to fail as soon as the first test failed (or any other number of tests, naturally). It is already supported in Developer Console and Tooling API as maxFailedTests.

Describe alternatives you've considered
I've considered writing either a plugin on my own or calling the Tooling API myself, but I believe it belongs in SFDX.

Additional context
Screenshot 2021-08-13 at 07 35 55

Apex Test Report - Cannot read property 'records' of null

Summary

force:apex:test:report fails with message:
Cannot read property 'records' of null

Steps To Reproduce:

  • Run this command to schedule a full test run
    sfdx force:apex:test:run --codecoverage --resultformat=human --synchronous --testlevel=RunLocalTests

  • Run this command to check on the status
    sfdx force:apex:test:report --testrunid=707xxxxxxxxxxxx

You should get the error mentioned above.

Additional information

SFDX CLI Version(to find the version of the CLI engine run sfdx --version):
sfdx-cli/7.102.0 darwin-x64 node-v16.1.0

SFDX plugin Version(to find the version of the CLI plugin run sfdx plugins --core)
@oclif/plugin-autocomplete 0.3.0
@oclif/plugin-commands 1.3.0 (core)
@oclif/plugin-help 3.2.2 (core)
@oclif/plugin-not-found 1.2.4 (core)
@oclif/plugin-plugins 1.10.0 (core)
@oclif/plugin-update 1.4.0-3 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/analytics 0.23.0
@salesforce/lwc-dev-mobile 1.2.0
@salesforce/sfdx-trust 3.6.0 (core)
alias 1.1.10 (core)
auth 1.5.4 (core)
config 1.2.8 (core)
generator 1.1.5 (core)
salesforcedx 51.12.0 (core)
├─ templates 51.3.1 (core)
├─ custom-metadata 1.0.12 (core)
├─ data 0.4.6 (core)
├─ apex 0.2.0 (core)
├─ user 1.2.10 (core)
├─ @salesforce/sfdx-plugin-lwc-test 0.1.7 (core)
├─ org 1.6.5 (core)
├─ salesforce-alm 51.6.23 (core)
├─ schema 1.0.6 (core)
└─ limits 1.2.0 (core)
sfdx-cli 7.102.0 (core)
telemetry 1.2.1 (core)

OS and version:
MacOS 11.3.1

Unhandled exceptions when trying to write files on a read-only directory

Summary

The test:run command fails with and unhandled exceptions when a user tries to write the execution results on a folder they don't have access to or is a read-only folder.

Steps To Reproduce:

  1. Run force:test:run and provide an output directory that is set as a read only directory
  2. sfdx force:apex:test:run -l RunLocalTests -d "/.sfdx/tools/customresultsv2"
sfdx force:apex:test:run -l RunLocalTests -d "/.sfdx/tools/customresultsv2"             
Listening for streaming state changes...
Processing test run 7075A0000BiWoduQQC
Processing test run 7075A0000BiWoduQQC
Processing test run 7075A0000BiWoduQQC
Processing test run 7075A0000BiWoduQQC
Processing test run 7075A0000BiWoduQQC
Processing test run 7075A0000BiWoduQQC
Run "sfdx force:apex:test:report -i 7075A0000BiWodu -u [email protected]" to retrieve test results
(node:85517) UnhandledPromiseRejectionWarning: Error: EROFS: read-only file system, mkdir '/.sfdx'
    at Object.mkdirSync (fs.js:987:3)
    at ensureDirectoryExists (/Users/lcamposguajardo/github/DevTools/salesforcedx-apex/packages/plugin-apex/node_modules/@salesforce/apex-node/src/utils/fileSystemHandler.ts:17:6)
    at ensureDirectoryExists (/Users/lcamposguajardo/github/DevTools/salesforcedx-apex/packages/plugin-apex/node_modules/@salesforce/apex-node/src/utils/fileSystemHandler.ts:16:3)
    at ensureDirectoryExists (/Users/lcamposguajardo/github/DevTools/salesforcedx-apex/packages/plugin-apex/node_modules/@salesforce/apex-node/src/utils/fileSystemHandler.ts:16:3)
    at ensureFileExists (/Users/lcamposguajardo/github/DevTools/salesforcedx-apex/packages/plugin-apex/node_modules/@salesforce/apex-node/src/utils/fileSystemHandler.ts:21:3)
    at /Users/lcamposguajardo/github/DevTools/salesforcedx-apex/packages/plugin-apex/node_modules/@salesforce/apex-node/src/utils/fileSystemHandler.ts:57:5
    at Array.map (<anonymous>)
    at Object.<anonymous> (/Users/lcamposguajardo/github/DevTools/salesforcedx-apex/packages/plugin-apex/node_modules/@salesforce/apex-node/src/utils/fileSystemHandler.ts:56:33)
    at Generator.next (<anonymous>)
    at /Users/lcamposguajardo/github/DevTools/salesforcedx-apex/packages/plugin-apex/node_modules/@salesforce/apex-node/lib/src/utils/fileSystemHandler.js:14:71
(Use `node --trace-warnings ...` to show where the warning was created)
(node:85517) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:85517) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected result

The command should finish the execution successfully and provide a warning that files couldn't be created since the path provided is not writeable.

Test Issue - Ignore

Summary

Short summary of what is going on or to provide context.

Steps To Reproduce:

  1. This is step 1.
  2. This is step 2. All steps should start with '1.'

Expected result

Describe what should have happened.

Actual result

Describe what actually happened instead.

Additional information

Feel free to attach a screenshot.

Apex library Version:

OS and version:

Unable to run multiple test methods from the same class with force:apex:test:run

Summary

When specifying individual test methods to execute, using the -t, --tests=tests flag, we are no longer able to specify multiple test methods from same test class to run. Getting error Include the class name MyTest only once.

Steps To Reproduce:

MyTest.cls

@IsTest(isParallel = true)
class MyTest {
    @IsTest
    static void test1() {
        Assert.equals(1, 1 + 1);
    }

    @IsTest
    static void test2() {
        Assert.equals(2, 1 + 1);
    }

    @IsTest
    static void test3() {
        Assert.equals(3, 2 + 1);
    }
}

Given the test class MyTest exists in the Org.

$ sfdx force:apex:test:run -w -1 -r human -t "MyTest.test1,MyTest.test3"

Expected result

Expected the test methods test1 and test3 of MyTest test class to be executed and the results output to the screen in human format.

Actual result

$ sfdx force:apex:test:run -w -1 -r human -t "MyTest.test1,MyTest.test3"
ERROR running force:apex:test:run:  Include the class name MyTest only once.

Additional information

Trying same command with -y, --synchronous flag, also fail but with a different error message

$ sfdx force:apex:test:run -w -1 -r human -t "MyTest.test1,MyTest.test3" -y
ERROR running force:apex:test:run:  Provide only one tests array.

SFDX CLI Version(to find the version of the CLI engine run sfdx --version): sfdx-cli/7.107.0 linux-x64 node-v14.17.1

SFDX plugin Version(to find the version of the CLI plugin run sfdx plugins --core)

$ sfdx plugins --core                                                                                                                                                                               
@alan-morey/sfdx-plugin 0.0.0 (link) /home/alan/repos/alan-morey-sfdx-plugin                                                                                                   
@oclif/plugin-autocomplete 0.3.0                                                                                                                                               
@oclif/plugin-commands 1.3.0 (core)                                                                                                                                            
@oclif/plugin-help 3.2.2 (core)                                                                                                                                                
@oclif/plugin-not-found 1.2.4 (core)                                                                                                                                           
@oclif/plugin-plugins 1.10.0 (core)                                                                                                                                            
@oclif/plugin-update 1.4.0-3 (core)                                                                                                                                            
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-diff 0.0.6
@salesforce/sfdx-plugin-lwc-test 0.1.7 (core)
@salesforce/sfdx-scanner 2.9.2
@salesforce/sfdx-trust 3.6.0 (core)
alias 1.1.10 (core)
apex 0.2.2 (core)
apexlink 1.3.2
auth 1.6.1 (core)
config 1.2.8 (core)
custom-metadata 1.0.12 (core)
data 0.4.12 (core)
generator 1.1.7 (core)
gr-sfdx-plugin 0.0.0 (link) /home/alan/repos/salesforce/gr-sfdx-plugin
limits 1.2.1 (core)
org 1.6.7 (core)
salesforce-alm 52.0.2 (core)                                                                                                                                                   
schema 1.0.7 (core)                                                                                                                                                            
sfdx-cli 7.107.0 (core)
telemetry 1.2.2 (core)
templates 52.0.0 (core)
user 1.3.0 (core)

OS and version: Ubuntu 18.04.5 LTS

apex:test:run command does not support running tests by providing the class id

Summary

The official docs and the help output for force:apex:test:run indicates that a user can provide a test's name or id under the -t flag. Providing an Apex test class ID throws the error This class name's value is invalid: 01p5A00000A1aBfQAJ. Provide the name of an Apex class that has test methods.

Steps To Reproduce:

  1. Run force:apex:test:run by provide an Apex test ID e.g. sfdx force:apex:test:run -t 01p5A00000A1aBfQAJ
  2. Throws an error:
sfdx force:apex:test:run -t 01p5A00000A1aBfQAJ
Listening for streaming state changes...
ERROR running force:apex:test:run:  This class name's value is invalid: 01p5A00000A1aBfQAJ. Provide the name of an Apex class that has test methods.

Expected result

The command should be able to execute the Apex tests when a user provides the Apex test class ID.

sfdx force:apex:test:run fails when run from Github action

Summary

When we run sfdx force:apex:test:run from our ci/cd Github action, it fails with the error "ERROR running force:apex:test:run: Always provide a classes, suites, tests, or testLevel property."

Steps To Reproduce:

Repository to reproduce: dreamhouse-lwc

We are using code based on the scratch-org-test job of ci-pr.yml in the dreamhouse repo.

  1. Install Salesforce CLI
  2. Checkout the source code
  3. Store secret for dev hub
  4. Authenticate dev hub
  5. Create scratch org
  6. Deploy source to scratch org
  7. Assign permissionset
  8. SKIPPED Import sample data
  9. Run Apex tests in scratch org

Expected result

Test suite is run

Actual result

Error - "ERROR running force:apex:test:run: Always provide a classes, suites, tests, or testLevel property."

We have tried adding a -l RunAllTestsInOrg switch (also tried RunLocalTests, and using --testlevel) and still get the same error.

System Information

Output after installing the sfdx-cli -
sfdx-cli/7.144.2 linux-x64 node-v16.14.2

This was previously working with v7.143.0

"sfdx force:apex:test:run" and "sfdx force:apex:test:report" generate invalid XML when using JUNIT output

Hello,

I encounterd an error with the force:apex:test:run and force:apex:test:report commands, where the output creation of a JUNIT xml generates an invalid XML. This is because messages containing a double-quote don't get escaped.

We are using this command in an automated pipeline in Azure, where we want to publish the testresults, but Azure cannot parse the XML because it is not valid.

I have first updated SFDX before submitting this issue:

# sfdx update
sfdx-cli: Updating CLI from 7.132.0-6621068 to 7.142.1-05bbd4a... done
sfdx-cli: Updating CLI... done
sfdx-cli: Updating sf... done

Steps to reproduce

Create the following test class:

@IsTest
public class TestJunit {

    @IsTest
    public static void generateIncorrectOutput() {
        throw new CustomException('This message contains "Double quotes"');
    }
    
    
    class CustomException extends Exception {
        
    }
}

Run the testclass with JUNIT output

sfdx force:apex:test:run -n TestJunit -r junit

This generates:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite name="force.apex" timestamp="2022-03-14T07:10:00.000Z" hostname="https://force-site-2505.cs189.my.salesforce.com" tests="1" failures="1"  errors="0"  time="0.02">
        <properties>
            <property name="outcome" value="Failed"/>
            <property name="testsRan" value="1"/>
            <property name="passing" value="0"/>
            <property name="failing" value="1"/>
            <property name="skipped" value="0"/>
            <property name="passRate" value="0%"/>
            <property name="failRate" value="100%"/>
            <property name="testStartTime" value="Mon Mar 14 2022 08:10:00"/>
            <property name="testExecutionTime" value="0.02 s"/>
            <property name="testTotalTime" value="0.02 s"/>
            <property name="commandTime" value="0.11 s"/>
            <property name="hostname" value="https://.... "/>
            <property name="orgId" value="00D7a0000001AdvEAE"/>
            <property name="username" value="[email protected]"/>
            <property name="testRunId" value="7077a000038XYJ8"/>
            <property name="userId" value="0057a....."/>
        </properties>
        <testcase name="generateIncorrectOutput" classname="TestJunit" time="0.02">
            <failure message="TestJunit.CustomException: This message contains "Double quotes""><![CDATA[Class.TestJunit.generateIncorrectOutput: line 6, column 1]]></failure>
        </testcase>
    </testsuite>
</testsuites>

If you try to parse this XML (for instance using sfdx force:apex:test:run -n TestJunit -r junit | xmllint -) you will get:

-:23: parser error : attributes construct error
            <failure message="TestJunit.CustomException: This message contains "
                                                                               ^
-:23: parser error : Couldn't find end of Start Tag failure line 23
            <failure message="TestJunit.CustomException: This message contains "
                                                                               ^
-:23: parser error : Opening and ending tag mismatch: testcase line 22 and failure
"><![CDATA[Class.TestJunit.generateIncorrectOutput: line 6, column 1]]></failure
                                                                               ^
-:24: parser error : Opening and ending tag mismatch: testsuite line 3 and testcase
        </testcase>
                   ^
-:25: parser error : Opening and ending tag mismatch: testsuites line 2 and testsuite
    </testsuite>
                ^
-:26: parser error : Extra content at the end of the document
</testsuites>
^

Not handling users with no Streaming API access

Summary

The force:apex:test:run command does not handle scenarios where the user does not have the expected api access to the Streaming API.

Steps To Reproduce:

  1. Create a user with a profile that does not provide access to the Streaming API e.g. Standard Platform User
  2. Run force:apex:test:run e.g. sfdx force:apex:test:run -t "TestPermSetAssignment,TestPermstachioConfig" -r human
  3. It does not thrown an error the is consistent with the rest of the command error handling
sfdx force:apex:test:run  -t "TestPermSetAssignment,TestPermstachioConfig" -r human
Listening for streaming state changes...
Error encountered during test update: 403::User not enabled for streaming

Expected result

The command should handle the error and report it back to the user in the same way as the other command errors are handled e.g. Error running force:apex:test:run: <clear error message>

sfdx force:apex:test:report -c has no option to display code coverage without details

Is your feature request related to a problem? Please describe.

The force:apex:test:run -c -r human command provides the --detailedcoverage option to display code coverage detailed information, for each test in each class
The force:apex:test:report -c -r human always displays the detailed report which force:apex:test:run -c --detailedcoverage would display.

There is no option for force:apex:test:report -c to display the same results as those displayed by force:apex:test:run -c without the --detailedcoverage option

What are you trying to do
I'm trying to use the force:apex:test:report -c -r human command to display the code coverage summary information without all the code coverage detailed information (test by test).

Describe the solution you'd like
I would like a --detailedcoverage option for the force:apex:test:report -c command.

I would like the force:apex:test:report -c -r human to work like the force:apex:test:run -c -r human command :

  • display the same summary in the absence of the --detailedcoverage option
  • display the same details in the presence of the --detailedcoverage option

Describe alternatives you've considered
I have no alternative.
I cannot produce the human-readable summary by using the force:apex:test:runcommand, because I am producing this report later, after the tests have been run. That is why I have to use the force:apex:test:reportcommand.

Additional context

Regression: sfdx force:apex:test:run No longer waits and returns testRunId only

sfdx-cli/7.114.0 win32-x64 node-v14.17.5

This was working as expected until I updated to 7.114.0

sfdx force:apex:test:run -n hellohellotest -u prod -w 60 --json

returns:
{
"status": 0,
"result": {
"testRunId": "7074x00002LI5cg"
}
}

expected

{
"status": 100,
"result": {
"summary": {
"outcome": "Failed",
"testsRan": 2,
"passing": 0,
"failing": 2,
"skipped": 0,
"passRate": "0%",
"failRate": "100%",
"testStartTime": "Tue Aug 24 2021 5:41:52 PM",
"testExecutionTime": "31 ms",...

`sfdx force:apex:test:run` failing to execute 2+ test methods from same class

Summary

Unable to execute more than one test method in the same class using sfdx force:apex:test:run ...

Steps To Reproduce:

Repository to reproduce: dreamhouse-lwc

  1. run the following command:
sfdx force:apex:test:run -t- "TestPropertyController.testGetPagedPropertyList,TestPropertyController.testGetPicturesNoResults" -u <username>

Expected result

Run both specified tests. This should be possible with this command according to the official docs, here.

Actual result

Received the error:

ERROR running force:apex:test:run:  Include the class name TestPropertyController only once.

System Information

  • Which shell/terminal are you using? bash

  • If you are using sfdx

    • Run sfdx version --verbose --json
  • If you are using sf

    • Run sf version --verbose --json
  • Paste the output here

{
  "cliVersion": "sfdx-cli/7.184.2",
  "architecture": "win32-x64",
  "nodeVersion": "node-v18.12.1",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 1.3.8 (core)",
    "@oclif/plugin-commands 2.2.2 (core)",
    "@oclif/plugin-help 5.1.20 (core)",
    "@oclif/plugin-not-found 2.3.13 (core)",
    "@oclif/plugin-plugins 2.1.8 (core)",
    "@oclif/plugin-search 0.0.6 (core)",
    "@oclif/plugin-update 3.0.9 (core)",
    "@oclif/plugin-version 1.1.4 (core)",
    "@oclif/plugin-warn-if-update-available 2.0.18 (core)",
    "@oclif/plugin-which 2.2.6 (core)",
    "alias 2.1.16 (core)",
    "apex 1.3.0 (core)",
    "auth 2.3.10 (core)",
    "community 2.1.3 (core)",
    "config 1.4.23 (core)",
    "custom-metadata 2.0.11 (core)",
    "data 2.1.22 (core)",
    "generator 2.0.15 (core)",
    "info 2.3.2 (core)",
    "limits 2.2.2 (core)",
    "org 2.2.22 (core)",
    "packaging 1.12.2 (core)",
    "schema 2.2.2 (core)",
    "signups 1.2.12 (core)",
    "source 2.3.12 (core)",
    "telemetry 2.0.5 (core)",
    "templates 55.1.0 (core)",
    "trust 2.2.6 (core)",
    "user 2.1.25 (core)",
    "@salesforce/sfdx-diff 0.0.6 (user)",
    "@salesforce/sfdx-plugin-lwc-test 1.0.1 (core)",
    "salesforce-alm 54.8.5 (core)"
  ],
  "osVersion": "Windows_NT 10.0.19044",
  "shell": "cmd.exe",
  "rootPath": "C:\\Users\\pweinberg\\AppData\\Local\\sfdx\\client\\7.184.2-8a80929"
}

Unable to get Junit test result format when running Apex tests

Summary

Error "Invalid time value" occurs when executing force:apex:test:run or force:apex:test:report with the result format specified as -r junit

Steps To Reproduce:

MyTest.cls

@IsTest(isParallel = true)
class MyTest {
    @IsTest
    static void shouldFail() {
        System.assertEquals(1, 1 + 1);
    }

    @IsTest
    static void shouldPass() {
        System.assertEquals(2, 1 + 1);
    }
}

Run apex test and specify result format as junit:

sfdx force:apex:test:run --wait -1 -r junit -t MyTest

Expected result

Expected test results written to standard output in Junit format

Actual result

Results are output as JSON and error occurs

$ sfdx force:apex:test:run --wait -1 -r junit -t MyTest
{
  "summary": {
    "outcome": "Failed",
    "testsRan": 2,
    "passing": 1,
    "failing": 1,
    "skipped": 0,
    "passRate": "50%",
    "failRate": "50%",
    "skipRate": "0%",
    "testStartTime": "Thu Jun 24 2021 12:30:14 p.m.",
    "testExecutionTimeInMs": 34,
    "testTotalTimeInMs": 34,
    "commandTimeInMs": 287,
    "hostname": "https://example--alandev01.my.salesforce.com",
    "orgId": "00D1F000000YO2SUAW",
    "username": "[email protected]",
    "testRunId": "7071F0000208syH",
    "userId": "00530000003ZbzsAAC"
  },
  "tests": [
    {
      "id": "07M1F00000Mb95RUAR",
      "queueItemId": "7091F000002PGCzQAO",
      "stackTrace": "Class.Assert.fail: line 95, column 1\nClass.Assert.failNotEquals: line 145, column 1\nClass.Assert.equals: line 127, column 1\nClass.Assert.equals: line 108, column 1\nClass.MyTest.shouldFail: line 5, column 1",
      "message": "System.AssertException: Assertion Failed: Expected: <1>, Actual: <2>",
      "asyncApexJobId": "7071F0000208syHQAQ",
      "methodName": "shouldFail",
      "outcome": "Fail",
      "apexLogId": null,
      "apexClass": {
        "id": "01p1F00000JCxPPQA1",
        "name": "MyTest",
        "namespacePrefix": null,
        "fullName": "MyTest"
      },
      "runTime": 14,
      "testTimestamp": "2021-06-24T19:30:15.000+0000",
      "fullName": "MyTest.shouldFail",
      "diagnostic": {
        "exceptionMessage": "System.AssertException: Assertion Failed: Expected: <1>, Actual: <2>",
        "exceptionStackTrace": "Class.Assert.fail: line 95, column 1\nClass.Assert.failNotEquals: line 145, column 1\nClass.Assert.equals: line 127, column 1\nClass.Assert.equals: line 108, column 1\nClass.MyTest.shouldFail: line 5, column 1",
        "className": "Assert",
        "compileProblem": "",
        "lineNumber": 95,
        "columnNumber": 1
      }
    },
    {
      "id": "07M1F00000Mb95SUAR",
      "queueItemId": "7091F000002PGCzQAO",
      "stackTrace": null,
      "message": null,
      "asyncApexJobId": "7071F0000208syHQAQ",
      "methodName": "shouldPass",
      "outcome": "Pass",
      "apexLogId": null,
      "apexClass": {
        "id": "01p1F00000JCxPPQA1",
        "name": "MyTest",
        "namespacePrefix": null,
        "fullName": "MyTest"
      },
      "runTime": 20,
      "testTimestamp": "2021-06-24T19:30:38.000+0000",
      "fullName": "MyTest.shouldPass"
    }
  ]
}
Encountered an error when processing test results
RangeError: Invalid time value
    at Date.toISOString (<anonymous>)
    at JUnitReporter.format (/home/alan/.local/share/sfdx/client/7.107.0-621a7d2/node_modules/@salesforce/apex-node/lib/src/reporters/junitReporter.js:19:65)
    at Run.logJUnit (/home/alan/.local/share/sfdx/client/7.107.0-621a7d2/node_modules/@salesforce/plugin-apex/lib/commands/force/apex/test/run.js:164:30)
    at Run.<anonymous> (/home/alan/.local/share/sfdx/client/7.107.0-621a7d2/node_modules/@salesforce/plugin-apex/lib/commands/force/apex/test/run.js:83:30)
    at Generator.next (<anonymous>)
    at fulfilled (/home/alan/.local/share/sfdx/client/7.107.0-621a7d2/node_modules/@salesforce/plugin-apex/node_modules/tslib/tslib.js:112:62)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Additional information

Same result occurs when using force:apex:test:report

sfdx force:apex:test:report --wait -1 -r junit -i 7071F0000208syH

If the output directory flag is also specified, the output is slightly different but the result is still an error.

$ sfdx force:apex:test:run -r junit -w -1 -t MyTest -d test-results
WARNING: WARNING: In the Summer ’21 release, we'll rename or remove some of the output files that are created when you run force:apex:test:run or force:apex:test:report with the --outputdir (-d) parameter.  This breaking change could impact your CI/CD scripts if they reference specific filenames. See https://sfdc.co/apex-test-updates for details

ERROR running force:apex:test:run:  Invalid time value

No output files are written and the output directory test-results does not gets created.

SFDX CLI Version(to find the version of the CLI engine run sfdx --version): sfdx-cli/7.107.0 linux-x64 node-v14.17.1

SFDX plugin Version(to find the version of the CLI plugin run sfdx plugins --core)

 sfdx plugins --core
@alan-morey/sfdx-plugin 0.0.0 (link) /home/alan/repos/alan-morey-sfdx-plugin                                                                                                   
@oclif/plugin-autocomplete 0.3.0                                                                                                                                               
@oclif/plugin-commands 1.3.0 (core)
@oclif/plugin-help 3.2.2 (core)
@oclif/plugin-not-found 1.2.4 (core)
@oclif/plugin-plugins 1.10.0 (core)
@oclif/plugin-update 1.4.0-3 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-diff 0.0.6
@salesforce/sfdx-plugin-lwc-test 0.1.7 (core)
@salesforce/sfdx-scanner 2.9.2
@salesforce/sfdx-trust 3.6.0 (core)
alias 1.1.10 (core)
apex 0.2.2 (core)
apexlink 1.3.2
auth 1.6.1 (core)
config 1.2.8 (core)
custom-metadata 1.0.12 (core)
data 0.4.12 (core)
generator 1.1.7 (core)
gr-sfdx-plugin 0.0.0 (link) /home/alan/repos/salesforce/gr-sfdx-plugin
limits 1.2.1 (core)
org 1.6.7 (core)
salesforce-alm 52.0.2 (core)
schema 1.0.7 (core)
sfdx-cli 7.107.0 (core)
telemetry 1.2.2 (core)
templates 52.0.0 (core)                                                                                                                                                        
user 1.3.0 (core)   

OS and version: Ubuntu 18.04.5 LTS

force:apex:test:run with codecoverage enabled resulting in Apex Unit Test failures

Summary

When running "sfdx force:apex:test:run -c -r human --testlevel RunSpecifiedTests --classnames ... " , we are seeing errors in the "Apex Test Execution" section in the org:

  • Lots of "Code coverage from running this test class was not applied due to a conflicting recompilation task running at the same time. Please rerun this test class to recalculate code coverage." messages.

  • Huge increase in our CI pipelines times(~10x) at that specific stage. It looks like caused by codecoverage calculation

  • Some errors on unit tests like "Could not run test on class XXXX because: connection was cancelled here". When running the same unit tests in org individually , they do not fail and execution time is very low.

Note that this is happening only in large org with hundreds of classes and and multiple classes are being executed in a single test run. When running the same cmd without -c flag, the run is much faster and there is no failure of unit tests.Hence logically codecoverage calculation must be causing the above issues.

Steps To Reproduce:

Can't provide the exact steps to recreate as it depends on the tests code, so probably with some basic test you won't get those messages for timeouts and conflicts. But as mentioned above, this happens when above cmd is run from anywhere (terminal cli,vscode,pipeline).

  1. Push your code (tests included)

  2. Run: sfdx force:apex:test:run -c -r human --testlevel RunSpecifiedTests --classnames ...

  3. Open your org (web ui) and go to Setup > Apex Test Execution

Expected result

All the tests are executed successfully

Actual result

Execution time way longer than usual
Warnings: "Code coverage from running this test class was not applied due..."
Errors for classes timing out.

Additional information

Also this issue is intermittent, where some runs are successful but some are not. Cannot provide sample repo aswell because if tried with small and less unit tests, the issue will not occur. Happens only when multiple unit tests are ran in a single run and the unit tests are complex with multiple classes present in org.

SFDX CLI Version:

@oclif/plugin-autocomplete 1.3.0 (core)
@oclif/plugin-commands 2.2.0 (core)
@oclif/plugin-help 5.1.12 (core)
@oclif/plugin-not-found 2.3.1 (core)
@oclif/plugin-plugins 2.1.0 (core)
@oclif/plugin-update 3.0.0 (core)
@oclif/plugin-version 1.1.2 (core)
@oclif/plugin-warn-if-update-available 2.0.4 (core)
@oclif/plugin-which 2.1.0 (core)
@salesforce/sfdx-plugin-lwc-test 1.0.0 (core)
alias 2.1.0 (core)
apex 1.2.0 (core)
auth 2.2.3 (core)
community 2.0.1 (core)
config 1.4.17 (core)
custom-metadata 2.0.0 (core)
data 2.1.2 (core)
generator 2.0.2 (core)
info 2.0.1 (core)
limits 2.0.1 (core)
org 2.2.0 (core)
packaging 1.5.1 (core)
salesforce-alm 54.8.1 (core)
schema 2.1.1 (core)
sfdx-cli 7.166.1 (core)
signups 1.2.0 (core)
source 2.0.13 (core)
telemetry 2.0.0 (core)
templates 55.1.0 (core)
trust 2.0.3 (core)
user 2.1.0 (core)

OS and version:
Mac and linux

force:apex:test:run does not allow the user to run tests in managed packages

Summary

force:apex:test:run does not allow the user to run tests in managed packages which the current cli does.

Steps To Reproduce:

  1. Run the test command specifying the managed package test name e.g. sfdx force:apex:test:run -c -t "pDT01.TestLogger" -r human
  2. The command throws the following error:
sfdx force:apex:test:run -c -t "pDT01.TestLogger" -r human
Listening for streaming state changes...
ERROR running force:apex:test:run:  This class name's value is invalid: TestLogger. Provide the name of an Apex class that has test methods.

Expected result

The command should allow a user to run tests from managed packages. Below is the output of the current CLI commands:

sfdx force:apex:test:run -c -t "pDT01.TestLogger" -r human 
=== Apex Code Coverage
ID                  NAME                                    % COVERED           UNCOVERED LINES
──────────────────  ──────────────────────────────────────  ──────────────────  ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
01p4100000NWwavAAD  AssignmentPermSetHelper                 70%                 25,26,31,36,53,59,60,66,99,100,101,110,111,116,117,118,119,120,121
01p4100000NWwazAAD  PermstachioConfig                       100%
01q41000001kBYjAAM  AssignmentPermSetTrigger                100%
01p4100000NWwawAAD  AssignmentPermSetUtil                   81%                 17,42,52,57,101,102,103,107,108,111
01q2M000001r7MIQAY  Impala                                  NaN%
01q2M000001OnFmQAK  accountCreated                          NaN%
01q41000001qqmyAAA  AccountTrigger                          100%
01q41000001kBYkAAM  AssignmentRuleTrigger                   100%
01p4100000NWwb1AAD  PermstachioLogger                       40%                 8,9,18,19,27,28,29,30,31,33,34,35
01p4100000NWwaxAAD  AssignmentRuleHelper                    43%                 8,9,10,11
01p2M00000O6wEZQAZ  ExternalNlpHttpFormBuilder              100%
01p2M00000O6wEoQAJ  ExternalNlpServiceException             100%
01p2M00000O6wEiQAJ  ExternalNlpPredictionResult             100%
01p2M00000O6wEnQAJ  ExternalNlpService                      93%                 40,92,93,94
01p2M00000O6wEmQAJ  ExternalNlpSentiment                    76%                 20,21,40,41,42
01p2M00000O6wEYQAZ  ExternalNlpEntity                       56%                 33,34,37,38,41,42,45,46,75,76,77,81,82,83,86,87,88,91,92,93
01p2M00000O6wEpQAJ  ExternalNlpServiceExceptionCode         NaN%
01p2M00000O6wEXQAZ  ExternalNlpEmotion                      40%
01p2M00000O6wEhQAJ  ExternalNlpPredictionRequestParameters  76%                 17,18,40,41,42
01p2M00000O6wEdQAJ  ExternalNlpModelParameters              87%                 11,12
01p2M00000O6wEkQAJ  ExternalNlpPredictionSentimentResult    100%
01p2M00000O6wElQAJ  ExternalNlpPredictionToneResult         100%
01p2M00000O6wErQAJ  ExternalNlpServiceParameters            76%                 44,45,56,57,96,97,98,101,102,103,106,107,108
01p2M00000O6wEUQAZ  ExternalNlpDocumentEmotion              100%
01p2M00000O6wEjQAJ  ExternalNlpPredictionResultParameters   100%
01p2M00000O6wEbQAJ  ExternalNlpMockAPICalloutMockImpl       100%
01p2M00000O6wEWQAZ  ExternalNlpDocumentTone                 40%
01p2M00000O6wEaQAJ  ExternalNlpIntent                       40%
01p2M00000O6wEgQAJ  ExternalNlpPredictionIntentResult       100%
01p2M00000O6wEqQAJ  ExternalNlpServiceFactory               23%                 3,4,10,11,15,16,19,20,21,23
01p2M00000O6wEfQAJ  ExternalNlpPredictionEntityResult       100%
01p2M00000O6wEVQAZ  ExternalNlpDocumentSentiment            100%
01p2M00000O6wEeQAJ  ExternalNlpPredictionEmotionResult      44%
01p2M00000O6wEsQAJ  ExternalNlpTone                         100%
01p2M00000O6wEuQAJ  ExternalNlpWorkbenchCtrl                78.21782178217822%  40,49,77,97,98,105,107,108,109,110,111,112,115,116,117,118,119,120,121,148,152,153
01p2M00000O6wEtQAJ  ExternalNlpUtils                        100%
01p41000004rxNEAAY  z_BatchableMetadataDump3                100%
01p41000004rxNGAAY  z_DumpFrontPageCont                     53%                 17,64,65,66,67,69,70,81,82,83,84,86,89,92,93,94,95,98,99,100,103,104,105,109,110,111,112,114,117,118,119,121,131,132,133,134,137,138,139,142,148,149,155,156,164,165,166,167,168,177,183,184,185,187
01p41000004rxNCAAY  z_BatchableMetadataDump1                80%                 33,34,35
01p41000004rxNMAAY  z_Util                                  87%                 3,11,12,15,25,26,34,35,51,52,65,66,98,99
01p41000004rxNDAAY  z_BatchableMetadataDump2                91%                 73,74,75
01p41000004rxNHAAY  z_MetadataSettingCont                   81.81818181818183%  11,12
01p4100000MWatAAAT  SiteLoginController                     100%
01p4100000MWatCAAT  SiteRegisterController                  81.48148148148148%  39,40,43,44,45
01p4100000MWatEAAT  ChangePasswordController                100%
01p4100000MWatGAAT  ForgotPasswordController                88.88888888888889%  15
01p4100000MWatIAAT  MyProfilePageController                 87.5%               21,37,38
01p4100000NWwb2AAD  PermstachioStartController              100%
01p4100000NWwb0AAD  PermstachioInit                         54%                 74,77,85,86,87,88,91,94,96,97,98,100,101,103,104,105,106,107,108,110,111,113,114,115,116,117,118,121,122,123,124,127,128,131,132,134,141

=== Test Results
TEST NAME                      OUTCOME  MESSAGE  RUNTIME (MS)
─────────────────────────────  ───────  ───────  ────────────
TestLogger.testAccountTrigger  Pass              1421
TestLogger.testLoggerLog       Pass              8

=== Test Summary
NAME                 VALUE
───────────────────  ────────────────────────────
Outcome              Passed
Tests Ran            2
Passing              2
Failing              0
Skipped              0
Pass Rate            100%
Fail Rate            0%
Test Start Time      Mar 10, 2021 2:40 PM
Test Execution Time  1429 ms
Test Total Time      1429 ms
Command Time         5393 ms
Hostname             https://na96.salesforce.com
Org Id               00D41000000FH4IEAW
Username             [email protected]
Test Run Id          7072M0000BTgTKg
User Id              00541000000uEgSAAU
Test Run Coverage    77%
Org Wide Coverage    67%

WARNING: In Summer '20, the Apex test reporter will return more relevant and accurate code coverage results for test runs. To preview this change, set the environment variable SFDX_IMPROVED_CODE_COVERAGE='true'. Learn more at https://releasenotes.docs.salesforce.com/en-us/spring20/release-notes/rn_sf_cli_code_coverage_apextests.htm

sfcli apex test run command is throwing an error "Error (10): Cannot read properties of undefined (reading 'Status')"

Summary

sfcli apex test run command is throwing an error "

  • sf apex run test -o -l RunLocalTests -d {dir} -w 240 -r human -c
    Error (10): Cannot read properties of undefined (reading 'Status')"

Steps To Reproduce

IMPORTANT
First authenticate the user using salesforce cli. Use the authenticator token to run the following command

sf apex run test -o -l RunLocalTests -d {dir} -w 240 -r human -c

Expected result

This should give the test result report along with the coverage for each class

Actual result

It is throwing an error
"Error (10): Cannot read properties of undefined (reading 'Status')""

System Information

Jenkins linux agent

Salesforce cli version:

  • sf --version
    @salesforce/cli/2.26.10 linux-x64 node-v18.17.1

Test summary start time in locale causes issues with junit reporter

Summary

The syncTests.ts and asyncTests.ts build test summary JSON with start times in local locale. Later, when using these summaries to generate a junit report, the Date constructor fails to construct a valid date, causing a failure at;

RangeError: Invalid time value
    at Date.toISOString (<anonymous>)
    at JUnitReporter.format (/Users/jpower/Code/sfpowerscripts/packages/core/node_modules/@salesforce/apex-node/src/reporters/junitReporter.ts:32:61)

Should the test summary just have an ISO date string for start time instead, given intention to programmatically parse again later in junit reporter?

Steps To Reproduce:

  1. Setup machine to have a locale that will produce a date time string like: Sat Jul 22 2023 9:54:03 a.m. (like en-CA)
  2. Run apex tests via apex-node
  3. Use junit reporter to save results

Expected result

  1. Expect correctly parsed date

Actual result

  1. Error, invalid time value

Additional information

Apex library Version: "@salesforce/apex-node": "1.1.0"
OS and version: Darwin TRAC-C02F314EML7L 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64 x86_64

Publish job fails with timeout error on git tag step

Summary

When running the publish job it has failed twice now on the git tag step.
Screen Shot 2022-08-18 at 4 55 47 PM

I'm not sure if the --More-- is specific to the output in Circle or if it's actually having issues reading all of the displayed git tags.
This failure results in the tag never getting created in git or pushed to github as well as not pushing the commit version bump commit to the main branch.

Ideally it'd be nice if update the CI jobs to be more repeatable. Currently when the publish job fails on this step we can't rerun to fix the issue and have to manually intervene to get the repo back in a good state.

Steps To Reproduce:

See https://app.circleci.com/pipelines/github/forcedotcom/salesforcedx-apex/1404/workflows/e9152731-c977-4d47-99f6-ada841d300a2

Expected result

Should complete the publish job successfully.

Actual result

Fails to push git tag and version bump commit.

Missing classes in coverage report generated from sfdx force:apex:test:run

Recently I started observing issues related to code coverage report generation. Sometimes whole classes are not listed in report, so our SonarClourd Quality gate fails, even though class is covered with tests properly. When class is not listed in report, then also its not listed in list of classes that were executed.

Steps To Reproduce:

Attached in file (in comment)

Expected result

Class is listed as executed in tests, and coverage report is created

Actual result

Class is NOT listed as executed in tests, and coverage report is NOT created

System Information

Version is listed in attachment

force:apex:test:run causes "Your request exceeded the time limit for processing. connection was cancelled here" errors when tests run in parallel.

Summary

We've made an effort to clean up our unit tests to work with parallel execution, to speed up run times. Now we are encountering a new error, which only happens when running via sfdx force:apex:test:run

Your request exceeded the time limit for processing. connection was cancelled here

See also this issue on Salesforce Stack Exchange describing the issue.

Steps To Reproduce:

Enable parallel testing in an org with a decent number of tests(*), and run tests with SFDX:

  1. sfdx force:apex:test:run -u orgname --testlevel RunLocalTests -c -r json --wait 120 > testresults.json

(*) yes, "decent number of tests" is hand-wavy, and I cannot quantify better. My customer has a very large codebase, and it is proprietary; I cannot provide a link. Other mentions of this issue on the internet seem to think it occurs when "too many large unit tests try to run at once." Running these tests in serial takes over two hours, and exceeds our automation limits. We need a better solution.

Expected result

All tests should execute.

Actual result

Some tests execute, others fail with the error "Your request exceeded the time limit for processing. connection was cancelled here"

System Information

Run sfdx version --verbose --json and paste the output here.

{
        "cliVersion": "sfdx-cli/7.117.0",
        "architecture": "darwin-x64",
        "nodeVersion": "node-v14.17.6",
        "pluginVersions": [
                "@oclif/plugin-autocomplete 0.3.0 (core)",
                "@oclif/plugin-commands 1.3.0 (core)",
                "@oclif/plugin-help 3.2.2 (core)",
                "@oclif/plugin-not-found 1.2.4 (core)",
                "@oclif/plugin-plugins 1.10.1 (core)",
                "@oclif/plugin-update 1.4.0-3 (core)",
                "@oclif/plugin-warn-if-update-available 1.7.0 (core)",
                "@oclif/plugin-which 1.0.3 (core)",
                "@salesforce/sfdx-plugin-lwc-test 0.1.7 (core)",
                "@salesforce/sfdx-trust 3.6.0 (core)",
                "alias 1.1.10 (core)",
                "apex 0.2.8 (core)",
                "auth 1.7.1 (core)",
                "config 1.2.28 (core)",
                "custom-metadata 1.0.12 (core)",
                "data 0.6.1 (core)",
                "generator 1.1.7 (core)",
                "limits 1.2.1 (core)",
                "org 1.7.0 (core)",
                "salesforce-alm 52.3.2 (core)",
                "schema 1.0.8 (core)",
                "sfdx-cli 7.117.0 (core)",
                "sfpowerkit 3.2.3",
                "source 1.0.12 (core)",
                "telemetry 1.2.3 (core)",
                "templates 52.1.0 (core)",
                "user 1.4.0 (core)"
        ],
        "osVersion": "Darwin 18.7.0"
}

Additional information

I've also tried supplying a list of specific tests, like so:

cd force-app/main/default/classes
CLASSLIST=`grep -il '@IsTest' *.cls | sed 's/.cls$//' | tr '\n' ',' | sed 's/,$//'`
cd -
sfdx force:apex:test:run -u orgname --testlevel RunSpecifiedTests -n $CLASSLIST -c -r json --wait 120 > testresults.json

This also exhibits the issue.

Client name elided from screenshot
Screen Shot 2021-09-21 at 9 18 51 AM

sfdx force:apex:test:run hangs and provides no response

Summary

We have nightly regression job run using Jenkins, which includes pushing our source to a scratch org and reporting on unit tests.
When we run sfdx force:apex:test:run --testlevel RunLocalTests --targetusername RegressionScratchOrg --json the command hangs and we receive no response. If the build is not aborted, it hits the timeout (currently 3 hours). All other sfdx commands work as expected, and sfdx force:apex:test:run -h outputs usage documentation. We've tried with and without the --json flag, but neither scenario is producing a response.

I'm unable to replicate this when running the command locally, and this user can execute apex tests through the UI.

Steps To Reproduce:

Repository to reproduce: N/A (private repository)

  1. Jenkins authenticates with Dev Hub, creates scratch org and pushes source
  2. Execute sfdx force:apex:test:run --testlevel RunLocalTests --targetusername RegressionScratchOrg

Expected result

Jenkins logs output details run ID, e.g. Run "sfdx force:apex:test:report -i 7032z000007S0o9" to retrieve test results.

Actual result

Jenkins hangs waiting for a response.

Additional information

apex-test-run

SFDX CLI Version(to find the version of the CLI engine run sfdx --version):
sfdx-cli/7.107.0 linux-x64 node-v14.17.1

SFDX plugin Version(to find the version of the CLI plugin run sfdx plugins --core):
@oclif/plugin-autocomplete 0.3.0 (core)
@oclif/plugin-commands 1.3.0 (core)
@oclif/plugin-help 3.2.2 (core)
@oclif/plugin-not-found 1.2.4 (core)
@oclif/plugin-plugins 1.10.0 (core)
@oclif/plugin-update 1.4.0-3 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-plugin-lwc-test 0.1.7 (core)
@salesforce/sfdx-scanner 2.9.2
@salesforce/sfdx-trust 3.6.0 (core)
alias 1.1.10 (core)
apex 0.2.2 (core)
auth 1.6.1 (core)
config 1.2.8 (core)
custom-metadata 1.0.12 (core)
data 0.4.12 (core)
generator 1.1.7 (core)
limits 1.2.1 (core)
org 1.6.7 (core)
salesforce-alm 52.0.2 (core)
schema 1.0.7 (core)
sfdx-cli 7.107.0 (core)
sfdx-git-delta 4.6.1
telemetry 1.2.2 (core)
templates 52.0.0 (core)
user 1.3.0 (core)

OS and version: Linux

force:apex:test:run can throw "CLIError: timed out" beginning in v1.6 (CLI v7.185)

Summary

Users have reported seeing a CLIError: timed out error when running sfdx force:apex:test:run --resultformat junit --testlevel RunSpecifiedTests --wait=-1 for test suites that were running fine in previous versions starting in cli release 7.185.

The error message also states: ERROR running force:apex:test:run: Unknown error in Apex Library: timed out.

7.185 is the first CLI version to be released with apex-node library 1.6 (via plugin-source 2.3.15).

Steps To Reproduce:

TBD

Expected result

A test suite that runs successfully under CLI version 7.184 should also run successfully under CLI version 7.185.

Actual result

The test suite fails under version 7.185, and the output is not formatted as valid XML.

Additional information

Apex library Version:
1.6

OS and version:

force:apex:logs:get doesn't respect user locale when printing log START TIME

Summary

force:apex:logs:list outputs a list of log files with the datestamp in UTC. This means I have to try to do timezone conversion to figure out which logs I'm actually after.

Steps To Reproduce:

  1. sfdx force:apex:logs:list
  2. Observe that the "START TIME" column lists dates in ISO8601 format (good) but +0000 timezone offset (bad).

Expected result

I expect the datestamp to be in my locale, not UTC. This should either be my Salesforce user's locale, or my machine's locale. I'd prefer my machine's locale and this would probably be easier to implement.

Actual result

The datestamp is output in UTC time (+0000 offset) which means I have to do timezone conversion to figure out the date/time of the logs I'm looking for.

Additional information

n/a

Apex library Version:

apex 0.2.7 (core)

OS and version:

Windows 10, Version 21H1, Build 19043.1165

Incorrect status when running classes with no tests

Summary

Incorrect status when running classes with no tests

Steps To Reproduce:

  1. Specify a non-test Apex class name in the test:run command e.g. sfdx force:apex:test:run --tests AppHelper --json
  2. The command response sets the outcome as Passed
{
  "status": 0,
  "result": {
    "summary": {
      "outcome": "Passed",
      "testsRan": 0,
      "passing": 0,
      "failing": 0,
      "skipped": 0,
      "passRate": "0%",
      "failRate": "0%",
      "testStartTime": "Wed Mar 10 2021 11:56:35 AM",
      "testExecutionTime": "0 ms",
      "testTotalTime": "0 ms",
      "commandTime": "1042 ms",
      "hostname": "https://na49.salesforce.com",
      "orgId": "00Dxx0000016d9AUAQ",
      "username": "[email protected]",
      "testRunId": "707xx0000BiWaJv",
      "userId": "005xx000009m7tsQAA"
    },
    "tests": []
  }
}

Expected result

The outcome field to not be Passed

Cannot read properties of null (reading 'replace') when trying to retrieve Apex Test results

Summary

I am running the following command to retrieve Apex test run results.
sf apex get test -o --test-run-id -d --code-coverage -r human

Expected result

This should produce 6 files in the specified directory

Actual result

I received the following error.
Error (1): Cannot read properties of null (reading 'replace')

This error only occurs if if use the -d flag to specify where to save the results. If I run without the -d and path, I will get data returned which I can redirect to a file.

I have a similar problem when I try to use the -d parameter in running the test, although the error is slightly different.
Error (1): Cannot read properties of undefined (reading 'Status')

Steps To Reproduce

I've updated the sf client to ensure I had the latest version. I've run this against different SalesForce Orgs and specified different directories to eliminate environmental issues. I've also run this from a Mac and Linux. Everything seems to run fine until I specify the directory output. (I've tried relative and full paths)

System Information

System Information

{
"versionDetail": {
"cliVersion": "@salesforce/cli/2.5.8",
"architecture": "linux-arm64",
"nodeVersion": "node-v20.5.0",
"osVersion": "Linux 5.15.49-linuxkit-pr",
"shell": "ash",
"rootPath": "/usr/local/lib/node_modules/@salesforce/cli",
"pluginVersions": [
"@oclif/plugin-autocomplete 2.3.6 (core)",
"@oclif/plugin-commands 2.2.22 (core)",
"@oclif/plugin-help 5.2.17 (core)",
"@oclif/plugin-not-found 2.3.37 (core)",
"@oclif/plugin-plugins 3.2.6 (core)",
"@oclif/plugin-search 0.0.22 (core)",
"@oclif/plugin-update 3.1.32 (core)",
"@oclif/plugin-version 1.3.8 (core)",
"@oclif/plugin-warn-if-update-available 2.0.48 (core)",
"@oclif/plugin-which 2.2.30 (core)",
"@salesforce/cli 2.5.8 (core)",
"apex 2.3.10 (core)",
"auth 2.8.12 (core)",
"data 2.5.6 (core)",
"deploy-retrieve 1.17.5 (core)",
"info 2.6.39 (core)",
"limits 2.3.30 (core)",
"login 1.2.26 (core)",
"org 2.10.0 (core)",
"schema 2.3.23 (core)",
"settings 1.4.25 (core)",
"sobject 0.2.4 (core)",
"source 2.10.31 (core)",
"telemetry 2.3.0 (core)",
"templates 55.5.10 (core)",
"trust 2.6.1 (core)",
"user 2.3.28 (core)"
]
},
"sfdxEnvVars": [],
"sfEnvVars": [
[
"SF_AUTOUPDATE_DISABLE",
"true"
],
[
"SF_DISABLE_AUTOUPDATE",
"true"
],
[
"SF_UPDATE_INSTRUCTIONS",
"Use "npm update --global @salesforce/cli" to update npm-based installations."
]
],
"cliConfig": {
"_base": "@oclif/[email protected]",
"debug": 0,
"topicSeparator": " ",
"warned": false,
"commandPermutations": {
"validPermutations": {}
},
"topicPermutations": {
"validPermutations": {}
},
"_commands": {},
"_topics": {},
"root": "/usr/local/lib/node_modules/@salesforce/cli",
"name": "@salesforce/cli",
"version": "2.5.8",
"channel": "stable",
"valid": true,
"arch": "arm64",
"platform": "linux",
"windows": false,
"bin": "sf",
"binAliases": [
"sfdx"
],
"nsisCustomization": "scripts/nsis.nsi",
"dirname": "sf",
"flexibleTaxonomy": true,
"userAgent": "@salesforce/cli/2.5.8 linux-arm64 node-v20.5.0",
"shell": "ash",
"home": "/root",
"cacheDir": "/root/.cache/sf",
"configDir": "/root/.config/sf",
"dataDir": "/root/.local/share/sf",
"errlog": "/root/.cache/sf/error.log",
"_commandIDs": [
"cmdt:generate:field",
"force:cmdt:field:create",
"cmdt:field:create",
"cmdt:generate:fromorg",
"force:cmdt:generate",
"cmdt:generate:object",
"force:cmdt:create",
"cmdt:create",
"cmdt:generate:record",
"force:cmdt:record:create",
"cmdt:record:create",
"cmdt:generate:records",
"force:cmdt:record:insert",
"cmdt:record:insert",
"community:create",
"force:community:create",
"community:list:template",
"force:community:template:list",
"community:publish",
"force:community:publish",
"deploy:functions",
"dev:audit:messages",
"dev:configure:repo",
"dev:configure:secrets",
"dev:convert:messages",
"dev:convert:script",
"dev:generate:command",
"dev:generate:flag",
"dev:generate:library",
"dev:generate:plugin",
"plugins:generate",
"env:compute:collaborator:add",
"env:create:compute",
"env:delete",
"env:display",
"env:list",
"env:log",
"env:log:tail",
"env:logdrain:add",
"env:logdrain:list",
"env:logdrain:remove",
"env:open",
"env:var:get",
"env:var:list",
"env:var:set",
"env:var:unset",
"force:lightning:lwc:test:create",
"force:lightning:lwc:test:run",
"force:lightning:lwc:test:setup",
"generate:function",
"login:functions",
"login:functions:jwt",
"logout:functions",
"org:create:shape",
"force:org:shape:create",
"org:create:snapshot",
"force:org:snapshot:create",
"org:delete:shape",
"force:org:shape:delete",
"org:delete:snapshot",
"force:org:snapshot:delete",
"org:get:snapshot",
"force:org:snapshot:get",
"org:list:shape",
"force:org:shape:list",
"org:list:snapshot",
"force:org:snapshot:list",
"package:convert",
"force:package:convert",
"package:create",
"force:package:create",
"package:delete",
"force:package:delete",
"package:install",
"force:package:install",
"package:install:report",
"force:package:install:report",
"package:installed:list",
"force:package:installed:list",
"package:list",
"force:package:list",
"package:uninstall",
"force:package:uninstall",
"package:uninstall:report",
"force:package:uninstall:report",
"package:update",
"force:package:update",
"package:version:create",
"force:package:version:create",
"package:version:create:list",
"force:package:version:create:list",
"package:version:create:report",
"force:package:version:create:report",
"package:version:delete",
"force:package:version:delete",
"package:version:displayancestry",
"force:package:version:displayancestry",
"package:version:list",
"force:package:version:list",
"package:version:promote",
"force:package:version:promote",
"package:version:report",
"force:package:version:report",
"package:version:retrieve",
"package:version:update",
"force:package:version:update",
"package1:version:create",
"force:package1:version:create",
"package1:version:create:get",
"force:package1:version:create:get",
"package1:version:display",
"force:package1:version:display",
"package1:version:list",
"force:package1:version:list",
"run:function",
"run:function:start",
"run:function:start:container",
"run:function:start:local",
"scanner:rule:add",
"scanner:rule:describe",
"scanner:rule:list",
"scanner:rule:remove",
"scanner:run",
"scanner:run:dfa",
"whoami:functions",
"commands",
"help",
"plugins",
"plugins:inspect",
"plugins:install",
"plugins:add",
"plugins:link",
"plugins:uninstall",
"plugins:unlink",
"plugins:remove",
"plugins:update",
"update",
"telemetry",
"version",
"search",
"which",
"apex:get:log",
"force:apex:log:get",
"apex:get:test",
"force:apex:test:report",
"apex:list:log",
"force:apex:log:list",
"apex:run",
"force:apex:execute",
"apex:run:test",
"force:apex:test:run",
"apex:tail:log",
"force:apex:log:tail",
"org:list:auth",
"force:auth:list",
"auth:list",
"org:login:access-token",
"force:auth:accesstoken:store",
"auth:accesstoken:store",
"org:login:device",
"force:auth:device:login",
"auth:device:login",
"org:login:jwt",
"force:auth:jwt:grant",
"auth:jwt:grant",
"org:login:sfdx-url",
"force:auth:sfdxurl:store",
"auth:sfdxurl:store",
"org:login:web",
"force:auth:web:login",
"auth:web:login",
"org:logout",
"force:auth:logout",
"auth:logout",
"login",
"logout",
"data:create:record",
"force:data:record:create",
"data:delete:bulk",
"data:delete:record",
"force:data:record:delete",
"data:delete:resume",
"data:export:tree",
"force:data:tree:export",
"data:get:record",
"force:data:record:get",
"data:import:tree",
"force:data:tree:import",
"data:query",
"force:data:soql:query",
"data:query:resume",
"force:data:soql:bulk:report",
"data:resume",
"data:update:record",
"force:data:record:update",
"data:upsert:bulk",
"data:upsert:resume",
"force:data:bulk:delete",
"force:data:bulk:status",
"force:data:bulk:upsert",
"autocomplete",
"autocomplete:create",
"autocomplete:script",
"doctor",
"info:releasenotes:display",
"whatsnew",
"force:org:clone",
"force:org:create",
"force:org:delete",
"force:org:status",
"org:create:sandbox",
"env:create:sandbox",
"org:create:scratch",
"env:create:scratch",
"org:delete:sandbox",
"env:delete:sandbox",
"org:delete:scratch",
"env:delete:scratch",
"org:display",
"force:org:display",
"org:list",
"force:org:list",
"org:list:metadata",
"force:mdapi:listmetadata",
"org:list:metadata-types",
"force:mdapi:describemetadata",
"org:open",
"force:org:open",
"force:source:open",
"org:resume:sandbox",
"env:resume:sandbox",
"org:resume:scratch",
"env:resume:scratch",
"deploy",
"project:convert:mdapi",
"force:mdapi:convert",
"project:convert:source",
"force:source:convert",
"project:delete:source",
"force:source:delete",
"project:delete:tracking",
"force:source:tracking:clear",
"project:deploy:cancel",
"deploy:metadata:cancel",
"project:deploy:preview",
"deploy:metadata:preview",
"project:deploy:quick",
"deploy:metadata:quick",
"project:deploy:report",
"deploy:metadata:report",
"project:deploy:resume",
"deploy:metadata:resume",
"project:deploy:start",
"deploy:metadata",
"project:deploy:validate",
"deploy:metadata:validate",
"project:generate:manifest",
"force:source:manifest:create",
"project:list:ignored",
"force:source:ignored:list",
"project:reset:tracking",
"force:source:tracking:reset",
"project:retrieve:preview",
"retrieve:metadata:preview",
"project:retrieve:start",
"retrieve:metadata",
"sobject:describe",
"force:schema:sobject:describe",
"sobject:list",
"force:schema:sobject:list",
"limits:api:display",
"force:limits:api:display",
"org:list:limits",
"limits:recordcounts:display",
"force:limits:recordcounts:display",
"org:list:sobject:record-counts",
"schema:generate:field",
"generate:metadata:field",
"schema:generate:platformevent",
"generate:metadata:platformevent",
"schema:generate:sobject",
"generate:metadata:sobject",
"schema:generate:tab",
"generate:metadata:tab",
"alias:list",
"force:alias:list",
"alias:set",
"force:alias:set",
"alias:unset",
"force:alias:unset",
"config:get",
"force:config:get",
"config:list",
"force:config:list",
"config:set",
"force:config:set",
"config:unset",
"force:config:unset",
"plugins:trust:verify",
"force",
"force:mdapi:deploy",
"force:mdapi:deploy:cancel",
"force:mdapi:deploy:report",
"force:mdapi:retrieve",
"force:mdapi:retrieve:report",
"force:source:deploy",
"force:source:deploy:cancel",
"force:source:deploy:report",
"force:source:pull",
"force:source:push",
"force:source:retrieve",
"force:source:status",
"force:user:password:generate",
"force:user:permset:assign",
"force:user:permsetlicense:assign",
"org:assign:permset",
"org:assign:permsetlicense",
"org:create:user",
"force:user:create",
"org:display:user",
"force:user:display",
"org:generate:password",
"org:list:users",
"force:user:list",
"analytics:generate:template",
"force:analytics:template:create",
"apex:generate:class",
"force:apex:class:create",
"apex:generate:trigger",
"force:apex:trigger:create",
"lightning:generate:app",
"force:lightning:app:create",
"lightning:generate:component",
"force:lightning:component:create",
"lightning:generate:event",
"force:lightning:event:create",
"lightning:generate:interface",
"force:lightning:interface:create",
"lightning:generate:test",
"force:lightning:test:create",
"project:generate",
"force:project:create",
"static-resource:generate",
"force:staticresource:create",
"visualforce:generate:component",
"force:visualforce:component:create",
"visualforce:generate:page",
"force:visualforce:page:create"
],
"nodeEngine": ">=14.0.0"
},
"pluginSpecificData": {
"@salesforce/plugin-source": [
{
"targetOrgApiVersion": "58.0"
}
]
},
"diagnosticResults": [
{
"testName": "salesforcedx plugin not installed",
"status": "pass"
},
{
"testName": "no linked plugins",
"status": "pass"
},
{
"testName": "[@salesforce/plugin-source] sourceApiVersion matches apiVersion",
"status": "warn"
},
{
"testName": "using latest or latest-rc CLI version",
"status": "pass"
}
],
"suggestions": [
"Check https://github.com/forcedotcom/cli/issues for CLI issues posted by the community.",
"Check http://status.salesforce.com for general Salesforce availability and performance.",
"Neither sourceApiVersion nor apiVersion are defined. The commands that deploy and retrieve source use the max apiVersion of the target org in this case. The issue isn't a problem, as long as it's the behavior you actually want."
],
"logFilePaths": [
"/app/1693328165878-command-stdout.log",
"/app/1693328165878-command-debug.log"
],
"commandExitCode": 0,
"commandName": "sf force:org:list --all --dev-debug"
}/app #

Debug Information

Running the get test command above, I see the following:

...
sf:connection DEBUG request: {"method":"GET","url":"https://wexinc.my.salesforce.com/services/data/v58.0/tooling/query?q=SELECT%20PercentCovered%20FROM%20ApexOrgWideCoverage","headers":{"content-type":"application/json","user-agent":"sfdx toolbelt:"}} +3s
Error (1): Cannot read properties of null (reading 'replace')

*** Internal Diagnostic ***

TypeError: Cannot read properties of null (reading 'replace')
at JUnitReporter.xmlEscape (/usr/local/lib/node_modules/@salesforce/cli/node_modules/@salesforce/apex-node/lib/src/reporters/junitReporter.js:71:14)
at JUnitReporter.buildTestCases (/usr/local/lib/node_modules/@salesforce/cli/node_modules/@salesforce/apex-node/lib/src/reporters/junitReporter.js:53:37)
at JUnitReporter.format (/usr/local/lib/node_modules/@salesforce/cli/node_modules/@salesforce/apex-node/lib/src/reporters/junitReporter.js:27:24)
at TestService. (/usr/local/lib/node_modules/@salesforce/cli/node_modules/@salesforce/apex-node/lib/src/tests/testService.js:208:81)
at Generator.next ()
at /usr/local/lib/node_modules/@salesforce/cli/node_modules/@salesforce/apex-node/lib/src/tests/testService.js:8:71
at new Promise ()
at __awaiter (/usr/local/lib/node_modules/@salesforce/cli/node_modules/@salesforce/apex-node/lib/src/tests/testService.js:4:12)
at TestService.writeResultFiles (/usr/local/lib/node_modules/@salesforce/cli/node_modules/@salesforce/apex-node/lib/src/tests/testService.js:174:16)
at TestReporter.report (/usr/local/lib/node_modules/@salesforce/cli/node_modules/@salesforce/plugin-apex/lib/reporters/testReporter.js:34:31)


...

JSON flag not being accepted as resultformat for code coverage

Summary

Running this command featured in our documentation results in an error:
sfdx force:apex:test:run -n "MyTestName" -c --json

Steps To Reproduce:

  1. Run this command: sfdx force:apex:test:run -n "MyTestName" -c --json, where MyTestName is the name of a valid test class.
  2. Get this error: Select a result format when specifying code coverage

Expected result

--json is enough information for the code coverage result format.

Actual result

I need to add the resultformat to get it to work: sfdx force:apex:test:run -n "MyTestName" -c --resultformat=json

Additional information

We should either allow the --json flag to work without the --resultformat=json, or remove that example.

Apex library Version:
0.7.0

Add cobertura report format for force:apex:test:report command

Is your feature request related to a problem? Please describe.
On gitlab CI/CD if you want to visualize code coverage , you have to provide a cobertura report

What are you trying to do
Visualize code coverage on gitlab CI/CD or Azure DevOps

Describe the solution you'd like
It would be great if we could choose cobertura format in command force:apex:test:report
ie:
sfdx force:apex:test:report -i <test run id> -r cobertura

Describe alternatives you've considered
Develop a sfdx plugin to convert existing report output (human, junit or json) into cobertura format

Additional context
I tried to use this plugin but never managed to install it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.