license import { Spec } from './spec.js' ; import { Fixturable } from './mixins/fixturable.js' ; import { Suite } from './suite.js' ; import { Test , TestResult , TestRunContext } from './test.js' ; import { timePasses } from './util.js' ; import '../../../chai/chai.js' ; const spec = new ( Fixturable ( Spec ) ) ( ) ; const { expect } = ( self as any ) . chai ; const { describe , it , before , after } = spec ; describe ( 'Test' , ( ) => { before ( ( context ) => { let testRunCount = 0 ; const testSpy = { get runCount ( ) { return testRunCount ; } , implementation : ( ) => { testRunCount ++ ; } } ; const suite = new Suite ( [ ] ) ; return { ... context , suite , testSpy , test : new Test ( 'is awesome' , testSpy . implementation , { } ) } ; } ) ; it ( 'always assumes tests could be asynchronous' , ( { test , suite } ) => { expect ( test . run ( suite ) ) . to . be . instanceof ( Promise ) ; } ) ; it ( 'invokes the implementation when run' , async ( { test , testSpy , suite } ) => { await test . run ( suite ) ; expect ( testSpy . runCount ) . to . be . equal ( 1 ) ; } ) ; describe ( 'postProcess' , ( ) => { before ( ( context ) => { const originalPostProcess = ( Test as any ) . prototype . postProcess ; Object . defineProperty ( Test . prototype , 'postProcess' , { value : ( _context , result ) => { return { ... result , special : true } ; } } ) ; return { ... context , originalPostProcess } ; } ) ; after ( ( { originalPostProcess } ) => { Object . defineProperty ( Test . prototype , 'postProcess' , { value : originalPostProcess } ) ; } ) ; it ( 'manipulates the TestResult after the test is run' , async ( { test , suite } ) => { const result = await test . run ( suite ) ; expect ( result . special ) . to . be . equal ( true ) ; } ) ; } ) ; describe ( 'when timing out' , ( ) => { before ( ( context ) => ( { ... context , test : new Test ( 'is timing out' , async ( ) => await timePasses ( 100 ) , { timeout : 50 } ) } ) ) ; it ( 'eventually fails' , async ( { test , suite } ) => { const result = await test . run ( suite ) ; expect ( result . passed ) . to . be . equal ( false ) ; expect ( result . error ) . to . be . instanceof ( Error ) ; } ) ; } ) ; } ) ; export const testSpec = spec ;