assetFileTransformer.js 859 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. */
  9. 'use strict';
  10. /* eslint-env node */
  11. const path = require('path');
  12. const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');
  13. module.exports = {
  14. // Mocks asset requires to return the filename. Makes it possible to test that
  15. // the correct images are loaded for components. Essentially
  16. // require('img1.png') becomes `Object { "testUri": 'path/to/img1.png' }` in
  17. // the Jest snapshot.
  18. process: (_, filename) =>
  19. `module.exports = {
  20. testUri:
  21. ${JSON.stringify(
  22. path.relative(__dirname, filename).replace(/\\/g, '/'),
  23. )}
  24. };`,
  25. getCacheKey: createCacheKeyFunction([__filename]),
  26. };