-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Let Jest handle all file types #1197
Conversation
d34ac47
to
18427fd
Compare
'^.+\\.(?!(js|jsx|css|json)$)[^\\.]+$': resolve('config/jest/fileTransform.js'), | ||
}, | ||
transformIgnorePatterns: [ | ||
'/node_modules/.+\.(js|jsx|json)$' |
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.
I needed this because otherwise we can't import CSS from node_modules
(e.g. bootstrap/dist/bootstrap.css
). Would it make sense to change the default to that?
|
||
module.exports = { | ||
process(src, filename) { | ||
return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';'; |
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.
should this not include the extension name?
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.
I think it does!
require('path').basename('aas.asa')
'aas.asa'
nice! |
* Fix exclusion regex to also exclude files without extension * Be over-cautious with Windows paths because I'm not sure how Jest handles them
16cdfc0
to
cddbe73
Compare
Tested with: import React, { Component } from 'react';
import appCss from './App.css';
import depCss from 'postcss-discard-overridden/test/input.css';
import appSVG from './logo.svg';
import depSVG from 'postcss-load-options/logo.svg';
import appNoExt from './noext';
import depNoExt from 'abbrev/LICENSE';
import appUnknown from './lol.unknown'; // I added this
import depUnknown from 'abab/lol.unknown'; // I added this
import depJS from 'abab/lol'; // I added this, it's just module.exports = function() { return `haha` }
class App extends Component {
render() {
return (
<div className="App">
app css: {JSON.stringify(appCss)}
<br />{'\n'}
dep css: {JSON.stringify(depCss)}
<br />{'\n'}
app svg: {appSVG}
<br />{'\n'}
dep svg: {depSVG}
<br />{'\n'}
app noExt: {appNoExt}
<br />{'\n'}
dep noExt: {depNoExt}
<br />{'\n'}
app unknown: {appUnknown}
<br />{'\n'}
dep unknown: {depUnknown}
<br />{'\n'}
dep js {depJS()}{depJS.toString()}
</div>
);
}
}
export default App; (Need to add something like this to integration test, see #1187)
|
9bf7db4
to
0d79330
Compare
I already added this to the todo list of #1187 ;) |
* Let Jest handle all file types * Update regexes * Fix exclusion regex to also exclude files without extension * Be over-cautious with Windows paths because I'm not sure how Jest handles them * There is no automatic babel-jest discovery now that we use transsform
* Let Jest handle all file types * Update regexes * Fix exclusion regex to also exclude files without extension * Be over-cautious with Windows paths because I'm not sure how Jest handles them * There is no automatic babel-jest discovery now that we use transsform
In 0.8.x, we switched to treat all non-JS/CSS extensions as files by default (#1059, #1077).
However when we tried to do the same in Jest, we made a mistake which introduced false positives (#1145, #1147).
We temporarily reverted this change in #1149 and reopened #667 (comment). @cpojer suggested to use
transform
instead ofmoduleNameMapper
so that we can match against the full paths.This PR implements that. I verified that the following cases work:
node_modules
(gives you `{})node_modules
(gives you the filename)../something
orlodash.assign
(covers Upgrading to 0.8.0 will break imports from outside of the test's directory #1145, FileStub.js used for lodash modules :-( #1147).Fixes #667.