hubot 11.0.3 → 11.1.1
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/LICENSE.md +1 -1
- package/package.json +1 -1
- package/src/GenHubot.mjs +117 -4
- package/src/Robot.mjs +5 -5
package/LICENSE.md
CHANGED
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,129 @@ 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
|
})
|
|
59
|
+
robot.router.get('/helo', async (req, res) => {
|
|
60
|
+
res.send("HELO World! I'm Dumbotheelephant.")
|
|
61
|
+
})
|
|
56
62
|
}`)
|
|
57
63
|
|
|
64
|
+
File.writeFileSync('./tests/doubles/DummyAdapter.mjs', `
|
|
65
|
+
'use strict'
|
|
66
|
+
import { Adapter, TextMessage } from 'hubot'
|
|
67
|
+
|
|
68
|
+
export class DummyAdapter extends Adapter {
|
|
69
|
+
constructor (robot) {
|
|
70
|
+
super(robot)
|
|
71
|
+
this.name = 'DummyAdapter'
|
|
72
|
+
this.messages = new Set()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async send (envelope, ...strings) {
|
|
76
|
+
this.emit('send', envelope, ...strings)
|
|
77
|
+
this.robot.emit('send', envelope, ...strings)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async reply (envelope, ...strings) {
|
|
81
|
+
this.emit('reply', envelope, ...strings)
|
|
82
|
+
this.robot.emit('reply', envelope, ...strings)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async topic (envelope, ...strings) {
|
|
86
|
+
this.emit('topic', envelope, ...strings)
|
|
87
|
+
this.robot.emit('topic', envelope, ...strings)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async play (envelope, ...strings) {
|
|
91
|
+
this.emit('play', envelope, ...strings)
|
|
92
|
+
this.robot.emit('play', envelope, ...strings)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
run () {
|
|
96
|
+
// This is required to get the scripts loaded
|
|
97
|
+
this.emit('connected')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
close () {
|
|
101
|
+
this.emit('closed')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async say (user, message, room) {
|
|
105
|
+
this.messages.add(message)
|
|
106
|
+
user.room = room
|
|
107
|
+
await this.robot.receive(new TextMessage(user, message))
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export default {
|
|
111
|
+
use (robot) {
|
|
112
|
+
return new DummyAdapter(robot)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
`)
|
|
116
|
+
File.writeFileSync('./tests/XampleTest.mjs', `
|
|
117
|
+
import { describe, it, beforeEach, afterEach } from 'node:test'
|
|
118
|
+
import assert from 'node:assert/strict'
|
|
119
|
+
|
|
120
|
+
import { Robot } from 'hubot'
|
|
121
|
+
|
|
122
|
+
// You need a dummy adapter to test scripts
|
|
123
|
+
import dummyRobot from './doubles/DummyAdapter.mjs'
|
|
124
|
+
|
|
125
|
+
// Mocks Aren't Stubs
|
|
126
|
+
// https://www.martinfowler.com/articles/mocksArentStubs.html
|
|
127
|
+
|
|
128
|
+
describe('Xample testing Hubot scripts', () => {
|
|
129
|
+
let robot = null
|
|
130
|
+
beforeEach(async () => {
|
|
131
|
+
robot = new Robot(dummyRobot, true, 'Dumbotheelephant')
|
|
132
|
+
await robot.loadAdapter()
|
|
133
|
+
await robot.run()
|
|
134
|
+
await robot.loadFile('./scripts', 'Xample.mjs')
|
|
135
|
+
})
|
|
136
|
+
afterEach(() => {
|
|
137
|
+
robot.shutdown()
|
|
138
|
+
})
|
|
139
|
+
it('should handle /helo request', async () => {
|
|
140
|
+
const expected = "HELO World! I'm Dumbotheelephant."
|
|
141
|
+
const url = 'http://localhost:' + robot.server.address().port + '/helo'
|
|
142
|
+
const response = await fetch(url)
|
|
143
|
+
const actual = await response.text()
|
|
144
|
+
assert.strictEqual(actual, expected)
|
|
145
|
+
})
|
|
146
|
+
it('should reply with expected message', async () => {
|
|
147
|
+
const expected = "HELO World! I'm Dumbotheelephant."
|
|
148
|
+
const user = robot.brain.userForId('test-user', { name: 'test user' })
|
|
149
|
+
let actual = ''
|
|
150
|
+
robot.on('reply', (envelope, ...strings) => {
|
|
151
|
+
actual = strings.join('')
|
|
152
|
+
})
|
|
153
|
+
await robot.adapter.say(user, '@Dumbotheelephant helo', 'test-room')
|
|
154
|
+
assert.strictEqual(actual, expected)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('should send message to the #general room', async () => {
|
|
158
|
+
const expected = 'general'
|
|
159
|
+
const user = robot.brain.userForId('test-user', { name: 'test user' })
|
|
160
|
+
let actual = ''
|
|
161
|
+
robot.on('send', (envelope, ...strings) => {
|
|
162
|
+
actual = envelope.room
|
|
163
|
+
})
|
|
164
|
+
await robot.adapter.say(user, '@Dumbotheelephant helo room', 'general')
|
|
165
|
+
assert.strictEqual(actual, expected)
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
`)
|
|
169
|
+
|
|
58
170
|
const packageJsonPath = path.resolve(process.cwd(), 'package.json')
|
|
59
171
|
const packageJson = JSON.parse(File.readFileSync(packageJsonPath, 'utf8'))
|
|
60
172
|
|
|
61
173
|
packageJson.scripts = {
|
|
62
|
-
start: 'hubot'
|
|
174
|
+
start: 'hubot',
|
|
175
|
+
test: 'node --test'
|
|
63
176
|
}
|
|
64
177
|
packageJson.description = 'A simple helpful robot for your Company'
|
|
65
178
|
if (options.adapter) {
|
package/src/Robot.mjs
CHANGED
|
@@ -470,12 +470,12 @@ class Robot {
|
|
|
470
470
|
// returns nothing
|
|
471
471
|
setupNullRouter () {
|
|
472
472
|
const msg = 'A script has tried registering a HTTP route while the HTTP server is disabled with --disabled-httpd.'
|
|
473
|
-
|
|
473
|
+
const self = this
|
|
474
474
|
this.router = {
|
|
475
|
-
get: () =>
|
|
476
|
-
post: () =>
|
|
477
|
-
put: () =>
|
|
478
|
-
delete: () =>
|
|
475
|
+
get: () => self.logger.info(msg),
|
|
476
|
+
post: () => self.logger.info(msg),
|
|
477
|
+
put: () => self.logger.info(msg),
|
|
478
|
+
delete: () => self.logger.info(msg)
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
481
|
|