Skip to content

Commit cad58c5

Browse files
authored
fix: Adapter name wasn't getting set correctly (#1798)
1 parent 00a084a commit cad58c5

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"start": "bin/hubot",
3030
"gen": "bin/hubot --create myhubot",
3131
"pretest": "standard",
32-
"test": "node --test",
32+
"test": "node --test --test-timeout=20000",
3333
"test:smoke": "node src/**/*.js",
3434
"test:e2e": "bin/e2e-test.sh",
3535
"build:local": "npx @hubot-friends/sfab --folder ./docs --destination ./_site --verbose --serve /hubot/ --watch-path ./docs --scripts ./sfab-hooks",

src/Robot.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,9 @@ class Robot {
501501
//
502502
// Returns nothing.
503503
async loadAdapter (adapterPath = null) {
504-
if (this.adapter) {
504+
if (this.adapter && this.adapter.use) {
505505
this.adapter = await this.adapter.use(this)
506+
this.adapterName = this.adapter.name ?? this.adapter.constructor.name
506507
return
507508
}
508509
this.logger.debug(`Loading adapter ${adapterPath ?? 'from npmjs:'} ${this.adapterName}`)
@@ -521,6 +522,8 @@ class Robot {
521522
this.logger.error(`Cannot load adapter ${adapterPath ?? '[no path set]'} ${this.adapterName} - ${error}`)
522523
throw error
523524
}
525+
526+
this.adapterName = this.adapter.name ?? this.adapter.constructor.name
524527
}
525528

526529
async requireAdapterFrom (adapaterPath) {

test/AdapterName_test.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import test from 'node:test'
2+
import assert from 'node:assert/strict'
3+
import { Robot, Adapter } from '../index.mjs'
4+
5+
class InMemoryAdapter extends Adapter {
6+
}
7+
8+
function getRobotWithAdapter (adapter) {
9+
return new Robot({
10+
async use (robot) {
11+
adapter.robot = robot
12+
return adapter
13+
}
14+
}, false, 'Hubot', 't-bot')
15+
}
16+
17+
await test('Adapter Name', async (t) => {
18+
await t.test('Adapter argument is an object with user function', async () => {
19+
const adapter = new InMemoryAdapter()
20+
const robot = getRobotWithAdapter(adapter)
21+
await robot.loadAdapter()
22+
assert.equal(robot.adapterName, 'InMemoryAdapter')
23+
})
24+
25+
await t.test('Adapter argument is null', async () => {
26+
const robot = new Robot(null, false, 'Hubot', 't-bot')
27+
await robot.loadAdapter()
28+
assert.equal(robot.adapterName, 'Shell')
29+
})
30+
31+
await t.test('Adapter argument is a file path', async () => {
32+
const robot = new Robot('../test/fixtures/MockAdapter.mjs', false, 'Hubot', 't-bot')
33+
await robot.loadAdapter()
34+
assert.equal(robot.adapterName, 'MockAdapter')
35+
})
36+
})

0 commit comments

Comments
 (0)