fileTransform.js 755 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. const path = require('path');
  3. // This is a custom Jest transformer turning file imports into filenames.
  4. // http://facebook.github.io/jest/docs/en/webpack.html
  5. module.exports = {
  6. process(src, filename) {
  7. const assetFilename = JSON.stringify(path.basename(filename));
  8. if (filename.match(/\.svg$/)) {
  9. return `module.exports = {
  10. __esModule: true,
  11. default: ${assetFilename},
  12. ReactComponent: (props) => ({
  13. $$typeof: Symbol.for('react.element'),
  14. type: 'svg',
  15. ref: null,
  16. key: null,
  17. props: Object.assign({}, props, {
  18. children: ${assetFilename}
  19. })
  20. }),
  21. };`;
  22. }
  23. return `module.exports = ${assetFilename};`;
  24. },
  25. };