github.com/kubeshop/testkube@v1.17.23/test/cli-tests/helpers/output-validators.js (about)

     1  import { expect } from 'chai';
     2  
     3  class OutputValidators {
     4      removeAnsiCodes(rawOutput) {
     5          const output = rawOutput.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
     6  
     7          return output
     8      }
     9  
    10      normalizeSpaces(output) {
    11          return output.replace(/\s+/g, ' ').trim()
    12      }
    13  
    14      validateTestCreated(testName, output) {
    15          const testCreatedText = `Test created testkube / ${testName}`
    16  
    17          expect(output).to.include(testCreatedText)
    18      }
    19  
    20      validateTestRunStarted(testData, output) {
    21          const normalizedOutput = this.normalizeSpaces(output)
    22  
    23          const typeText = `Type: ${testData.type}`
    24          const nameText = `Name: ${testData.name}`
    25          const statusText = `Status: running`
    26          const testExecutionStartedText = 'Test execution started'
    27          
    28          expect(normalizedOutput).to.include(typeText)
    29          expect(normalizedOutput).to.include(nameText)
    30          expect(normalizedOutput).to.include(statusText)
    31          expect(normalizedOutput).to.include(testExecutionStartedText)
    32      }
    33  
    34      validateTestExecutionSummary(executionData, output) {
    35          const normalizedOutput = this.normalizeSpaces(output)
    36  
    37          for (let key in executionData) {
    38              var value = executionData[key];
    39  
    40              if(key == 'Name') { //special case because of this bug: https://github.com/kubeshop/testkube/issues/2655
    41                  expect(normalizedOutput).to.include(`${key} ${value}`)
    42              } else {
    43                  expect(normalizedOutput).to.include(`${key}: ${value}`)
    44              }
    45          }
    46      }
    47  
    48      getExecutionId(output) {
    49          const normalizedOutput = this.normalizeSpaces(output)
    50  
    51          const executionIdRegex = /Execution ID:\s(?<id>\w+)/gm;
    52          const executionId = executionIdRegex.exec(normalizedOutput).groups.id
    53  
    54          return executionId
    55      }
    56  }
    57  export default OutputValidators