@@ -4,23 +4,24 @@ import { describe, it, beforeEach, afterEach } from 'node:test'
44import assert from 'node:assert/strict'
55import { Robot , TextMessage , User } from '../index.mjs'
66import stream from 'node:stream'
7- import fs from 'node:fs'
8- import { writeFile } from 'node:fs/promises'
7+ import { writeFile , stat } from 'node:fs/promises'
8+ import { fileURLToPath } from 'node:url'
9+ import path from 'node:path'
910
1011describe ( 'Shell history file test' , ( ) => {
1112 it ( 'History file is > 1024 bytes when running does not throw an error' , async ( ) => {
1213 const robot = new Robot ( 'Shell' , false , 'TestHubot' )
1314 robot . stdin = new stream . Readable ( )
1415 robot . stdin . _read = ( ) => { }
15- const __dirname = new URL ( '.' , import . meta. url ) . pathname
16- const historyPath = `${ __dirname } /../.hubot_history`
16+ const __filename = fileURLToPath ( import . meta. url )
17+ const __dirname = path . dirname ( __filename )
18+ const historyPath = path . join ( __dirname , '..' , '.hubot_history' )
1719 await writeFile ( historyPath , 'a' . repeat ( 1025 ) )
1820 await robot . loadAdapter ( )
1921 await robot . run ( )
20- assert . ok ( fs . existsSync ( historyPath ) , 'History file should exist' )
2122 try {
22- const stats = fs . statSync ( historyPath )
23- assert . ok ( stats . size <= 1024 , 'History file should be less than or equal to 1024 bytes after running the robot' )
23+ const fileInfo = await stat ( historyPath )
24+ assert . ok ( fileInfo . size <= 1024 , 'History file should be less than or equal to 1024 bytes after running the robot' )
2425 } catch ( error ) {
2526 assert . fail ( 'Should not throw an error when reading history file' )
2627 } finally {
0 commit comments