import * as ts from 'typescript' ; import { AstUtils } from './AstUtils' ; import { Utils } from './Utils' ; /**
 * Common functions for Mocha AST.
 */ export namespace MochaUtils { export function isMochaTest ( node ) { return Utils . exists ( node . statements , ( statement ) : boolean => { return isStatementDescribeCall ( statement ) ; } ) ; } export function isStatementDescribeCall ( statement ) { if ( statement . kind === ts . SyntaxKind . ExpressionStatement ) { const expression = ( < ts . ExpressionStatement > statement ) . expression ; if ( expression . kind === ts . SyntaxKind . CallExpression ) { const call = < ts . CallExpression > expression ; return isDescribe ( call ) ; } } return false ; } /**
     * Tells you if the call is a describe or context call.
     */ export function isDescribe ( call ) { const functionName = AstUtils . getFunctionName ( call ) ; const callText = call . expression . getText ( ) ; return functionName === 'describe' || functionName === 'context' || /(describe|context)\.(only|skip|timeout)/ . test ( callText ) ; } /**
     * Tells you if the call is an it(), specify(), before(), etc.
     */ export function isLifecycleMethod ( call ) { const functionName = AstUtils . getFunctionName ( call ) ; return ( functionName === 'it' || functionName === 'specify' || functionName === 'before' || functionName === 'beforeEach' || functionName === 'beforeAll' || functionName === 'after' || functionName === 'afterEach' || functionName === 'afterAll' ) ; } }