Skip to content

Commit ffa03d3

Browse files
authored
Merge pull request #57 from ilearnio/bugfix/module-alias-reset-node-11-12
Fix unit tests on node >= 11 - Also, explicitly test against node 8 through 12 + node stable in Travis CI.
2 parents 6d26835 + 4150cba commit ffa03d3

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@ sudo: false
22
language: node_js
33
node_js:
44
- stable
5+
- '12.0'
6+
- '11.0'
7+
- '10.0'
8+
- '9.0'
9+
- '8.0'
510
- '5.0'
611
- '0.10'

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ function reset () {
116116
// Reset all changes in paths caused by addPath function
117117
modulePaths.forEach(function (path) {
118118
removePathHelper(path, require.main.paths)
119+
120+
// Delete from require.cache if the module has been required before.
121+
// This is required for node >= 11
122+
Object.getOwnPropertyNames(require.cache).forEach(function (name) {
123+
if (name.indexOf(path) !== -1) {
124+
delete require.cache[name]
125+
}
126+
})
127+
119128
var parent = module.parent
120129
while (parent && parent !== require.main) {
121130
removePathHelper(path, parent.paths)

test/specs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('module-alias', function () {
107107
expectAliasesToBeImported()
108108
})
109109

110-
describe('with process.cwd()', function () {
110+
describe('when base working directory is process.cwd()', function () {
111111
var baseWorkingDirectory
112112
beforeEach(function () {
113113
baseWorkingDirectory = process.cwd()
@@ -125,7 +125,7 @@ describe('module-alias', function () {
125125
})
126126
})
127127

128-
describe('by looking up __dirname/../../', function () {
128+
describe('when module-alias package is nested (looking up __dirname/../../)', function () {
129129
var moduleAliasDir = path.resolve(
130130
'.',
131131
'test',

0 commit comments

Comments
 (0)