2017-01-03 13:16:48 -08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2018-01-25 04:55:52 +08:00
|
|
|
const common = require('../common');
|
2017-10-06 11:11:04 -07:00
|
|
|
const fixtures = require('../common/fixtures');
|
2016-12-05 00:03:15 -05:00
|
|
|
const assert = require('assert');
|
2010-10-18 18:17:33 -07:00
|
|
|
|
2016-12-05 00:03:15 -05:00
|
|
|
assert.strictEqual(
|
2017-10-06 11:11:04 -07:00
|
|
|
fixtures.path('a.js').toLowerCase(),
|
2017-10-13 22:13:14 +02:00
|
|
|
require.resolve(fixtures.path('a')).toLowerCase());
|
2016-12-05 00:03:15 -05:00
|
|
|
assert.strictEqual(
|
2017-10-06 11:11:04 -07:00
|
|
|
fixtures.path('a.js').toLowerCase(),
|
|
|
|
require.resolve(fixtures.path('a')).toLowerCase());
|
2016-12-05 00:03:15 -05:00
|
|
|
assert.strictEqual(
|
2017-10-06 11:11:04 -07:00
|
|
|
fixtures.path('nested-index', 'one', 'index.js').toLowerCase(),
|
2017-10-25 12:36:24 +02:00
|
|
|
require.resolve(fixtures.path('nested-index', 'one')).toLowerCase());
|
2016-12-05 00:03:15 -05:00
|
|
|
assert.strictEqual('path', require.resolve('path'));
|
2010-10-18 18:17:33 -07:00
|
|
|
|
2016-04-25 12:19:28 -04:00
|
|
|
// Test configurable resolve() paths.
|
|
|
|
require(fixtures.path('require-resolve.js'));
|
2017-11-18 01:39:02 -05:00
|
|
|
require(fixtures.path('resolve-paths', 'default', 'verify-paths.js'));
|
2018-01-25 04:55:52 +08:00
|
|
|
|
|
|
|
const re = /^The "request" argument must be of type string\. Received type \w+$/;
|
|
|
|
[1, false, null, undefined, {}].forEach((value) => {
|
|
|
|
common.expectsError(
|
|
|
|
() => { require.resolve(value); },
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
message: re
|
|
|
|
});
|
2018-01-25 04:56:15 +08:00
|
|
|
|
|
|
|
common.expectsError(
|
|
|
|
() => { require.resolve.paths(value); },
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
message: re
|
|
|
|
});
|
2018-01-25 04:55:52 +08:00
|
|
|
});
|