-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Load .mjs files as scripts (#1657)
BREAKING CHANGE: This change introduces using async/await to load files from the scripts folder.
- Loading branch information
1 parent
ac5dcd2
commit 85db19b
Showing
11 changed files
with
136 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
// Description: A test .mjs script for the robot to load | ||
// | ||
// Commands: | ||
// hubot test mjs - Responds with a test response from a .mjs script | ||
// | ||
|
||
export default robot => { | ||
robot.hasLoadedTestMjsScript = true | ||
robot.respond(/test$/, res => { | ||
res.reply('test response from .mjs script') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
// Description: A test script for the robot to load | ||
// | ||
// Commands: | ||
// hubot test - Responds with a test response | ||
// | ||
|
||
module.exports = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
// Description: A test .mjs script for the robot to load | ||
// | ||
// Commands: | ||
// hubot test mjs - Responds with a test response from a .mjs script | ||
// | ||
|
||
export default {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict' | ||
|
||
/* global describe, it, before, after */ | ||
/* eslint-disable no-unused-expressions */ | ||
|
||
const path = require('path') | ||
const chai = require('chai') | ||
chai.use(require('sinon-chai')) | ||
const expect = chai.expect | ||
const root = __dirname.replace(/test$/, '') | ||
const { TextMessage, User } = require('../index.js') | ||
|
||
describe('hubot', () => { | ||
let hubot | ||
before(() => { | ||
process.env.HUBOT_ADAPTER = path.join(__dirname, './fixtures/MockAdapter.mjs') | ||
hubot = require('../bin/hubot.js') | ||
}) | ||
after(() => { | ||
hubot.shutdown() | ||
delete process.env.HUBOT_ADAPTER | ||
}) | ||
it('should export robot instance', done => { | ||
hubot.loadFile(path.resolve(root, 'test/fixtures'), 'TestScript.mjs').then(() => { | ||
hubot.adapter.on('reply', (envelope, ...strings) => { | ||
expect(strings[0]).to.equal('test response from .mjs script') | ||
done() | ||
}) | ||
hubot.receive(new TextMessage(new User('mocha', { room: '#mocha' }), 'Hubot test')) | ||
expect(hubot.hasLoadedTestMjsScript).to.be.true | ||
expect(hubot.name).to.equal('Hubot') | ||
}).catch(done) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters