-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add global path in require.resolve.paths #13633
Changes from 7 commits
46da204
c96b300
6dc8310
349dd7d
4ae19b9
b010ad2
1c88b5c
c026cd9
d27aa8b
4a9642c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,7 +13,7 @@ import {IModuleMap, ModuleMap} from 'jest-haste-map'; | |||||
import userResolver from '../__mocks__/userResolver'; | ||||||
import userResolverAsync from '../__mocks__/userResolverAsync'; | ||||||
import defaultResolver, {PackageFilter} from '../defaultResolver'; | ||||||
import nodeModulesPaths from '../nodeModulesPaths'; | ||||||
import nodeModulesPaths, {findGlobalPaths} from '../nodeModulesPaths'; | ||||||
import Resolver from '../resolver'; | ||||||
import type {ResolverConfig} from '../types'; | ||||||
|
||||||
|
@@ -707,3 +707,51 @@ describe('Resolver.getModulePaths() -> nodeModulesPaths()', () => { | |||||
expect(dirs_actual).toEqual(expect.arrayContaining(dirs_expected)); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe('findGlobalPaths', () => { | ||||||
const paths = findGlobalPaths(); | ||||||
expect(paths.length).toBeGreaterThanOrEqual(1); | ||||||
}); | ||||||
|
||||||
describe('Resolver.getGlobalPaths()', () => { | ||||||
const _path = path; | ||||||
let moduleMap: IModuleMap; | ||||||
beforeEach(() => { | ||||||
moduleMap = ModuleMap.create('/'); | ||||||
}); | ||||||
|
||||||
it('return global paths with npm package', () => { | ||||||
jest.doMock('path', () => _path.posix); | ||||||
const resolver = new Resolver(moduleMap, {} as ResolverConfig); | ||||||
const globalPaths = resolver.getGlobalPaths('jest'); | ||||||
expect(globalPaths.length).toBeGreaterThan(0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably we could test this more precisely with something like
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I will update it |
||||||
}); | ||||||
|
||||||
it('return empty array with builtin module', () => { | ||||||
jest.doMock('path', () => _path.posix); | ||||||
const resolver = new Resolver(moduleMap, {} as ResolverConfig); | ||||||
const globalPaths = resolver.getGlobalPaths('fs'); | ||||||
expect(globalPaths).toStrictEqual([]); | ||||||
}); | ||||||
|
||||||
it('return empty array with absolute path', () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
jest.doMock('path', () => _path.posix); | ||||||
const resolver = new Resolver(moduleMap, {} as ResolverConfig); | ||||||
const globalPaths = resolver.getGlobalPaths('/'); | ||||||
expect(globalPaths.length).toBeGreaterThan(0); | ||||||
}); | ||||||
|
||||||
it('return empty array with relative path', () => { | ||||||
jest.doMock('path', () => _path.posix); | ||||||
const resolver = new Resolver(moduleMap, {} as ResolverConfig); | ||||||
const globalPaths = resolver.getGlobalPaths('./'); | ||||||
expect(globalPaths).toStrictEqual([]); | ||||||
}); | ||||||
|
||||||
it('return empty array without module name', () => { | ||||||
jest.doMock('path', () => _path.posix); | ||||||
const resolver = new Resolver(moduleMap, {} as ResolverConfig); | ||||||
const globalPaths = resolver.getGlobalPaths(); | ||||||
expect(globalPaths).toStrictEqual([]); | ||||||
}); | ||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be removed I think, it's kind of internal and we're testing it through Resolver.getGlobalPaths