forked from storybookjs/storybook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinjectFileName.js
More file actions
23 lines (20 loc) · 741 Bytes
/
injectFileName.js
File metadata and controls
23 lines (20 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const { ScriptTransformer } = require('@jest/transform');
const getNextTransformer = (fileName, config) => {
const self = config.transform.find(([pattern]) => new RegExp(pattern).test(fileName));
return new ScriptTransformer({
...config,
transform: config.transform.filter((entry) => entry !== self),
});
};
module.exports = {
process(src, fileName, config, { instrument }) {
const transformer = getNextTransformer(fileName, config);
const { code } = transformer.transformSource(fileName, src, instrument);
return `${code};
if(exports.default != null) {
exports.default.parameters = exports.default.parameters || {};
exports.default.parameters.fileName = '${fileName.replace(/\\/g, '\\\\')}';
}
`;
},
};