-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This was added in v8.9.0: https://nodejs.org/api/modules.html#modules_require_resolve_paths_request
- Loading branch information
Showing
3 changed files
with
93 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
console.log( | ||
'%j', | ||
{ | ||
hasRequireResolve: typeof require.resolve.paths === 'function', | ||
value: typeof require.resolve.paths === 'function' | ||
? require.resolve.paths(process.argv[2]) | ||
: undefined | ||
} | ||
); |
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,68 @@ | ||
'use strict'; | ||
|
||
const child_process = require('child_process'); | ||
const tap = require('tap'); | ||
const semver = require('semver'); | ||
|
||
tap.beforeEach(cb => { | ||
delete process.env.DISABLE_V8_COMPILE_CACHE; | ||
cb(); | ||
}); | ||
|
||
tap.test('require.resolve.paths module', t => { | ||
const psWithoutCache = child_process.spawnSync( | ||
process.execPath, | ||
[require.resolve('./fixtures/require-resolve-paths'), 'tap'], | ||
{cwd: __dirname} | ||
); | ||
|
||
const psWithCache = child_process.spawnSync( | ||
process.execPath, | ||
[ | ||
'--require', | ||
'..', | ||
require.resolve('./fixtures/require-resolve-paths'), | ||
'tap', | ||
], | ||
{cwd: __dirname} | ||
); | ||
|
||
const actual = JSON.parse(psWithCache.stdout); | ||
const expected = JSON.parse(psWithoutCache.stdout); | ||
|
||
t.same(actual, expected); | ||
t.equal(psWithCache.stderr.toString(), ''); | ||
t.equal(psWithCache.status, 0); | ||
|
||
t.equal( | ||
actual.hasRequireResolve, | ||
semver.satisfies(process.versions.node, '>=8.9.0') | ||
); | ||
|
||
t.end(); | ||
}); | ||
|
||
tap.test('require.resolve.paths relative', t => { | ||
const psWithoutCache = child_process.spawnSync( | ||
process.execPath, | ||
[require.resolve('./fixtures/require-resolve-paths'), './foo'], | ||
{cwd: __dirname} | ||
); | ||
|
||
const psWithCache = child_process.spawnSync( | ||
process.execPath, | ||
[ | ||
'--require', | ||
'..', | ||
require.resolve('./fixtures/require-resolve-paths'), | ||
'./foo', | ||
], | ||
{cwd: __dirname} | ||
); | ||
|
||
t.same(JSON.parse(psWithCache.stdout), JSON.parse(psWithoutCache.stdout)); | ||
t.equal(psWithCache.stderr.toString(), ''); | ||
t.equal(psWithCache.status, 0); | ||
|
||
t.end(); | ||
}); |
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