|
| 1 | +/* |
| 2 | + * Copyright 2025, Salesforce, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; |
| 17 | +import { expect, config } from 'chai'; |
| 18 | +import { TestRunIdResult } from '@salesforce/apex-node/lib/src/tests/types.js'; |
| 19 | +import { RunResult } from '../../../../src/reporters/index.js'; |
| 20 | +import { setupUnifiedFrameworkProject } from '../testHelper.js'; |
| 21 | + |
| 22 | +config.truncateThreshold = 0; |
| 23 | + |
| 24 | +describe('logic run test', () => { |
| 25 | + let session: TestSession; |
| 26 | + before(async () => { |
| 27 | + session = await setupUnifiedFrameworkProject(); |
| 28 | + }); |
| 29 | + |
| 30 | + after(async () => { |
| 31 | + await session?.clean(); |
| 32 | + }); |
| 33 | + |
| 34 | + describe('--test-category', () => { |
| 35 | + it('will run tests with Apex category', async () => { |
| 36 | + const result = execCmd('logic:run:test --test-category Apex --test-level RunLocalTests --wait 10', { |
| 37 | + ensureExitCode: 0 |
| 38 | + }).shellOutput.stdout; |
| 39 | + expect(result).to.include('CATEGORY'); |
| 40 | + expect(result).to.include('Apex'); |
| 41 | + expect(result).to.not.include('Flow'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('will run tests with Flow category', async () => { |
| 45 | + const result = execCmd('logic:run:test --test-category Flow --test-level RunLocalTests --wait 10', { |
| 46 | + ensureExitCode: 0 |
| 47 | + }).shellOutput.stdout; |
| 48 | + expect(result).to.include('CATEGORY'); |
| 49 | + expect(result).to.include('Flow'); |
| 50 | + expect(result).to.not.include('Apex'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('will run tests with multiple categories', async () => { |
| 54 | + const result = execCmd('logic:run:test --test-category Apex --test-category Flow --test-level RunLocalTests --wait 10', { |
| 55 | + ensureExitCode: 0 |
| 56 | + }).shellOutput.stdout; |
| 57 | + expect(result).to.include('CATEGORY'); |
| 58 | + expect(result).to.include('Apex'); |
| 59 | + expect(result).to.include('Flow'); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + describe('--class-names', () => { |
| 64 | + it('will run specified class', async () => { |
| 65 | + const result = execCmd('logic:run:test --class-names GeocodingServiceTest --wait 10', { |
| 66 | + ensureExitCode: 0 |
| 67 | + }).shellOutput.stdout; |
| 68 | + expect(result).to.match(/Tests Ran\s+3/); |
| 69 | + expect(result).to.include('GeocodingServiceTest'); |
| 70 | + expect(result).to.include('CATEGORY'); |
| 71 | + expect(result).to.include('Apex'); |
| 72 | + expect(result).to.not.include('Flow'); |
| 73 | + }); |
| 74 | + |
| 75 | + it('will run multiple specified classes from different categories', async () => { |
| 76 | + const result = execCmd('logic:run:test --class-names GeocodingServiceTest --class-names FlowTesting.Populate_opp_description --wait 10', { |
| 77 | + ensureExitCode: 0 |
| 78 | + }).shellOutput.stdout; |
| 79 | + expect(result).to.match(/Tests Ran\s+4/); |
| 80 | + expect(result).to.include('CATEGORY'); |
| 81 | + expect(result).to.include('Apex'); |
| 82 | + expect(result).to.include('Flow'); |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + describe('--tests', () => { |
| 87 | + it('will run specified test methods', async () => { |
| 88 | + const result = execCmd('logic:run:test --tests FlowTesting.Populate_opp_description.test_opportunity_updates --wait 10', { |
| 89 | + ensureExitCode: 0 |
| 90 | + }).shellOutput.stdout; |
| 91 | + expect(result).to.match(/Tests Ran\s+1/); |
| 92 | + expect(result).to.include('CATEGORY'); |
| 93 | + expect(result).to.include('Flow'); |
| 94 | + expect(result).to.include('Populate_opp_description.test_opportunity_updates'); |
| 95 | + expect(result).to.not.include('Apex'); |
| 96 | + }); |
| 97 | + |
| 98 | + it('will run multiple test methods from different categories', async () => { |
| 99 | + const result = execCmd('logic:run:test --tests TestPropertyController.testGetPicturesWithResults --tests FlowTesting.Populate_opp_description.test_opportunity_updates --wait 10', { |
| 100 | + ensureExitCode: 0 |
| 101 | + }).shellOutput.stdout; |
| 102 | + expect(result).to.match(/Tests Ran\s+2/); |
| 103 | + expect(result).to.include('CATEGORY'); |
| 104 | + expect(result).to.include('Apex'); |
| 105 | + expect(result).to.include('Flow'); |
| 106 | + expect(result).to.include('TestPropertyController.testGetPicturesWithResults'); |
| 107 | + expect(result).to.include('Populate_opp_description.test_opportunity_updates'); |
| 108 | + }); |
| 109 | + }); |
| 110 | + |
| 111 | + describe('JSON output', () => { |
| 112 | + it('will run tests and return JSON with Category property', async () => { |
| 113 | + const result = execCmd<RunResult>('logic:run:test --test-level RunLocalTests --wait 10 --json', { |
| 114 | + ensureExitCode: 0 |
| 115 | + }).jsonOutput?.result; |
| 116 | + expect(result?.tests.length).to.be.greaterThan(0); |
| 117 | + expect(result?.summary.outcome).to.equal('Passed'); |
| 118 | + expect(result?.summary).to.have.all.keys( |
| 119 | + 'outcome', |
| 120 | + 'testsRan', |
| 121 | + 'passing', |
| 122 | + 'failing', |
| 123 | + 'skipped', |
| 124 | + 'passRate', |
| 125 | + 'failRate', |
| 126 | + 'testStartTime', |
| 127 | + 'testExecutionTime', |
| 128 | + 'testTotalTime', |
| 129 | + 'commandTime', |
| 130 | + 'hostname', |
| 131 | + 'orgId', |
| 132 | + 'username', |
| 133 | + 'testRunId', |
| 134 | + 'userId' |
| 135 | + ); |
| 136 | + expect(result?.tests[0]).to.have.all.keys( |
| 137 | + 'Id', |
| 138 | + 'QueueItemId', |
| 139 | + 'StackTrace', |
| 140 | + 'Message', |
| 141 | + 'AsyncApexJobId', |
| 142 | + 'Category', |
| 143 | + 'MethodName', |
| 144 | + 'Outcome', |
| 145 | + 'ApexClass', |
| 146 | + 'RunTime', |
| 147 | + 'FullName' |
| 148 | + ); |
| 149 | + }); |
| 150 | + }); |
| 151 | + |
| 152 | + describe('async execution', () => { |
| 153 | + it('will run tests async and return test run id', async () => { |
| 154 | + const result = execCmd<TestRunIdResult>('logic:run:test --test-category Flow --test-level RunLocalTests --json', { |
| 155 | + ensureExitCode: 0 |
| 156 | + }).jsonOutput?.result; |
| 157 | + expect(result?.testRunId).to.be.a('string'); |
| 158 | + expect(result?.testRunId.startsWith('707')).to.be.true; |
| 159 | + }); |
| 160 | + }); |
| 161 | + |
| 162 | + describe('--synchronous', () => { |
| 163 | + it('will run tests synchronously', async () => { |
| 164 | + const result = execCmd('logic:run:test --test-category Apex --test-level RunLocalTests --synchronous', { |
| 165 | + ensureExitCode: 0 |
| 166 | + }).shellOutput.stdout; |
| 167 | + expect(result).to.include('Outcome'); |
| 168 | + expect(result).to.include('CATEGORY'); |
| 169 | + expect(result).to.include('Apex'); |
| 170 | + expect(result).to.include('Passed'); |
| 171 | + }); |
| 172 | + }); |
| 173 | +}); |
0 commit comments