Skip to content

Commit 1ebf598

Browse files
authored
fix: XampleTest script loading order (#1714)
* fix: scripts that use the Express router were not loaded in order in the XampleTest * fix: Github actions message to use 20 instead of 18
1 parent a5db89e commit 1ebf598

8 files changed

Lines changed: 34 additions & 15 deletions

File tree

.github/workflows/nodejs-macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
node-version: [18.x]
16+
node-version: [20.x]
1717

1818
steps:
1919
- uses: actions/checkout@v3

.github/workflows/nodejs-ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
node-version: [18.x, latest]
16+
node-version: [20.x, latest]
1717

1818
steps:
1919
- uses: actions/checkout@v3

.github/workflows/nodejs-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: windows-latest
1111
strategy:
1212
matrix:
13-
node-version: [18.x]
13+
node-version: [20.x]
1414
steps:
1515
- uses: actions/checkout@v3
1616
- name: Use Node.js ${{ matrix.node-version }}

.github/workflows/pipeline.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
matrix:
2222
node-version:
23-
- 18.x
23+
- 20.x
2424
steps:
2525
- name: Checkout
2626
uses: actions/checkout@v3
@@ -42,7 +42,7 @@ jobs:
4242
strategy:
4343
matrix:
4444
node-version:
45-
- 18.x
45+
- 20.x
4646
steps:
4747
- name: Checkout
4848
uses: actions/checkout@v3
@@ -64,7 +64,7 @@ jobs:
6464
strategy:
6565
matrix:
6666
node-version:
67-
- 18.x
67+
- 20.x
6868
steps:
6969
- name: Checkout
7070
uses: actions/checkout@v3

src/GenHubot.mjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export default (robot) => {
5656
robot.respond(/helo room/, async res => {
5757
await res.send('Hello World!')
5858
})
59+
robot.router.get('/helo', async (req, res) => {
60+
res.send("HELO World! I'm Dumbotheelephant.")
61+
})
5962
}`)
6063

6164
File.writeFileSync('./tests/doubles/DummyAdapter.mjs', `
@@ -125,14 +128,21 @@ export default (robot) => {
125128
describe('Xample testing Hubot scripts', () => {
126129
let robot = null
127130
beforeEach(async () => {
128-
robot = new Robot(dummyRobot, false, 'Dumbotheelephant')
131+
robot = new Robot(dummyRobot, true, 'Dumbotheelephant')
129132
await robot.loadAdapter()
130-
await robot.loadFile('./scripts', 'Xample.mjs')
131133
await robot.run()
134+
await robot.loadFile('./scripts', 'Xample.mjs')
132135
})
133136
afterEach(() => {
134137
robot.shutdown()
135138
})
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+
})
136146
it('should reply with expected message', async () => {
137147
const expected = "HELO World! I'm Dumbotheelephant."
138148
const user = robot.brain.userForId('test-user', { name: 'test user' })

src/Robot.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,12 @@ class Robot {
470470
// returns nothing
471471
setupNullRouter () {
472472
const msg = 'A script has tried registering a HTTP route while the HTTP server is disabled with --disabled-httpd.'
473-
473+
const self = this
474474
this.router = {
475-
get: () => this.logger.warning(msg),
476-
post: () => this.logger.warning(msg),
477-
put: () => this.logger.warning(msg),
478-
delete: () => this.logger.warning(msg)
475+
get: () => self.logger.info(msg),
476+
post: () => self.logger.info(msg),
477+
put: () => self.logger.info(msg),
478+
delete: () => self.logger.info(msg)
479479
}
480480
}
481481

test/XampleTest.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ import dummyRobot from './doubles/DummyAdapter.mjs'
1313
describe('Xample testing Hubot scripts', () => {
1414
let robot = null
1515
beforeEach(async () => {
16-
robot = new Robot(dummyRobot, false, 'Dumbotheelephant')
16+
robot = new Robot(dummyRobot, true, 'Dumbotheelephant')
1717
await robot.loadAdapter()
18-
await robot.loadFile('./test/scripts', 'Xample.mjs')
1918
await robot.run()
19+
await robot.loadFile('./test/scripts', 'Xample.mjs')
2020
})
2121
afterEach(() => {
2222
robot.shutdown()
2323
})
24+
it('should handle /helo request', async () => {
25+
const expected = "HELO World! I'm Dumbotheelephant."
26+
const response = await fetch(`http://localhost:${robot.server.address().port}/helo`)
27+
const actual = await response.text()
28+
assert.strictEqual(actual, expected)
29+
})
2430
it('should reply with expected message', async () => {
2531
const expected = 'HELO World! I\'m Dumbotheelephant.'
2632
const user = robot.brain.userForId('test-user', { name: 'test user' })

test/scripts/Xample.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ export default (robot) => {
1515
robot.respond(/helo (.*)/gi, async res => {
1616
await res.send(`Hello World! I'm ${robot.name}.`)
1717
})
18+
robot.router.get('/helo', async (req, res) => {
19+
res.send(`HELO World! I'm ${robot.name}.`)
20+
})
1821
}

0 commit comments

Comments
 (0)