Skip to content

Commit dd7c114

Browse files
committed
chore: Use stats and await to ensure the history file is created. Also, add doc comments
1 parent 33eec79 commit dd7c114

7 files changed

Lines changed: 48 additions & 8 deletions

File tree

configuration/Config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
// Description:
2+
// Configuration
3+
//
4+
// Commands:
5+
//
6+
// Notes:
7+
// This is a test script.
8+
//
9+
110
export default async robot => {
211
robot.config = {}
312
}

src/adapters/Shell.mjs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
import fs from 'node:fs'
4+
import { stat, writeFile, unlink } from 'node:fs/promises'
45
import readline from 'node:readline'
56
import Adapter from '../Adapter.mjs'
67
import { TextMessage } from '../Message.mjs'
@@ -44,12 +45,15 @@ class Shell extends Adapter {
4445
}
4546

4647
async run () {
47-
const stats = fs.statSync(historyPath)
48-
if (stats.size > historySize) {
49-
fs.unlinkSync(historyPath)
50-
}
51-
if (!fs.existsSync(historyPath)) {
52-
fs.writeFileSync(historyPath, '')
48+
try {
49+
const stats = await stat(historyPath)
50+
if (stats.size > historySize) {
51+
await unlink(historyPath)
52+
await writeFile(historyPath, '')
53+
}
54+
} catch (error) {
55+
console.log(error)
56+
await writeFile(historyPath, '')
5357
}
5458

5559
this.#rl = readline.createInterface({

test/DataStore_test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import assert from 'node:assert/strict'
55
import InMemoryDataStore from '../src/datastores/Memory.mjs'
66
import Brain from '../src/Brain.mjs'
77

8-
describe.skip('Datastore', () => {
8+
describe('Datastore', () => {
99
let robot = null
1010
beforeEach(() => {
1111
robot = {

test/Shell_test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import stream from 'node:stream'
77
import fs from 'node:fs'
88
import { writeFile } from 'node:fs/promises'
99

10-
describe.skip('Shell history file test', () => {
10+
describe('Shell history file test', () => {
1111
it('History file is > 1024 bytes when running does not throw an error', async () => {
1212
const robot = new Robot('Shell', false, 'TestHubot')
1313
robot.stdin = new stream.Readable()

test/ordered-scripts/01-PFirst.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
// Description:
2+
// First one
3+
//
4+
// Commands:
5+
//
6+
// Notes:
7+
// This is a test script.
8+
//
9+
110
export default async robot => {
211
robot.loadedScripts = []
312
robot.loadedScripts.push('01-First')
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
// Description:
2+
// Setup bot configuration
3+
//
4+
// Commands:
5+
//
6+
// Notes:
7+
// This is a test script.
8+
//
9+
110
export default async robot => {
211
robot.loadedScripts.push('02-Second')
312
}

test/ordered-scripts/WebSetup.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
// Description:
2+
// Third one
3+
//
4+
// Commands:
5+
//
6+
// Notes:
7+
// This is a test script.
8+
//
9+
110
export default async robot => {
211
robot.loadedScripts.push('03-Third')
312
}

0 commit comments

Comments
 (0)