Skip to content

Commit

Permalink
fix: XampleTest script loading order (#1714)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
joeyguerra committed Feb 17, 2024
1 parent a5db89e commit 1ebf598
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [18.x, latest]
node-version: [20.x, latest]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
node-version: [18.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
node-version:
- 18.x
- 20.x
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -42,7 +42,7 @@ jobs:
strategy:
matrix:
node-version:
- 18.x
- 20.x
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -64,7 +64,7 @@ jobs:
strategy:
matrix:
node-version:
- 18.x
- 20.x
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
14 changes: 12 additions & 2 deletions src/GenHubot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export default (robot) => {
robot.respond(/helo room/, async res => {
await res.send('Hello World!')
})
robot.router.get('/helo', async (req, res) => {
res.send("HELO World! I'm Dumbotheelephant.")
})
}`)

File.writeFileSync('./tests/doubles/DummyAdapter.mjs', `
Expand Down Expand Up @@ -125,14 +128,21 @@ export default (robot) => {
describe('Xample testing Hubot scripts', () => {
let robot = null
beforeEach(async () => {
robot = new Robot(dummyRobot, false, 'Dumbotheelephant')
robot = new Robot(dummyRobot, true, 'Dumbotheelephant')
await robot.loadAdapter()
await robot.loadFile('./scripts', 'Xample.mjs')
await robot.run()
await robot.loadFile('./scripts', 'Xample.mjs')
})
afterEach(() => {
robot.shutdown()
})
it('should handle /helo request', async () => {
const expected = "HELO World! I'm Dumbotheelephant."
const url = 'http://localhost:' + robot.server.address().port + '/helo'
const response = await fetch(url)
const actual = await response.text()
assert.strictEqual(actual, expected)
})
it('should reply with expected message', async () => {
const expected = "HELO World! I'm Dumbotheelephant."
const user = robot.brain.userForId('test-user', { name: 'test user' })
Expand Down
10 changes: 5 additions & 5 deletions src/Robot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,12 @@ class Robot {
// returns nothing
setupNullRouter () {
const msg = 'A script has tried registering a HTTP route while the HTTP server is disabled with --disabled-httpd.'

const self = this
this.router = {
get: () => this.logger.warning(msg),
post: () => this.logger.warning(msg),
put: () => this.logger.warning(msg),
delete: () => this.logger.warning(msg)
get: () => self.logger.info(msg),
post: () => self.logger.info(msg),
put: () => self.logger.info(msg),
delete: () => self.logger.info(msg)
}
}

Expand Down
10 changes: 8 additions & 2 deletions test/XampleTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ import dummyRobot from './doubles/DummyAdapter.mjs'
describe('Xample testing Hubot scripts', () => {
let robot = null
beforeEach(async () => {
robot = new Robot(dummyRobot, false, 'Dumbotheelephant')
robot = new Robot(dummyRobot, true, 'Dumbotheelephant')
await robot.loadAdapter()
await robot.loadFile('./test/scripts', 'Xample.mjs')
await robot.run()
await robot.loadFile('./test/scripts', 'Xample.mjs')
})
afterEach(() => {
robot.shutdown()
})
it('should handle /helo request', async () => {
const expected = "HELO World! I'm Dumbotheelephant."
const response = await fetch(`http://localhost:${robot.server.address().port}/helo`)
const actual = await response.text()
assert.strictEqual(actual, expected)
})
it('should reply with expected message', async () => {
const expected = 'HELO World! I\'m Dumbotheelephant.'
const user = robot.brain.userForId('test-user', { name: 'test user' })
Expand Down
3 changes: 3 additions & 0 deletions test/scripts/Xample.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ export default (robot) => {
robot.respond(/helo (.*)/gi, async res => {
await res.send(`Hello World! I'm ${robot.name}.`)
})
robot.router.get('/helo', async (req, res) => {
res.send(`HELO World! I'm ${robot.name}.`)
})
}

0 comments on commit 1ebf598

Please sign in to comment.