import { Test , TestService , TestCallback } from './types' ; export * from './types' ; let callbackService = ( ) => { throw new Error ( 'No callback service for test setup.' ) ; } ; function getCallerFile ( ) { const original = Error . prepareStackTrace ; Error . prepareStackTrace = ( err , stack ) => stack ; const error = new Error ( ) ; if ( ! error . stack ) { throw new Error ( 'Cannot get caller file: no stack to trace.' ) ; } let { stack } = ( error as any ) as { stack : NodeJS . CallSite [ ] ; } ; const currentFile = stack . shift ( ) ! . getFileName ( ) ; let callerFile = currentFile ; while ( error . stack . length && currentFile === callerFile ) { stack = ( error . stack as any ) as NodeJS . CallSite [ ] ; callerFile = stack . shift ( ) ! . getFileName ( ) ; } Error . prepareStackTrace = original ; return callerFile || '' ; } export function setCallbackService ( service ) { callbackService = service ; } const test = ( config , callback ) => { const file = getCallerFile ( ) ; callbackService ( config , callback , file ) ; } ; test . skip = ( config , callback ) => test ( { ... config , skip : true } , callback ) ; export default test ; export function proofsOf ( kind ) { return { add ( story , callback ) { callbackService ( { kind , story , skip : false , } , callback , getCallerFile ( ) ) ; } , } ; }