hubot 11.0.2 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/GenHubot.mjs +107 -4
- package/src/Robot.mjs +2 -2
package/package.json
CHANGED
package/src/GenHubot.mjs
CHANGED
|
@@ -26,7 +26,7 @@ function runCommands (hubotDirectory, options) {
|
|
|
26
26
|
}
|
|
27
27
|
output = spawnSync('npm', ['i', 'hubot-help@latest', 'hubot-rules@latest', 'hubot-diagnostics@latest'].concat([options.adapter]).filter(Boolean))
|
|
28
28
|
console.log('npm i', output.stderr.toString(), output.stdout.toString())
|
|
29
|
-
spawnSync('mkdir', ['scripts'])
|
|
29
|
+
spawnSync('mkdir', ['scripts', 'tests', 'tests/doubles'])
|
|
30
30
|
spawnSync('touch', ['external-scripts.json'])
|
|
31
31
|
|
|
32
32
|
const externalScriptsPath = path.resolve('./', 'external-scripts.json')
|
|
@@ -39,7 +39,7 @@ function runCommands (hubotDirectory, options) {
|
|
|
39
39
|
|
|
40
40
|
File.writeFileSync(externalScriptsPath, JSON.stringify(externalScripts, null, 2))
|
|
41
41
|
|
|
42
|
-
File.writeFileSync('./scripts/
|
|
42
|
+
File.writeFileSync('./scripts/Xample.mjs', `// Description:
|
|
43
43
|
// Test script
|
|
44
44
|
//
|
|
45
45
|
// Commands:
|
|
@@ -50,16 +50,119 @@ function runCommands (hubotDirectory, options) {
|
|
|
50
50
|
//
|
|
51
51
|
|
|
52
52
|
export default (robot) => {
|
|
53
|
-
robot.respond(/helo
|
|
53
|
+
robot.respond(/helo$/, async res => {
|
|
54
|
+
await res.reply("HELO World! I'm Dumbotheelephant.")
|
|
55
|
+
})
|
|
56
|
+
robot.respond(/helo room/, async res => {
|
|
54
57
|
await res.send('Hello World!')
|
|
55
58
|
})
|
|
56
59
|
}`)
|
|
57
60
|
|
|
61
|
+
File.writeFileSync('./tests/doubles/DummyAdapter.mjs', `
|
|
62
|
+
'use strict'
|
|
63
|
+
import { Adapter, TextMessage } from 'hubot'
|
|
64
|
+
|
|
65
|
+
export class DummyAdapter extends Adapter {
|
|
66
|
+
constructor (robot) {
|
|
67
|
+
super(robot)
|
|
68
|
+
this.name = 'DummyAdapter'
|
|
69
|
+
this.messages = new Set()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async send (envelope, ...strings) {
|
|
73
|
+
this.emit('send', envelope, ...strings)
|
|
74
|
+
this.robot.emit('send', envelope, ...strings)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async reply (envelope, ...strings) {
|
|
78
|
+
this.emit('reply', envelope, ...strings)
|
|
79
|
+
this.robot.emit('reply', envelope, ...strings)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async topic (envelope, ...strings) {
|
|
83
|
+
this.emit('topic', envelope, ...strings)
|
|
84
|
+
this.robot.emit('topic', envelope, ...strings)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async play (envelope, ...strings) {
|
|
88
|
+
this.emit('play', envelope, ...strings)
|
|
89
|
+
this.robot.emit('play', envelope, ...strings)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
run () {
|
|
93
|
+
// This is required to get the scripts loaded
|
|
94
|
+
this.emit('connected')
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
close () {
|
|
98
|
+
this.emit('closed')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async say (user, message, room) {
|
|
102
|
+
this.messages.add(message)
|
|
103
|
+
user.room = room
|
|
104
|
+
await this.robot.receive(new TextMessage(user, message))
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export default {
|
|
108
|
+
use (robot) {
|
|
109
|
+
return new DummyAdapter(robot)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
`)
|
|
113
|
+
File.writeFileSync('./tests/XampleTest.mjs', `
|
|
114
|
+
import { describe, it, beforeEach, afterEach } from 'node:test'
|
|
115
|
+
import assert from 'node:assert/strict'
|
|
116
|
+
|
|
117
|
+
import { Robot } from 'hubot'
|
|
118
|
+
|
|
119
|
+
// You need a dummy adapter to test scripts
|
|
120
|
+
import dummyRobot from './doubles/DummyAdapter.mjs'
|
|
121
|
+
|
|
122
|
+
// Mocks Aren't Stubs
|
|
123
|
+
// https://www.martinfowler.com/articles/mocksArentStubs.html
|
|
124
|
+
|
|
125
|
+
describe('Xample testing Hubot scripts', () => {
|
|
126
|
+
let robot = null
|
|
127
|
+
beforeEach(async () => {
|
|
128
|
+
robot = new Robot(dummyRobot, false, 'Dumbotheelephant')
|
|
129
|
+
await robot.loadAdapter()
|
|
130
|
+
await robot.loadFile('./scripts', 'Xample.mjs')
|
|
131
|
+
await robot.run()
|
|
132
|
+
})
|
|
133
|
+
afterEach(() => {
|
|
134
|
+
robot.shutdown()
|
|
135
|
+
})
|
|
136
|
+
it('should reply with expected message', async () => {
|
|
137
|
+
const expected = "HELO World! I'm Dumbotheelephant."
|
|
138
|
+
const user = robot.brain.userForId('test-user', { name: 'test user' })
|
|
139
|
+
let actual = ''
|
|
140
|
+
robot.on('reply', (envelope, ...strings) => {
|
|
141
|
+
actual = strings.join('')
|
|
142
|
+
})
|
|
143
|
+
await robot.adapter.say(user, '@Dumbotheelephant helo', 'test-room')
|
|
144
|
+
assert.strictEqual(actual, expected)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('should send message to the #general room', async () => {
|
|
148
|
+
const expected = 'general'
|
|
149
|
+
const user = robot.brain.userForId('test-user', { name: 'test user' })
|
|
150
|
+
let actual = ''
|
|
151
|
+
robot.on('send', (envelope, ...strings) => {
|
|
152
|
+
actual = envelope.room
|
|
153
|
+
})
|
|
154
|
+
await robot.adapter.say(user, '@Dumbotheelephant helo room', 'general')
|
|
155
|
+
assert.strictEqual(actual, expected)
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
`)
|
|
159
|
+
|
|
58
160
|
const packageJsonPath = path.resolve(process.cwd(), 'package.json')
|
|
59
161
|
const packageJson = JSON.parse(File.readFileSync(packageJsonPath, 'utf8'))
|
|
60
162
|
|
|
61
163
|
packageJson.scripts = {
|
|
62
|
-
start: 'hubot'
|
|
164
|
+
start: 'hubot',
|
|
165
|
+
test: 'node --test'
|
|
63
166
|
}
|
|
64
167
|
packageJson.description = 'A simple helpful robot for your Company'
|
|
65
168
|
if (options.adapter) {
|
package/src/Robot.mjs
CHANGED
|
@@ -544,7 +544,7 @@ class Robot {
|
|
|
544
544
|
let currentSection = null
|
|
545
545
|
let nextSection
|
|
546
546
|
|
|
547
|
-
this.logger.debug(`Parsing help for ${
|
|
547
|
+
this.logger.debug(`Parsing help for ${filePath}`)
|
|
548
548
|
|
|
549
549
|
for (let i = 0, line; i < lines.length; i++) {
|
|
550
550
|
line = lines[i]
|
|
@@ -568,7 +568,7 @@ class Robot {
|
|
|
568
568
|
}
|
|
569
569
|
|
|
570
570
|
if (currentSection === null) {
|
|
571
|
-
this.logger.info(`${
|
|
571
|
+
this.logger.info(`${filePath} is using deprecated documentation syntax`)
|
|
572
572
|
scriptDocumentation.commands = []
|
|
573
573
|
for (let i = 0, line, cleanedLine; i < lines.length; i++) {
|
|
574
574
|
line = lines[i]
|