* feat(testing): support jest 28 WIP jest migration * fix(testing): jest-environment-jsdom must be explicitly added now * fix(testing): add rxjs to the transform lsit * fix(testing): jest ts-jest updates and resolver issues * feat(testing): remove test runner for react native jest * feat(testing): add preprocessor for react native jest * fix(testing): update query to handle tsx file syntax, remove rxjs transform * chore(repo): remove file from accident commit * chore(testing): update migration to target 14.6 for RN jest preprocessor * fix(testing): call passed in packageFilter if preset * docs(testing): add resolver env var to troubleshooting guide * chore(repo): prep resolver for jest 28 migration * fix(testing): update deps to handle esbuild-wasm service error * fix(testing): switch to testEnvironmentOptions for cjs loading vs resolver list * fix(testing): force babel-jest preset in transformer for project transforms * chore(testing): address PR feedback * fix(testing): address pr feedback, remove react-native transform * chore(testing): update createTreeWithEmptyWorkspace calls * chore(testing): address pr feedback * feat(testing): add migration script for react native to rename .babelrc to babel.config.json * chore(testing): nx format after rebase * chore(testing): fix display name for @nrwl/js Co-authored-by: Emily Xiong <xiongemi@gmail.com>
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import * as path from 'path';
|
|
import { names } from '@nrwl/devkit';
|
|
|
|
const JS_SOURCE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'];
|
|
|
|
module.exports = {
|
|
process(src, filename, options): { code: string } {
|
|
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 = names(path.parse(filename).name).className;
|
|
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}
|
|
})
|
|
};
|
|
}),
|
|
};`,
|
|
};
|
|
}
|
|
|
|
if (JS_SOURCE_EXTENSIONS.includes(path.extname(filename))) {
|
|
const transformer = getJsTransform();
|
|
if (transformer) return transformer.process(src, filename, options);
|
|
}
|
|
|
|
// Fallback for unknown extensions
|
|
return {
|
|
code: `module.exports = ${assetFilename};`,
|
|
};
|
|
},
|
|
};
|
|
|
|
function getJsTransform() {
|
|
try {
|
|
return require('babel-jest').default;
|
|
} catch {
|
|
// ignored
|
|
}
|
|
|
|
try {
|
|
return require('@swc/jest').createTransformer();
|
|
} catch {
|
|
// ignored
|
|
}
|
|
}
|