Skip to content

Commit e306f2e

Browse files
authored
fix: Test fails on Windows because of path calculation differences. #1788 (#1789)
1 parent cc6f350 commit e306f2e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

test/Shell_test.mjs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@ import { describe, it, beforeEach, afterEach } from 'node:test'
44
import assert from 'node:assert/strict'
55
import { Robot, TextMessage, User } from '../index.mjs'
66
import 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

1011
describe('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

Comments
 (0)