Updates
This commit is contained in:
21
lowcoder/client/config/test/transform/babelTransform.js
Normal file
21
lowcoder/client/config/test/transform/babelTransform.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import babelJest from "babel-jest";
|
||||
|
||||
export default babelJest.createTransformer({
|
||||
presets: [
|
||||
[
|
||||
"babel-preset-react-app",
|
||||
{
|
||||
runtime: "automatic",
|
||||
},
|
||||
],
|
||||
[
|
||||
"babel-preset-vite",
|
||||
{
|
||||
"env": true,
|
||||
"glob": false
|
||||
}
|
||||
]
|
||||
],
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
});
|
||||
16
lowcoder/client/config/test/transform/cssTransform.js
Normal file
16
lowcoder/client/config/test/transform/cssTransform.js
Normal file
@@ -0,0 +1,16 @@
|
||||
// This is a custom Jest transformer turning style imports into empty objects.
|
||||
// http://facebook.github.io/jest/docs/en/webpack.html
|
||||
|
||||
export default {
|
||||
process() {
|
||||
return {
|
||||
code: "module.exports = {};",
|
||||
};
|
||||
},
|
||||
getCacheKey() {
|
||||
// The output is always the same.
|
||||
return {
|
||||
code: "cssTransform",
|
||||
};
|
||||
},
|
||||
};
|
||||
43
lowcoder/client/config/test/transform/fileTransform.js
Normal file
43
lowcoder/client/config/test/transform/fileTransform.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import path from "node:path";
|
||||
import camelcase from "camelcase";
|
||||
|
||||
// This is a custom Jest transformer turning file imports into filenames.
|
||||
// http://facebook.github.io/jest/docs/en/webpack.html
|
||||
|
||||
export default {
|
||||
process(src, filename) {
|
||||
const assetFilename = JSON.stringify(path.basename(filename));
|
||||
|
||||
if (filename.match(/\.svg$/)) {
|
||||
// Based on how SVGR generates a component name:
|
||||
// https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6
|
||||
const pascalCaseFilename = camelcase(path.parse(filename).name, {
|
||||
pascalCase: true,
|
||||
});
|
||||
const componentName = `Svg${pascalCaseFilename}`;
|
||||
return {
|
||||
code: `
|
||||
const React = require('react');
|
||||
module.exports = {
|
||||
__esModule: true,
|
||||
default: ${assetFilename},
|
||||
ReactComponent: React.forwardRef(function ${componentName}(props, ref) {
|
||||
return {
|
||||
$$typeof: Symbol.for('react.element'),
|
||||
type: 'svg',
|
||||
ref: ref,
|
||||
key: null,
|
||||
props: Object.assign({}, props, {
|
||||
children: ${assetFilename}
|
||||
})
|
||||
};
|
||||
}),
|
||||
};`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
code: `module.exports = ${assetFilename};`,
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user