import * as fs from "fs-extra" ; import * as os from "os" ; import expect from "should" ; import * as mochaTmpdir from "../src/mocha-tmpdir" ; function getTmpdirList ( matcher ) { const filelist = fs . readdirSync ( os . tmpdir ( ) ) ; return new Set ( filelist . filter ( ( name ) => matcher . test ( name ) ) ) ; } describe ( "Mocha-tmpdir each" , ( ) => { const prefix = "adapt-utils-test-tmpdir" ; const prefixRe = RegExp ( prefix ) ; const startingSet = getTmpdirList ( prefixRe ) ; const previous = new Set < string > ( ) ; mochaTmpdir . each ( prefix ) ; it ( "Should create a temp directory" , ( ) => { const cwd = process . cwd ( ) ; expect ( cwd ) . startWith ( os . tmpdir ( ) ) ; expect ( startingSet . has ( cwd ) ) . equals ( false ) ; previous . add ( cwd ) ; } ) ; it ( "Should delete the last dir and create new" , async ( ) => { const cwd = process . cwd ( ) ; expect ( cwd ) . startWith ( os . tmpdir ( ) ) ; expect ( startingSet . has ( cwd ) ) . equals ( false ) ; expect ( previous . has ( cwd ) ) . equals ( false ) ; const currentSet = getTmpdirList ( prefixRe ) ; previous . forEach ( ( name ) => { expect ( currentSet . has ( name ) ) . equals ( false ) ; } ) ; previous . add ( cwd ) ; } ) ; } ) ;