fileTransform.js 988 Bytes
Newer Older
1
// @remove-on-eject-begin
Christoph Pojer's avatar
Christoph Pojer committed
2
/**
Sophie Alpert's avatar
Sophie Alpert committed
3
 * Copyright (c) 2014-present, Facebook, Inc.
Christoph Pojer's avatar
Christoph Pojer committed
4
 *
Sophie Alpert's avatar
Sophie Alpert committed
5
6
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
Christoph Pojer's avatar
Christoph Pojer committed
7
 */
8
// @remove-on-eject-end
9
'use strict';
Christoph Pojer's avatar
Christoph Pojer committed
10

11
12
13
const path = require('path');

// This is a custom Jest transformer turning file imports into filenames.
vannio's avatar
vannio committed
14
// http://facebook.github.io/jest/docs/en/webpack.html
15
16
17

module.exports = {
  process(src, filename) {
18
19
20
21
22
23
    const assetFilename = JSON.stringify(path.basename(filename));

    if (filename.match(/\.svg$/)) {
      return `module.exports = {
        __esModule: true,
        default: ${assetFilename},
24
25
26
27
28
29
30
31
32
        ReactComponent: (props) => ({
          $$typeof: Symbol.for('react.element'),
          type: 'svg',
          ref: null,
          key: null,
          props: Object.assign({}, props, {
            children: ${assetFilename}
          })
        }),
33
34
35
36
      };`;
    }

    return `module.exports = ${assetFilename};`;
37
38
  },
};