import * as jetpack from "fs-jetpack" ; import Mocha from "mocha" ; import { MochaAllureReporter } from "allure-mocha/runtime" ; import * as path from "path" ; import { InMemoryAllureWriter , TestResult } from "allure-js-commons" ; const testDir = "./test/fixtures/specs" ; export function runTests ( ... specs ) { const writer = new InMemoryAllureWriter ( ) ; const mocha = new Mocha ( ) ; mocha . reporter ( MochaAllureReporter , { writer } ) ; assignSpecs ( mocha , specs ) ; return new Promise ( ( resolve ) => { mocha . run ( ( ) => resolve ( writer ) ) ; } ) ; } export function findLabel ( test , labelName ) { return test . labels . find ( ( label ) => label . name === labelName ) ; } export function findParameter ( test , parameterName ) { return test . parameters . find ( ( parameter ) => parameter . name === parameterName ) ; } export function findStep ( test , stepName ) { return test . steps . find ( ( step ) => step . name === stepName ) ; } function assignSpecs ( mocha , specs ) { jetpack . dir ( testDir ) . find ( { matching : specs . map ( ( spec ) => `${ spec }.ts` ) } ) . forEach ( ( file ) => { const testPath = path . resolve ( testDir , file ) ; delete require . cache [ testPath ] ; mocha . addFile ( testPath ) ; } ) ; }