CoE CLI arendamine, uue käsu lisamine (kasutuselt kõrvaldatud)

Märkus

CoE CLI on aegunud ja uusi funktsioone ei lisata. Probleeme enam ei vaadata ega lahendata.

Kui tuvastate võimaliku turvaprobleemi, palun teatage sellest Microsofti küberturbe reageerimiskeskus-le.

Lisaks Power Platform halduskeskusele kaaluge Microsoft Power Platform CLI, Power Platform API, Power Platform inventory API ja Power Platform for Admins V2 ühendust.

Uue näidiskäsu lisamiseks kasutage järgmist käsku, et mallindada käsu TypeScript algseadistus ja Jest JavaScripti testimise raamistiku üksuse test.

cd coe-cli
coe cli add -n sample

Ühendage käsk käsureale

Kui olete uue käsuüksuse testimise lõpule viinud, tehke järgmist.

  1. Vaadake üle https://www.npmjs.com/package/commander seoses käskude ja valikutega.

  2. Värskendage faili värskendada commands.ts, et kaasata uus käsk või alamkäsk.

    • Importige failid faili ülaosast.

      import { SampleArguments, SampleCommand} from './sample';
      
    • Lisage näidise sisestusele funktsioon.

      createSampleCommand: () => SampleCommand
      
    • Looge loomise funktsioonis käsk.

      this.createSampleCommand = () => new SampleCommand
      
    • Lisage funktsioon.

       AddSampleCommand(program: commander.Command) {
           var run = program.command('sample')
               .description('A new sample command')
               .option('-c, --comment <comment>', 'The comment for the command')
               .action(async (options: any) : Promise<void> => {
                   let args = new SampleArguments();
                   args.comment = options.comment;
                   let command = this.createSampleCommand();
                   await command.execute(args)
               });
       }
      
    • Registreerige uus käsk init-funktsioonile.

      this.AddSampleCommand(program);
      
  3. Värskendage faili commands.spec.ts, et lisada üksuse testid.

    • Lisage viide käsule.

      import { SampleCommand } from '../../src/commands/sample'
      
    • Lisage Jest-testide komplekt.

      describe('Sample', () => {
          test('Execute', async () => {
              // Arrange
              var commands = new CoeCliCommands();
              let mockSampleCommand = mock<SampleCommand>(); 
      
              commands.createSampleCommand = () => { return mockSampleCommand }
      
              mockSampleCommand.execute.mockResolvedValue()
      
              // Act
              await commands.execute(['node', 'commands.spec', 'sample', '-c', 'Some comment'])
      
              // Assert
              expect(mockSampleCommand.execute).toHaveBeenCalled()
          })
      });
      
  4. Käivitage ühikutestid uute muudatustega.

    npm run test