Skip to content

Commit 642f8ee

Browse files
authored
fix: remove mockery due to security vulnerability alert (#79)
1 parent 0aaad28 commit 642f8ee

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

package-lock.json

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"chai": "^4.3.7",
3434
"matchdep": "^2.0.0",
3535
"mocha": "^10.2.0",
36-
"mockery": "^2.1.0",
3736
"nyc": "^15.1.0",
3837
"semantic-release": "^21.0.2",
3938
"sinon": "^15.0.4",

test/fixtures/RequireMocker.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const Module = require('module')
2+
const originalRequire = Module.prototype.require
3+
const hookModuleToReturnMockFromRequire = (module, mock) => {
4+
Module.prototype.require = function () {
5+
if (arguments[0] === module) {
6+
return mock
7+
}
8+
return originalRequire.apply(this, arguments)
9+
}
10+
}
11+
12+
const resetModuleMocks = () => {
13+
Module.prototype.require = originalRequire
14+
}
15+
16+
module.exports = {
17+
hook: hookModuleToReturnMockFromRequire,
18+
reset: resetModuleMocks
19+
}

test/help_message_visibility_test.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const path = require('path')
66

77
const chai = require('chai')
88
const expect = chai.expect
9-
const mockery = require('mockery')
9+
const { hook, reset } = require('./fixtures/RequireMocker.js')
1010

1111
chai.use(require('sinon-chai'))
1212

@@ -31,19 +31,15 @@ const newTestRobot = function newTestRobot () {
3131

3232
describe('help in private', () => describe('message visibility', () => {
3333
beforeEach(function () {
34-
mockery.enable({
35-
warnOnReplace: false,
36-
warnOnUnregistered: false
37-
})
38-
mockery.registerMock('hubot-mock-adapter', require('./fixtures/MockAdapter.js'))
34+
hook('hubot-mock-adapter', require('./fixtures/MockAdapter.js'))
3935
this.robot = newTestRobot()
4036
this.robot.run()
4137
this.user = this.robot.brain.userForName('john')
4238
})
4339

4440
afterEach(function () {
4541
this.robot.shutdown()
46-
mockery.disable()
42+
reset()
4743
})
4844

4945
context('when HUBOT_HELP_REPLY_IN_PRIVATE is unset', () => it('replies in the same room', function (done) {

test/help_test.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const path = require('path')
66

77
const chai = require('chai')
88
const expect = chai.expect
9-
const mockery = require('mockery')
9+
const { hook, reset } = require('./fixtures/RequireMocker.js')
1010

1111
chai.use(require('sinon-chai'))
1212

@@ -30,19 +30,15 @@ const newTestRobot = function newTestRobot () {
3030

3131
describe('help', () => describe('getHelpCommands', () => {
3232
beforeEach(function () {
33-
mockery.enable({
34-
warnOnReplace: false,
35-
warnOnUnregistered: false
36-
})
37-
mockery.registerMock('hubot-mock-adapter', require('./fixtures/MockAdapter.js'))
33+
hook('hubot-mock-adapter', require('./fixtures/MockAdapter.js'))
3834
this.robot = newTestRobot()
3935
this.robot.run()
4036
this.user = this.robot.brain.userForName('john')
4137
})
4238

4339
afterEach(function () {
4440
this.robot.shutdown()
45-
mockery.disable()
41+
reset()
4642
})
4743

4844
context('when HUBOT_HELP_HIDDEN_COMMANDS is not set', () => it('lists all commands', function (done) {

0 commit comments

Comments
 (0)