@@ -2,58 +2,57 @@ import assert from "node:assert/strict";
22import fs from "node:fs" ;
33import os from "node:os" ;
44import path from "node:path" ;
5- import { after , before , describe , it } from "node:test" ;
5+ import { describe , it , type TestContext } from "node:test" ;
66
77import { findCurrentReplyIndexPath } from "./cmake-file-api.js" ;
88
99function createMockReplyDirectory (
10+ context : TestContext ,
1011 replyFiles : [ string , Record < string , unknown > ] [ ] ,
1112) {
1213 const tmpPath = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "test-" ) ) ;
1314
14- before ( ( ) => {
15- for ( const [ fileName , content ] of replyFiles ) {
16- const filePath = path . join ( tmpPath , fileName ) ;
17- fs . writeFileSync ( filePath , JSON . stringify ( content ) , {
18- encoding : "utf-8" ,
19- } ) ;
20- }
21- } ) ;
15+ for ( const [ fileName , content ] of replyFiles ) {
16+ const filePath = path . join ( tmpPath , fileName ) ;
17+ fs . writeFileSync ( filePath , JSON . stringify ( content ) , {
18+ encoding : "utf-8" ,
19+ } ) ;
20+ }
2221
23- after ( ( ) => {
22+ context . after ( ( ) => {
2423 fs . rmSync ( tmpPath , { recursive : true , force : true } ) ;
2524 } ) ;
2625
2726 return tmpPath ;
2827}
2928
3029describe ( "findCurrentReplyIndexPath" , ( ) => {
31- it ( "returns the correct path when only index files are present" , async ( ) => {
32- const tmpPath = createMockReplyDirectory ( [
30+ it ( "returns the correct path when only index files are present" , async function ( context ) {
31+ const tmpPath = createMockReplyDirectory ( context , [
3332 [ "index-a.json" , { } ] ,
3433 [ "index-b.json" , { } ] ,
3534 ] ) ;
3635 const result = await findCurrentReplyIndexPath ( tmpPath ) ;
3736 assert . strictEqual ( result , path . join ( tmpPath , "index-b.json" ) ) ;
3837 } ) ;
39- it ( "returns the correct path when only error files are present" , async ( ) => {
40- const tmpPath = createMockReplyDirectory ( [
38+ it ( "returns the correct path when only error files are present" , async function ( context ) {
39+ const tmpPath = createMockReplyDirectory ( context , [
4140 [ "error-a.json" , { } ] ,
4241 [ "error-b.json" , { } ] ,
4342 ] ) ;
4443 const result = await findCurrentReplyIndexPath ( tmpPath ) ;
4544 assert . strictEqual ( result , path . join ( tmpPath , "error-b.json" ) ) ;
4645 } ) ;
47- it ( "returns the correct path when both index and error files are present" , async ( ) => {
48- const tmpPath = createMockReplyDirectory ( [
46+ it ( "returns the correct path when both index and error files are present" , async function ( context ) {
47+ const tmpPath = createMockReplyDirectory ( context , [
4948 [ "index-a.json" , { } ] ,
5049 [ "error-b.json" , { } ] ,
5150 ] ) ;
5251 const result = await findCurrentReplyIndexPath ( tmpPath ) ;
5352 assert . strictEqual ( result , path . join ( tmpPath , "error-b.json" ) ) ;
5453 } ) ;
55- it ( "returns the correct path when both index and error files are present (reversed)" , async ( ) => {
56- const tmpPath = createMockReplyDirectory ( [
54+ it ( "returns the correct path when both index and error files are present (reversed)" , async function ( context ) {
55+ const tmpPath = createMockReplyDirectory ( context , [
5756 [ "error-a.json" , { } ] ,
5857 [ "index-b.json" , { } ] ,
5958 ] ) ;
0 commit comments