Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
To enable jest snapshots to imitate CSS module classnames
'use strict';
// This is a custom Jest transformer turning style imports into empty objects.
// http://facebook.github.io/jest/docs/tutorial-webpack.html
const path = require('path');
module.exports = {
process(src, filename, config, options) {
return `
/* eslint-disable no-var, comma-dangle */
var Reflect; // eslint-disable-line no-unused-vars
var idObj;
function checkIsNodeV6OrAbove() {
if (typeof process === 'undefined') {
return false;
}
return parseInt(process.versions.node.split('.')[0], 10) >= 6;
}
if (!checkIsNodeV6OrAbove()) {
Reflect = require('harmony-reflect'); // eslint-disable-line global-require
}
idObj = new Proxy({}, {
get: function getter(target, key) {
if (key === '__esModule') {
return false;
}
return 'bw__${path.basename(filename).split('.')[0]}__' + key;
}
});
module.exports = idObj;
`
},
getCacheKey() {
// The output is always the same.
return 'cssTransform';
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.