Skip to content

Commit

Permalink
Test whether require.resolve succeeds when passing options
Browse files Browse the repository at this point in the history
- This is another take on the tests on PR #54. Instead of spying on
  internals of "Module", we verify the behavior of require.resolve.
- HOWEVER, the test won't work on node [12.0-12.2], as require.resolve
  has a regression and won't use the "options" argument.
  • Loading branch information
Kehrlann committed Jul 29, 2019
1 parent e04b30b commit a94255f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: false
language: node_js
node_js:
- stable
- '12.0'
- '12.3'
- '11.0'
- '10.0'
- '9.0'
Expand Down
22 changes: 2 additions & 20 deletions test/specs.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
/* eslint-env mocha */

var BuiltinModule = require('module')

// Guard against poorly mocked module constructors
var Module = module.constructor.length > 1
? module.constructor
: BuiltinModule

var spyOn = require('./spyOn')
// This spy needs to be created before initially requiring module-alias.
var resolveSpy = spyOn(Module, '_resolveFilename')

var expect = require('chai').expect
var exec = require('child_process').exec
var path = require('path')
Expand All @@ -23,7 +11,6 @@ describe('module-alias', function () {

afterEach(function () {
moduleAlias.reset()
resolveSpy.reset()
})

it('should register path (addPath)', function () {
Expand Down Expand Up @@ -200,14 +187,9 @@ describe('module-alias', function () {
const options = {
paths: [path.join(process.cwd(), 'test', 'src', 'bar')]
}
const baz = require.resolve('./baz', options)

try {
require.resolve('./baz', options)
} catch (err) {}

const lastArgs = resolveSpy.lastArgs
expect(resolveSpy.callCount).to.be.greaterThan(0)
expect(lastArgs[lastArgs.length - 1]).to.equal(options)
expect(baz).to.have.string(path.join('bar', 'baz', 'index.js'))
})
}
})
Expand Down
31 changes: 0 additions & 31 deletions test/spyOn.js

This file was deleted.

0 comments on commit a94255f

Please sign in to comment.