-
Notifications
You must be signed in to change notification settings - Fork 634
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with assets living outside of the project root
Summary: When we removed the magic logic to find assets across `watchFolders` in a711d73 (which was unsound), an issue was introduced that caused assets outside of the projectRoot to not be found by the development server. This diff adds a temporary fix to the issue, the final solution will be done once we force all `watchFolders` to be relative to the `projectRoot`. This fixes #322 Reviewed By: mjesun Differential Revision: D13277398 fbshipit-source-id: 27a1adf2bd2191a7506b97691773796ba00d48f2
- Loading branch information
1 parent
3714f85
commit 0eaa741
Showing
4 changed files
with
72 additions
and
17 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
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 |
---|---|---|
|
@@ -37,8 +37,8 @@ describe('getAsset', () => { | |
writeImages({'b.png': 'b image', '[email protected]': 'b2 image'}); | ||
|
||
return Promise.all([ | ||
getAssetStr('imgs/b.png', '/root'), | ||
getAssetStr('imgs/[email protected]', '/root'), | ||
getAssetStr('imgs/b.png', '/root', []), | ||
getAssetStr('imgs/[email protected]', '/root', []), | ||
]).then(resp => resp.forEach(data => expect(data).toBe('b image'))); | ||
}); | ||
|
||
|
@@ -52,11 +52,11 @@ describe('getAsset', () => { | |
|
||
expect( | ||
await Promise.all([ | ||
getAssetStr('imgs/b.png', '/root', 'ios'), | ||
getAssetStr('imgs/b.png', '/root', 'android'), | ||
getAssetStr('imgs/c.png', '/root', 'android'), | ||
getAssetStr('imgs/c.png', '/root', 'ios'), | ||
getAssetStr('imgs/c.png', '/root'), | ||
getAssetStr('imgs/b.png', '/root', [], 'ios'), | ||
getAssetStr('imgs/b.png', '/root', [], 'android'), | ||
getAssetStr('imgs/c.png', '/root', [], 'android'), | ||
getAssetStr('imgs/c.png', '/root', [], 'ios'), | ||
getAssetStr('imgs/c.png', '/root', []), | ||
]), | ||
).toEqual([ | ||
'b ios image', | ||
|
@@ -74,8 +74,8 @@ describe('getAsset', () => { | |
}); | ||
|
||
return Promise.all([ | ||
getAssetStr('imgs/b.jpg', '/root'), | ||
getAssetStr('imgs/b.png', '/root'), | ||
getAssetStr('imgs/b.jpg', '/root', []), | ||
getAssetStr('imgs/b.png', '/root', []), | ||
]).then(data => expect(data).toEqual(['jpeg image', 'png image'])); | ||
}); | ||
|
||
|
@@ -87,7 +87,7 @@ describe('getAsset', () => { | |
'[email protected]': 'b4.5 image', | ||
}); | ||
|
||
expect(await getAssetStr('imgs/[email protected]', '/root')).toBe('b4 image'); | ||
expect(await getAssetStr('imgs/[email protected]', '/root', [])).toBe('b4 image'); | ||
}); | ||
|
||
it('should pick the bigger one with platform ext', async () => { | ||
|
@@ -104,11 +104,35 @@ describe('getAsset', () => { | |
|
||
expect( | ||
await Promise.all([ | ||
getAssetStr('imgs/[email protected]', '/root'), | ||
getAssetStr('imgs/[email protected]', '/root', 'ios'), | ||
getAssetStr('imgs/[email protected]', '/root', []), | ||
getAssetStr('imgs/[email protected]', '/root', [], 'ios'), | ||
]), | ||
).toEqual(['b4 image', 'b4 ios image']); | ||
}); | ||
|
||
it('should find an image located on a watchFolder', async () => { | ||
mkdirp.sync('/anotherfolder'); | ||
|
||
writeImages({ | ||
'../../anotherfolder/b.png': 'b image', | ||
}); | ||
|
||
expect( | ||
await getAssetStr('../anotherfolder/b.png', '/root', ['/anotherfolder']), | ||
).toBe('b image'); | ||
}); | ||
|
||
it('should throw an error if an image is not located on any watchFolder', async () => { | ||
mkdirp.sync('/anotherfolder'); | ||
|
||
writeImages({ | ||
'../../anotherfolder/b.png': 'b image', | ||
}); | ||
|
||
await expect( | ||
getAssetStr('../anotherfolder/b.png', '/root', []), | ||
).rejects.toBeInstanceOf(Error); | ||
}); | ||
}); | ||
|
||
describe('getAssetData', () => { | ||
|