-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Encapsulate Haste map initialisation in MutableHasteMap
Summary: A bit of internal rearranging to move some Haste-specific logic out of the `FileMap` core class and encapsulate it within the `MutableHasteMap` implementation of `HasteMap`. This provides a template for other plugins and sets up some further changes. Changelog: Internal Reviewed By: huntie Differential Revision: D67763377 fbshipit-source-id: e7f0e422622ded5ee93d9e613b7d6b2d36e595ab
- Loading branch information
1 parent
f9d330b
commit b7b3cf4
Showing
4 changed files
with
128 additions
and
29 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
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
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
64 changes: 64 additions & 0 deletions
64
packages/metro-file-map/src/lib/__tests__/MutableHasteMap-test.js
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,64 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import type {FileMetaData} from '../../flow-types'; | ||
import type HasteMapType from '../MutableHasteMap'; | ||
|
||
let mockPathModule; | ||
jest.mock('path', () => mockPathModule); | ||
|
||
describe.each([['win32'], ['posix']])('MockMap on %s', platform => { | ||
const p: string => string = filePath => | ||
platform === 'win32' | ||
? filePath.replace(/\//g, '\\').replace(/^\\/, 'C:\\') | ||
: filePath; | ||
|
||
let HasteMap: Class<HasteMapType>; | ||
|
||
const opts = { | ||
enableHastePackages: false, | ||
failValidationOnConflicts: false, | ||
perfLogger: null, | ||
platforms: new Set(['ios', 'android']), | ||
rootDir: p('/root'), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
mockPathModule = jest.requireActual<{}>('path')[platform]; | ||
HasteMap = require('../MutableHasteMap').default; | ||
jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('initialize', async () => { | ||
const hasteMap = new HasteMap(opts); | ||
const initialState = { | ||
metadataIterator: jest.fn().mockReturnValue([ | ||
{ | ||
canonicalPath: p('project/Foo.js'), | ||
baseName: 'Foo.js', | ||
metadata: hasteMetadata('NameForFoo'), | ||
}, | ||
]), | ||
}; | ||
await hasteMap.initialize(initialState); | ||
expect(initialState.metadataIterator).toHaveBeenCalledWith({ | ||
includeNodeModules: false, | ||
includeSymlinks: false, | ||
}); | ||
expect(hasteMap.getModule('NameForFoo')).toEqual(p('/root/project/Foo.js')); | ||
}); | ||
}); | ||
|
||
function hasteMetadata(hasteName: string): FileMetaData { | ||
return [hasteName, 0, 0, 0, '', '', 0]; | ||
} |