diff --git a/messages/flags.md b/messages/flags.md index 88377ee..3d865b0 100644 --- a/messages/flags.md +++ b/messages/flags.md @@ -69,3 +69,7 @@ ID of the test run. # flags.detailed-coverage.summary Not available for flow tests. + +# flags.wait.summary + +Sets the streaming client socket timeout in minutes; specify a longer wait time if timeouts occur frequently. diff --git a/messages/flow.run.test.md b/messages/flow.run.test.md index 3890ad6..59a8dae 100644 --- a/messages/flow.run.test.md +++ b/messages/flow.run.test.md @@ -8,7 +8,7 @@ Specify which tests to run by using the --class-names flag followed by the names To see code coverage results, use the --code-coverage flag with --result-format. The output displays a high-level summary of the test run and the code coverage values for classes in your org. If you specify human-readable result format, use the --detailed-coverage flag to see detailed coverage results for each test method run. -By default, "flow run test" runs asynchronously and immediately returns a test run ID. If you use the -–synchronous flag, you can use the --wait flag to specify the number of minutes to wait; if the tests finish in that timeframe, the command displays the results. If the tests haven't finished by the end of the wait time, the command displays a test run ID. Use the "flow get test --test-run-id" command to get the results. +By default, "flow run test" runs asynchronously and immediately returns a test run ID. If you use the --synchronous flag, you can use the --wait flag to specify the number of minutes to wait; if the tests finish in that timeframe, the command displays the results. If the tests haven't finished by the end of the wait time, the command displays a test run ID. Use the "flow get test --test-run-id" command to get the results. You must have the "View All Data" org system permission to use this command. The permission is disabled by default and can be enabled only by a system administrator. @@ -24,7 +24,7 @@ You must have the "View All Data" org system permission to use this command. The <%= config.bin %> <%= command.id %> --tests Flow1.Test1 --tests Flow2.Test2 --test-level RunSpecifiedTests - Run all tests synchronously in your default org; the command waits to display the test results until all tests finish: - <%= config.bin %> <%= command.id %> –synchronous + <%= config.bin %> <%= command.id %> --synchronous - Run all local tests in the org with the username “me@my.org”; save the output to the specified directory: <%= config.bin %> <%= command.id %> --test-level RunLocalTests --output-dir /Users/susan/temp/cliOutput --target-org me@my.org diff --git a/src/commands/flow/run/test.ts b/src/commands/flow/run/test.ts index 4f1fcef..c7470e3 100644 --- a/src/commands/flow/run/test.ts +++ b/src/commands/flow/run/test.ts @@ -29,6 +29,7 @@ import { classNamesFlag, suiteNamesFlag, testsFlag, + waitFlag, } from '../../../flags.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); @@ -53,6 +54,7 @@ export default class FlowRunTest extends SfCommand { 'class-names': classNamesFlag, 'suite-names': suiteNamesFlag, tests: testsFlag, + wait: waitFlag, }; protected cancellationTokenSource = new CancellationTokenSource(); diff --git a/src/flags.ts b/src/flags.ts index d385858..90c74a4 100644 --- a/src/flags.ts +++ b/src/flags.ts @@ -110,3 +110,10 @@ export const detailedCoverageSummaryFlag = Flags.boolean({ summary: messages.getMessage('flags.detailed-coverage.summary'), dependsOn: ['code-coverage'], }); + +export const waitFlag = Flags.duration({ + unit: 'minutes', + char: 'w', + summary: messages.getMessage('flags.wait.summary'), + min: 0, +}); diff --git a/test/commands/flow/run/test.nut.ts b/test/commands/flow/run/test.nut.ts index 75c253d..316b6dd 100644 --- a/test/commands/flow/run/test.nut.ts +++ b/test/commands/flow/run/test.nut.ts @@ -13,33 +13,52 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import path from 'node:path'; +import { join } from 'node:path'; +import fs from 'node:fs'; import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; -import { config } from 'chai'; - +import { expect, config } from 'chai'; config.truncateThreshold = 0; describe('flow run test', () => { let session: TestSession; before(async () => { session = await TestSession.create({ - project: { - gitClone: 'https://github.com/trailheadapps/dreamhouse-lwc.git', - }, + project: { sourceDir: join('test', 'mock-projects', 'flow-run-template') }, devhubAuthStrategy: 'AUTO', scratchOrgs: [ { - config: path.join('config', 'project-scratch-def.json'), + config: join('config', 'project-scratch-def.json'), setDefault: true, alias: 'org', }, ], }); - execCmd('project:deploy:start -o org --source-dir force-app', { ensureExitCode: 0, cli: 'sf' }); + + execCmd('project deploy start -o org --source-dir force-app', { ensureExitCode: 0, cli: 'sf' }); }); after(async () => { - await session?.zip(undefined, 'artifacts'); await session?.clean(); }); + + describe('--result-format', () => { + it('will print tap format', async () => { + const result = execCmd('flow run test --result-format tap --wait 400', { ensureExitCode: 0 }).shellOutput.stdout; + expect(result).to.include('1..1'); + expect(result).to.include('ok 1'); + expect(result).to.include('--result-format " to retrieve test results in a different format.'); + }); + }); + + it('will create --output-dir', () => { + const result = execCmd('flow run test --output-dir testresults --code-coverage --wait 100', { ensureExitCode: 0 }) + .shellOutput.stdout; + expect(result).to.include('Test result files written to testresults'); + const outputDir = join(session.project.dir, 'testresults'); + expect(fs.statSync(outputDir).isDirectory()).to.be.true; + expect(fs.readdirSync(outputDir).length).to.equal(6); + expect(fs.existsSync(join(outputDir, 'test-result-codecoverage.json'))).to.be.true; + expect(fs.existsSync(join(outputDir, 'test-result.txt'))).to.be.true; + expect(fs.existsSync(join(outputDir, 'test-run-id.txt'))).to.be.true; + }); }); diff --git a/test/mock-projects/flow-run-template/.forceignore b/test/mock-projects/flow-run-template/.forceignore new file mode 100644 index 0000000..67a140a --- /dev/null +++ b/test/mock-projects/flow-run-template/.forceignore @@ -0,0 +1,16 @@ +# List files or directories below to ignore them when running force:source:push, force:source:pull, and force:source:status + +# More information: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_exclude_source.htm + +# + +package.xml + +# LWC configuration files + +**/jsconfig.json +**/.eslintrc.json + +# LWC Jest + +**/__tests__/** diff --git a/test/mock-projects/flow-run-template/README.md b/test/mock-projects/flow-run-template/README.md new file mode 100644 index 0000000..e69de29 diff --git a/test/mock-projects/flow-run-template/config/project-scratch-def.json b/test/mock-projects/flow-run-template/config/project-scratch-def.json new file mode 100644 index 0000000..6b02a7d --- /dev/null +++ b/test/mock-projects/flow-run-template/config/project-scratch-def.json @@ -0,0 +1,5 @@ +{ + "orgName": "flowtest company", + "edition": "Developer", + "features": [] +} diff --git a/test/mock-projects/flow-run-template/force-app/main/default/flows/Flow1.flow-meta.xml b/test/mock-projects/flow-run-template/force-app/main/default/flows/Flow1.flow-meta.xml new file mode 100644 index 0000000..d7821db --- /dev/null +++ b/test/mock-projects/flow-run-template/force-app/main/default/flows/Flow1.flow-meta.xml @@ -0,0 +1,51 @@ + + + 64.0 + false + Default + Flow1 {!$Flow.CurrentDateTime} + + + BuilderType + + LightningFlowBuilder + + + + CanvasMode + + AUTO_LAYOUT_CANVAS + + + + OriginBuilderType + + LightningFlowBuilder + + + AutoLaunchedFlow + + updateAccount + + 0 + 0 + + Description + + Test + + + $Record + + + 0 + 0 + + updateAccount + + Account + Create + RecordAfterSave + + Draft + diff --git a/test/mock-projects/flow-run-template/force-app/main/default/flowtests/Flow1_test.flowtest b/test/mock-projects/flow-run-template/force-app/main/default/flowtests/Flow1_test.flowtest new file mode 100644 index 0000000..ef90396 --- /dev/null +++ b/test/mock-projects/flow-run-template/force-app/main/default/flowtests/Flow1_test.flowtest @@ -0,0 +1,27 @@ + + + Flow1 + + + Start + + $Record + InputTriggeringRecordInitial + + {"Name":"FlowTestAccount1","OwnerId":"005xx000001X7qfAAC"} + + + + + + + updateAccount + HasError + + false + + + + Finish + + diff --git a/test/mock-projects/flow-run-template/sfdx-project.json b/test/mock-projects/flow-run-template/sfdx-project.json new file mode 100644 index 0000000..4c25204 --- /dev/null +++ b/test/mock-projects/flow-run-template/sfdx-project.json @@ -0,0 +1,12 @@ +{ + "packageDirectories": [ + { + "path": "force-app", + "default": true + } + ], + "name": "flow-run-template", + "namespace": "", + "sfdcLoginUrl": "https://login.salesforce.com", + "sourceApiVersion": "64.0" +}