Skip to content

Instantly share code, notes, and snippets.

@dcherman
Created April 18, 2018 15:16
Show Gist options
  • Save dcherman/227caa43e27f21c784e6262091139f49 to your computer and use it in GitHub Desktop.
Save dcherman/227caa43e27f21c784e6262091139f49 to your computer and use it in GitHub Desktop.
const defaultResolver = require('jest-resolve/build/default_resolver').default;
const ScriptTransformer = require('jest-runtime').ScriptTransformer;
const fs = require('fs');
const transform = ScriptTransformer.prototype.transform;
Object.defineProperty(ScriptTransformer.prototype, 'transform', {
enumerable: false,
value(file, ...args) {
if (!fs.existsSync(file)) {
for (const ext of this._config.moduleFileExtensions) {
const maybe = `${file}.${ext}`;
if (fs.existsSync(maybe)) {
file = maybe;
break;
}
}
}
return transform.call(this, file, ...args);
}
});
module.exports = (...args) => {
return defaultResolver(...args);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment