-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Asset basenames in Jest snapshots #13319
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9f102e4
Asset basenames in Jest snapshots
myrjola bee962c
Return assets conforming to ImageURISourcePropType and use relative path
myrjola 05f41f2
Rephrase basename to relative path according to new semantics
myrjola f2ee740
Rename uri to testUri
myrjola 78e9906
Change empty PNG files to real PNGs
myrjola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Libraries/Image/__tests__/__snapshots__/assetRelativePathInSnapshot.js.snap
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,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders assets based on relative path 1`] = ` | ||
<View> | ||
<Image | ||
source={ | ||
Object { | ||
"testUri": "Libraries/Image/__tests__/img/img1.png", | ||
} | ||
} | ||
/> | ||
<Image | ||
source={ | ||
Object { | ||
"testUri": "Libraries/Image/__tests__/img/img2.png", | ||
} | ||
} | ||
/> | ||
</View> | ||
`; |
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,25 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
jest.disableAutomock(); | ||
|
||
const React = require('React'); | ||
const ReactTestRenderer = require('react-test-renderer'); | ||
const Image = require('Image'); | ||
const View = require('View'); | ||
|
||
it('renders assets based on relative path', () => { | ||
expect(ReactTestRenderer.create( | ||
<View> | ||
<Image source={require('./img/img1.png')} /> | ||
<Image source={require('./img/img2.png')} /> | ||
</View> | ||
)).toMatchSnapshot(); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
/* eslint-env node */ | ||
|
||
const path = require('path'); | ||
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction'); | ||
|
||
module.exports = { | ||
// Mocks asset requires to return the filename. Makes it possible to test that | ||
// the correct images are loaded for components. Essentially | ||
// require('img1.png') becomes `Object { "testUri": 'path/to/img1.png' }` in | ||
// the Jest snapshot. | ||
process: (_, filename) => | ||
`module.exports = { | ||
testUri: ${JSON.stringify(path.relative('.', filename))} | ||
};`, | ||
getCacheKey: createCacheKeyFunction([__filename]), | ||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Removing this broke importing files with multiple device resolution variations. Metro bundler will resolve
require('./file.png')
to./file@2x.png
if you're on a 2x screen.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.
Thanks for reporting! Could you give a bit more detail what the problem is? Apparently this change has broken your tests. Could you give some steps to reproduce?
I immediately notice that the regex
^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|png|psd|svg|webp)$
does not match the@
character in./file@2x.png
. The regex has been moved frommoduleNameMapper
to thetransform
mapper on line 17 in the same file. Perhaps the change from./file.png
to./file@2x.png
happens between the mappers. @oblador, could you edit the regex on line 17 to^[./a-zA-Z0-9@$_-]+\\.(bmp|gif|jpg|jpeg|png|psd|svg|webp)$
, so that it also matches./file@2x.png
?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.
This also breaks tests completely on Windows for me. Please see #19370 for details