import { TestReconciliationStateType } from './TestReconciliationState' ; import { JestFileResults , JestTotalResults } from 'jest-editor-support' ; import { FileCoverage } from 'istanbul-lib-coverage' ; import * as path from 'path' ; import { cleanAnsi , toLowerCaseDriveLetter } from '../helpers' ; import { MatchEvent } from './match-node' ; export interface Location { /** Zero-based column number */ column : number ; /** Zero-based line number */ line : number ; } export interface LocationRange { start : Location ; end : Location ; } export interface TestIdentifier { title : string ; ancestorTitles : string [ ] ; } export interface TestResult extends LocationRange { name : string ; identifier : TestIdentifier ; status : TestReconciliationStateType ; shortMessage ? : string ; terseMessage ? : string ; /** Zero-based line number */ lineNumberOfError ? : number ; multiResults ? : TestResult [ ] ; sourceHistory ? : MatchEvent [ ] ; assertionHistory ? : MatchEvent [ ] ; } function testResultWithLowerCaseWindowsDriveLetter ( testResult ) { const newFilePath = toLowerCaseDriveLetter ( testResult . name ) ; if ( newFilePath ) { return { ... testResult , name : newFilePath , } ; } return testResult ; } export const testResultsWithLowerCaseWindowsDriveLetters = ( testResults ) : JestFileResults [ ] => { if ( ! testResults ) { return testResults ; } return testResults . map ( testResultWithLowerCaseWindowsDriveLetter ) ; } ; function fileCoverageWithLowerCaseWindowsDriveLetter ( fileCoverage ) { const newFilePath = toLowerCaseDriveLetter ( fileCoverage . path ) ; if ( newFilePath ) { return { ... fileCoverage , path : newFilePath , } ; } return fileCoverage ; } export const coverageMapWithLowerCaseWindowsDriveLetters = ( data ) : any => { if ( ! data . coverageMap ) { return ; } const result = { } ; const filePaths = Object . keys ( data . coverageMap ) ; for ( const filePath of filePaths ) { const newFileCoverage = fileCoverageWithLowerCaseWindowsDriveLetter ( data . coverageMap [ filePath ] as FileCoverage ) ; result [ newFileCoverage . path ] = newFileCoverage ; } return result ; } ; param data export const resultsWithLowerCaseWindowsDriveLetters = ( data ) : JestTotalResults => { if ( path . sep === '\\' ) { return { ... data , coverageMap : coverageMapWithLowerCaseWindowsDriveLetters ( data ) , testResults : testResultsWithLowerCaseWindowsDriveLetters ( data . testResults ) , } ; } return data ; } ; /**
 * Removes ANSI escape sequence characters from test results in order to get clean messages
 */ export const resultsWithoutAnsiEscapeSequence = ( data ) : JestTotalResults => { if ( ! data || ! data . testResults ) { return data ; } return { ... data , testResults : data . testResults . map ( ( result ) => ( { ... result , message : cleanAnsi ( result . message ) , assertionResults : result . assertionResults . map ( ( assertion ) => ( { ... assertion , failureMessages : assertion . failureMessages . map ( ( message ) => cleanAnsi ( message ) ) , } ) ) , } ) ) , } ; } ; export interface StatusInfo { precedence : number ; desc : string ; } export const TestResultStatusInfo = { KnownFail : { precedence : 1 , desc : 'Failed' } , Unknown : { precedence : 2 , desc : 'Test has not run yet, due to Jest only running tests related to changes.' , } , KnownSkip : { precedence : 3 , desc : 'Skipped' } , KnownSuccess : { precedence : 4 , desc : 'Passed' } , KnownTodo : { precedence : 5 , desc : 'Todo' } , } ;