UNPKG

apex-mutation-testing

Version:

Apex mutation testing plugin

60 lines 2.79 kB
import { Messages } from '@salesforce/core'; import { Flags, SfCommand } from '@salesforce/sf-plugins-core'; import { ApexMutationHTMLReporter } from '../../../../reporter/HTMLReporter.js'; import { ApexClassValidator } from '../../../../service/apexClassValidator.js'; import { MutationTestingService } from '../../../../service/mutationTestingService.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('apex-mutation-testing', 'apex.mutation.test.run'); export default class ApexMutationTest extends SfCommand { static summary = messages.getMessage('summary'); static description = messages.getMessage('description'); static examples = messages.getMessages('examples'); static flags = { 'apex-class': Flags.string({ char: 'c', summary: messages.getMessage('flags.apex-class.summary'), required: true, }), 'test-class': Flags.string({ char: 't', summary: messages.getMessage('flags.test-class.summary'), required: true, }), 'report-dir': Flags.directory({ char: 'r', summary: messages.getMessage('flags.report-dir.summary'), exists: true, default: 'mutations', }), 'target-org': Flags.requiredOrg(), 'api-version': Flags.orgApiVersion(), }; async run() { // parse the provided flags const { flags } = await this.parse(ApexMutationTest); const connection = flags['target-org'].getConnection(flags['api-version']); const parameters = { apexClassName: flags['apex-class'], apexTestClassName: flags['test-class'], reportDir: flags['report-dir'], }; this.log(messages.getMessage('info.CommandIsRunning', [ parameters.apexClassName, parameters.apexTestClassName, ])); const apexClassValidator = new ApexClassValidator(connection); await apexClassValidator.validate(parameters); const mutationTestingService = new MutationTestingService(this.progress, this.spinner, connection, parameters); const mutationResult = await mutationTestingService.process(); const htmlReporter = new ApexMutationHTMLReporter(); await htmlReporter.generateReport(mutationResult, parameters.reportDir); this.log(messages.getMessage('info.reportGenerated', [parameters.reportDir])); const score = mutationTestingService.calculateScore(mutationResult); this.log(messages.getMessage('info.CommandSuccess', [score])); this.info(messages.getMessage('info.EncourageSponsorship')); return { score, }; } } //# sourceMappingURL=run.js.map