@openrewrite/recipes-react 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -1
- package/dist/migration/change-component-prop-value.d.ts.map +1 -1
- package/dist/migration/change-component-prop-value.js +14 -4
- package/dist/migration/change-component-prop-value.js.map +1 -1
- package/dist/mui/adapt-v4-theme.d.ts +8 -0
- package/dist/mui/adapt-v4-theme.d.ts.map +1 -0
- package/dist/mui/adapt-v4-theme.js +65 -0
- package/dist/mui/adapt-v4-theme.js.map +1 -0
- package/dist/mui/add-component-prop.d.ts +18 -0
- package/dist/mui/add-component-prop.d.ts.map +1 -0
- package/dist/mui/add-component-prop.js +53 -0
- package/dist/mui/add-component-prop.js.map +1 -0
- package/dist/mui/add-emotion-prepend.d.ts +8 -0
- package/dist/mui/add-emotion-prepend.d.ts.map +1 -0
- package/dist/mui/add-emotion-prepend.js +71 -0
- package/dist/mui/add-emotion-prepend.js.map +1 -0
- package/dist/mui/change-module-specifier.d.ts +14 -0
- package/dist/mui/change-module-specifier.d.ts.map +1 -0
- package/dist/mui/change-module-specifier.js +95 -0
- package/dist/mui/change-module-specifier.js.map +1 -0
- package/dist/mui/convert-mui-imports.d.ts +14 -0
- package/dist/mui/convert-mui-imports.d.ts.map +1 -0
- package/dist/mui/convert-mui-imports.js +195 -0
- package/dist/mui/convert-mui-imports.js.map +1 -0
- package/dist/mui/convert-prop-to-sx.d.ts +22 -0
- package/dist/mui/convert-prop-to-sx.d.ts.map +1 -0
- package/dist/mui/convert-prop-to-sx.js +99 -0
- package/dist/mui/convert-prop-to-sx.js.map +1 -0
- package/dist/mui/index.d.ts +32 -0
- package/dist/mui/index.d.ts.map +1 -0
- package/dist/mui/index.js +67 -0
- package/dist/mui/index.js.map +1 -0
- package/dist/mui/jsx-attributes.d.ts +27 -0
- package/dist/mui/jsx-attributes.d.ts.map +1 -0
- package/dist/mui/jsx-attributes.js +140 -0
- package/dist/mui/jsx-attributes.js.map +1 -0
- package/dist/mui/mark-manual-migration.d.ts +16 -0
- package/dist/mui/mark-manual-migration.d.ts.map +1 -0
- package/dist/mui/mark-manual-migration.js +73 -0
- package/dist/mui/mark-manual-migration.js.map +1 -0
- package/dist/mui/mark-palette-mode-usage.d.ts +12 -0
- package/dist/mui/mark-palette-mode-usage.d.ts.map +1 -0
- package/dist/mui/mark-palette-mode-usage.js +50 -0
- package/dist/mui/mark-palette-mode-usage.js.map +1 -0
- package/dist/mui/move-component-prop-to-slot.d.ts +22 -0
- package/dist/mui/move-component-prop-to-slot.d.ts.map +1 -0
- package/dist/mui/move-component-prop-to-slot.js +87 -0
- package/dist/mui/move-component-prop-to-slot.js.map +1 -0
- package/dist/mui/move-primary-text-to-children.d.ts +12 -0
- package/dist/mui/move-primary-text-to-children.d.ts.map +1 -0
- package/dist/mui/move-primary-text-to-children.js +52 -0
- package/dist/mui/move-primary-text-to-children.js.map +1 -0
- package/dist/mui/move-system-props-to-sx.d.ts +16 -0
- package/dist/mui/move-system-props-to-sx.d.ts.map +1 -0
- package/dist/mui/move-system-props-to-sx.js +122 -0
- package/dist/mui/move-system-props-to-sx.js.map +1 -0
- package/dist/mui/mui-components.d.ts +8 -0
- package/dist/mui/mui-components.d.ts.map +1 -0
- package/dist/mui/mui-components.js +41 -0
- package/dist/mui/mui-components.js.map +1 -0
- package/dist/mui/mui-tag-visitor.d.ts +5 -0
- package/dist/mui/mui-tag-visitor.d.ts.map +1 -0
- package/dist/mui/mui-tag-visitor.js +54 -0
- package/dist/mui/mui-tag-visitor.js.map +1 -0
- package/dist/mui/pre-v5-recipe.d.ts +14 -0
- package/dist/mui/pre-v5-recipe.d.ts.map +1 -0
- package/dist/mui/pre-v5-recipe.js +88 -0
- package/dist/mui/pre-v5-recipe.js.map +1 -0
- package/dist/mui/remove-component-prop.d.ts +18 -0
- package/dist/mui/remove-component-prop.d.ts.map +1 -0
- package/dist/mui/remove-component-prop.js +55 -0
- package/dist/mui/remove-component-prop.js.map +1 -0
- package/dist/mui/remove-root-ref.d.ts +8 -0
- package/dist/mui/remove-root-ref.d.ts.map +1 -0
- package/dist/mui/remove-root-ref.js +61 -0
- package/dist/mui/remove-root-ref.js.map +1 -0
- package/dist/mui/remove-spacing-px-suffix.d.ts +8 -0
- package/dist/mui/remove-spacing-px-suffix.d.ts.map +1 -0
- package/dist/mui/remove-spacing-px-suffix.js +62 -0
- package/dist/mui/remove-spacing-px-suffix.js.map +1 -0
- package/dist/mui/rename-component-prop.d.ts +20 -0
- package/dist/mui/rename-component-prop.d.ts.map +1 -0
- package/dist/mui/rename-component-prop.js +66 -0
- package/dist/mui/rename-component-prop.js.map +1 -0
- package/dist/mui/rename-joy-css-variables.d.ts +8 -0
- package/dist/mui/rename-joy-css-variables.d.ts.map +1 -0
- package/dist/mui/rename-joy-css-variables.js +51 -0
- package/dist/mui/rename-joy-css-variables.js.map +1 -0
- package/dist/mui/rename-theme-palette-type.d.ts +8 -0
- package/dist/mui/rename-theme-palette-type.d.ts.map +1 -0
- package/dist/mui/rename-theme-palette-type.js +61 -0
- package/dist/mui/rename-theme-palette-type.js.map +1 -0
- package/dist/mui/replace-box-border-radius.d.ts +10 -0
- package/dist/mui/replace-box-border-radius.d.ts.map +1 -0
- package/dist/mui/replace-box-border-radius.js +50 -0
- package/dist/mui/replace-box-border-radius.js.map +1 -0
- package/dist/mui/replace-breakpoints-width.d.ts +8 -0
- package/dist/mui/replace-breakpoints-width.d.ts.map +1 -0
- package/dist/mui/replace-breakpoints-width.js +46 -0
- package/dist/mui/replace-breakpoints-width.js.map +1 -0
- package/dist/mui/replace-component-class.d.ts +18 -0
- package/dist/mui/replace-component-class.d.ts.map +1 -0
- package/dist/mui/replace-component-class.js +126 -0
- package/dist/mui/replace-component-class.js.map +1 -0
- package/dist/mui/replace-components-with-slots.d.ts +14 -0
- package/dist/mui/replace-components-with-slots.d.ts.map +1 -0
- package/dist/mui/replace-components-with-slots.js +69 -0
- package/dist/mui/replace-components-with-slots.js.map +1 -0
- package/dist/mui/replace-import-paths.d.ts +14 -0
- package/dist/mui/replace-import-paths.d.ts.map +1 -0
- package/dist/mui/replace-import-paths.js +101 -0
- package/dist/mui/replace-import-paths.js.map +1 -0
- package/dist/mui/replace-in-string-literals.d.ts +15 -0
- package/dist/mui/replace-in-string-literals.d.ts.map +1 -0
- package/dist/mui/replace-in-string-literals.js +62 -0
- package/dist/mui/replace-in-string-literals.js.map +1 -0
- package/dist/mui/replace-list-item-button-prop.d.ts +12 -0
- package/dist/mui/replace-list-item-button-prop.d.ts.map +1 -0
- package/dist/mui/replace-list-item-button-prop.js +80 -0
- package/dist/mui/replace-list-item-button-prop.js.map +1 -0
- package/dist/mui/replace-tabs-scroll-buttons.d.ts +8 -0
- package/dist/mui/replace-tabs-scroll-buttons.d.ts.map +1 -0
- package/dist/mui/replace-tabs-scroll-buttons.js +41 -0
- package/dist/mui/replace-tabs-scroll-buttons.js.map +1 -0
- package/dist/mui/replace-theme-color-functions.d.ts +8 -0
- package/dist/mui/replace-theme-color-functions.d.ts.map +1 -0
- package/dist/mui/replace-theme-color-functions.js +72 -0
- package/dist/mui/replace-theme-color-functions.js.map +1 -0
- package/dist/mui/replace-theme-spacing-unit.d.ts +8 -0
- package/dist/mui/replace-theme-spacing-unit.d.ts.map +1 -0
- package/dist/mui/replace-theme-spacing-unit.js +77 -0
- package/dist/mui/replace-theme-spacing-unit.js.map +1 -0
- package/dist/mui/replace-typography-round.d.ts +8 -0
- package/dist/mui/replace-typography-round.d.ts.map +1 -0
- package/dist/mui/replace-typography-round.js +44 -0
- package/dist/mui/replace-typography-round.js.map +1 -0
- package/dist/mui/shift-hidden-down-props.d.ts +10 -0
- package/dist/mui/shift-hidden-down-props.d.ts.map +1 -0
- package/dist/mui/shift-hidden-down-props.js +49 -0
- package/dist/mui/shift-hidden-down-props.js.map +1 -0
- package/dist/mui/theme-access.d.ts +5 -0
- package/dist/mui/theme-access.d.ts.map +1 -0
- package/dist/mui/theme-access.js +21 -0
- package/dist/mui/theme-access.js.map +1 -0
- package/dist/mui/update-theme-breakpoints.d.ts +10 -0
- package/dist/mui/update-theme-breakpoints.d.ts.map +1 -0
- package/dist/mui/update-theme-breakpoints.js +58 -0
- package/dist/mui/update-theme-breakpoints.js.map +1 -0
- package/dist/mui/upgrade-grid-props.d.ts +16 -0
- package/dist/mui/upgrade-grid-props.d.ts.map +1 -0
- package/dist/mui/upgrade-grid-props.js +90 -0
- package/dist/mui/upgrade-grid-props.js.map +1 -0
- package/dist/react19/use-context-hook.d.ts.map +1 -1
- package/dist/react19/use-context-hook.js +2 -0
- package/dist/react19/use-context-hook.js.map +1 -1
- package/dist/search/find-enzyme-usage.d.ts +4 -0
- package/dist/search/find-enzyme-usage.d.ts.map +1 -1
- package/dist/search/find-enzyme-usage.js +91 -7
- package/dist/search/find-enzyme-usage.js.map +1 -1
- package/dist/testing/enzyme-host-components.d.ts +12 -0
- package/dist/testing/enzyme-host-components.d.ts.map +1 -1
- package/dist/testing/enzyme-host-components.js +100 -0
- package/dist/testing/enzyme-host-components.js.map +1 -1
- package/dist/testing/enzyme-render-blockers.d.ts +13 -4
- package/dist/testing/enzyme-render-blockers.d.ts.map +1 -1
- package/dist/testing/enzyme-render-blockers.js +162 -6
- package/dist/testing/enzyme-render-blockers.js.map +1 -1
- package/dist/testing/enzyme-to-react-testing-library.d.ts +9 -2
- package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
- package/dist/testing/enzyme-to-react-testing-library.js +163 -16
- package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
- package/dist/testing/enzyme-usage.d.ts +7 -0
- package/dist/testing/enzyme-usage.d.ts.map +1 -1
- package/dist/testing/enzyme-usage.js +8 -1
- package/dist/testing/enzyme-usage.js.map +1 -1
- package/dist/testing/enzyme-wrapper-scope.d.ts +8 -5
- package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
- package/dist/testing/enzyme-wrapper-scope.js +16 -4
- package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
- package/dist/zustand/redux-stores.d.ts +2 -0
- package/dist/zustand/redux-stores.d.ts.map +1 -1
- package/dist/zustand/redux-stores.js +120 -6
- package/dist/zustand/redux-stores.js.map +1 -1
- package/dist/zustand/redux-to-zustand.d.ts.map +1 -1
- package/dist/zustand/redux-to-zustand.js +10 -4
- package/dist/zustand/redux-to-zustand.js.map +1 -1
- package/dist/zustand/zustand-plan.d.ts +7 -0
- package/dist/zustand/zustand-plan.d.ts.map +1 -1
- package/dist/zustand/zustand-plan.js +141 -21
- package/dist/zustand/zustand-plan.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +10 -0
- package/src/migration/change-component-prop-value.ts +19 -8
- package/src/mui/adapt-v4-theme.ts +43 -0
- package/src/mui/add-component-prop.ts +43 -0
- package/src/mui/add-emotion-prepend.ts +48 -0
- package/src/mui/change-module-specifier.ts +71 -0
- package/src/mui/convert-mui-imports.ts +184 -0
- package/src/mui/convert-prop-to-sx.ts +89 -0
- package/src/mui/index.ts +31 -0
- package/src/mui/jsx-attributes.ts +133 -0
- package/src/mui/mark-manual-migration.ts +53 -0
- package/src/mui/mark-palette-mode-usage.ts +36 -0
- package/src/mui/move-component-prop-to-slot.ts +84 -0
- package/src/mui/move-primary-text-to-children.ts +41 -0
- package/src/mui/move-system-props-to-sx.ts +118 -0
- package/src/mui/mui-components.ts +40 -0
- package/src/mui/mui-tag-visitor.ts +36 -0
- package/src/mui/pre-v5-recipe.ts +82 -0
- package/src/mui/remove-component-prop.ts +43 -0
- package/src/mui/remove-root-ref.ts +41 -0
- package/src/mui/remove-spacing-px-suffix.ts +43 -0
- package/src/mui/rename-component-prop.ts +55 -0
- package/src/mui/rename-joy-css-variables.ts +41 -0
- package/src/mui/rename-theme-palette-type.ts +42 -0
- package/src/mui/replace-box-border-radius.ts +42 -0
- package/src/mui/replace-breakpoints-width.ts +28 -0
- package/src/mui/replace-component-class.ts +97 -0
- package/src/mui/replace-components-with-slots.ts +61 -0
- package/src/mui/replace-import-paths.ts +100 -0
- package/src/mui/replace-in-string-literals.ts +44 -0
- package/src/mui/replace-list-item-button-prop.ts +59 -0
- package/src/mui/replace-tabs-scroll-buttons.ts +31 -0
- package/src/mui/replace-theme-color-functions.ts +55 -0
- package/src/mui/replace-theme-spacing-unit.ts +59 -0
- package/src/mui/replace-typography-round.ts +29 -0
- package/src/mui/shift-hidden-down-props.ts +44 -0
- package/src/mui/theme-access.ts +18 -0
- package/src/mui/update-theme-breakpoints.ts +47 -0
- package/src/mui/upgrade-grid-props.ts +82 -0
- package/src/react19/use-context-hook.ts +2 -0
- package/src/search/find-enzyme-usage.ts +80 -7
- package/src/testing/enzyme-host-components.ts +110 -0
- package/src/testing/enzyme-render-blockers.ts +174 -9
- package/src/testing/enzyme-to-react-testing-library.ts +159 -25
- package/src/testing/enzyme-usage.ts +13 -0
- package/src/testing/enzyme-wrapper-scope.ts +27 -6
- package/src/zustand/redux-stores.ts +119 -5
- package/src/zustand/redux-to-zustand.ts +12 -5
- package/src/zustand/zustand-plan.ts +159 -18
|
@@ -25,6 +25,7 @@ exports.parsesOptionalChaining = parsesOptionalChaining;
|
|
|
25
25
|
exports.reactMajor = reactMajor;
|
|
26
26
|
exports.incompatibility = incompatibility;
|
|
27
27
|
exports.simulatesEvents = simulatesEvents;
|
|
28
|
+
exports.rtlTarget = rtlTarget;
|
|
28
29
|
const rewrite_1 = require("@openrewrite/rewrite");
|
|
29
30
|
const text_1 = require("@openrewrite/rewrite/text");
|
|
30
31
|
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
@@ -79,12 +80,14 @@ class EnzymeTestDependency extends java_recipe_proxy_1.JavaDependencyRecipe {
|
|
|
79
80
|
this.forecast = forecast;
|
|
80
81
|
this.landed = new Set();
|
|
81
82
|
this.declined = new Set();
|
|
83
|
+
this.outcomes = new Map();
|
|
82
84
|
this.manifests = [];
|
|
83
85
|
this.held = [];
|
|
84
86
|
}
|
|
85
87
|
initialValue() {
|
|
86
88
|
this.landed.clear();
|
|
87
89
|
this.declined.clear();
|
|
90
|
+
this.outcomes.clear();
|
|
88
91
|
this.manifests.length = 0;
|
|
89
92
|
this.held.length = 0;
|
|
90
93
|
return super.initialValue();
|
|
@@ -113,11 +116,19 @@ class EnzymeTestDependency extends java_recipe_proxy_1.JavaDependencyRecipe {
|
|
|
113
116
|
var _a, _b;
|
|
114
117
|
const converting = yield ((_b = (_a = this.forecast).converting) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
115
118
|
const scopes = lockfileScopes(this.held);
|
|
116
|
-
const
|
|
119
|
+
const withheld = (manifest) => {
|
|
117
120
|
var _a;
|
|
118
121
|
const scope = (_a = scopes.get(manifest.sourcePath)) !== null && _a !== void 0 ? _a : packageRoot(manifest.sourcePath);
|
|
119
|
-
|
|
120
|
-
|
|
122
|
+
if (converting && ![...converting].some(source => source.startsWith(scope)))
|
|
123
|
+
return { kind: "withheld" };
|
|
124
|
+
return this.withholds(scope) ? { kind: "peer" } : undefined;
|
|
125
|
+
};
|
|
126
|
+
const forwarded = new Set(this.held.filter(manifest => !withheld(manifest)));
|
|
127
|
+
for (const manifest of this.manifests) {
|
|
128
|
+
const why = forwarded.has(manifest) ? undefined : withheld(manifest);
|
|
129
|
+
if (why)
|
|
130
|
+
this.outcomes.set(packageRoot(manifest.sourcePath), why);
|
|
131
|
+
}
|
|
121
132
|
const scanner = yield this.java.scanner(acc);
|
|
122
133
|
for (const manifest of forwarded)
|
|
123
134
|
yield scanner.visit(manifest, ctx);
|
|
@@ -131,8 +142,13 @@ class EnzymeTestDependency extends java_recipe_proxy_1.JavaDependencyRecipe {
|
|
|
131
142
|
const root = manifest.sourcePath.slice(0, -"package.json".length);
|
|
132
143
|
if (edited && edited !== manifest && declares(edited, this.addition.packageName))
|
|
133
144
|
this.landed.add(root);
|
|
134
|
-
else if (!declares(manifest, this.addition.packageName) && this.resolvesGate(manifest))
|
|
145
|
+
else if (!declares(manifest, this.addition.packageName) && this.resolvesGate(manifest)) {
|
|
135
146
|
this.declined.add(root);
|
|
147
|
+
const warning = (edited !== null && edited !== void 0 ? edited : manifest).markers.markers.find(marker => marker.kind === rewrite_1.MarkersKind.MarkupWarn);
|
|
148
|
+
this.outcomes.set(root, { kind: "declined", warning: warning && [warning.message, warning.detail].filter(Boolean).join("\n") });
|
|
149
|
+
}
|
|
150
|
+
else if (!declares(manifest, this.addition.packageName))
|
|
151
|
+
this.outcomes.set(root, { kind: "gate" });
|
|
136
152
|
}
|
|
137
153
|
return generated;
|
|
138
154
|
});
|
|
@@ -290,6 +306,10 @@ function simulatesEvents(packages, sourcePath, landed = new Set()) {
|
|
|
290
306
|
return { events: new Set([...enzyme_wrapper_scope_1.SIMULATED_EVENTS].filter(event => !HOVER_EVENTS.has(event))), attached: true };
|
|
291
307
|
return { events: new Set(), attached: false };
|
|
292
308
|
}
|
|
309
|
+
function rtlTarget(packages, sourcePath) {
|
|
310
|
+
const { enzymeRoot, enzymeReact } = compatibility(packages, sourcePath, new Set());
|
|
311
|
+
return enzymeRoot === undefined ? undefined : { root: enzymeRoot, react18: enzymeReact === 18 };
|
|
312
|
+
}
|
|
293
313
|
function compatibility(packages, sourcePath, landed) {
|
|
294
314
|
var _a;
|
|
295
315
|
const roots = [...packages.keys()].filter(root => sourcePath.startsWith(root)).sort((a, b) => b.length - a.length);
|
|
@@ -308,11 +328,12 @@ function compatibility(packages, sourcePath, landed) {
|
|
|
308
328
|
const rtlMajor = added ? (enzymeReact.major >= 18 ? 16 : 12) : typeof rtl === "object" && rtl.major >= 10 && rtl.major <= 16 ? rtl.major : 0;
|
|
309
329
|
const compatible = supportedReact(react) && supportedReact(reactDom) && react.major === reactDom.major &&
|
|
310
330
|
rtlMajor > 0 && rtlSupports(rtlMajor, react.major);
|
|
331
|
+
const target = { enzymeRoot: enzymeRoots[0], enzymeReact: supportedReact(enzymeReact) ? enzymeReact.major : undefined };
|
|
311
332
|
if (compatible)
|
|
312
|
-
return { react: react.major, rtl: rtlMajor };
|
|
333
|
+
return Object.assign({ react: react.major, rtl: rtlMajor }, target);
|
|
313
334
|
const why = !supportedReact(react) || !supportedReact(reactDom) || react.major !== reactDom.major ? "react" :
|
|
314
335
|
rtl === undefined && !added ? "rtlMissing" : "rtl";
|
|
315
|
-
return { react: 0, rtl: rtlMajor, why };
|
|
336
|
+
return Object.assign({ react: 0, rtl: rtlMajor, why }, target);
|
|
316
337
|
}
|
|
317
338
|
function providerRoots(packages, roots) {
|
|
318
339
|
var _a;
|
|
@@ -369,16 +390,18 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
369
390
|
super(options);
|
|
370
391
|
this.name = "org.openrewrite.react.migrate.enzyme-to-react-testing-library";
|
|
371
392
|
this.displayName = "Migrate Enzyme to React Testing Library";
|
|
372
|
-
this.description = "Migrates Enzyme `mount` wrappers whose every use is a supported DOM read or event (`find(selector).length`, `.exists()`, `.text()`, `.html()`, `.hasClass()`, positions through `.at(n)`, `.first()`, `.last()`, the wrapper's `text()` and `exists(selector)`, found nodes as a `toHaveLength` subject, `setProps` as a rerender of the cloned element, and `simulate` with common mouse, keyboard, focus, form, and touch events, including `nativeEvent` mocks, on React 17 and 18 and, without the hover events and in a render attached to the document, on React 15.5 and 16) and bare `mount` statements to React Testing Library container queries, `rerender`, and `fireEvent` in packages using React 16 or 17 with RTL 10 to 12, React 15.5+ with RTL 12, or React 18 with RTL 16, adding RTL 12, or RTL 16 with its peer `@testing-library/dom` 10, where it is missing. On React 15, whose markup differs, `html()` and DOM nodes are left for review. Converts `shallow` wrappers the same way, without `simulate` or `html()`, where the component is imported from a source in the repository that creates host elements only and runs no effects, so a full render produces the DOM the shallow render does. Selectors are limited to HTML or SVG tag, class, ID, and pass-through attribute compounds and their descendant combinations. Reports remaining Enzyme usages for manual review. Requires an existing DOM test environment;
|
|
393
|
+
this.description = "Migrates Enzyme `mount` wrappers whose every use is a supported DOM read or event (`find(selector).length`, `.exists()`, `.text()`, `.html()`, `.hasClass()`, positions through `.at(n)`, `.first()`, `.last()`, the wrapper's `text()` and `exists(selector)`, found nodes as a `toHaveLength` subject, `setProps` as a rerender of the cloned element, and `simulate` with common mouse, keyboard, focus, form, and touch events, including `nativeEvent` mocks, on React 17 and 18 and, without the hover events and in a render attached to the document, on React 15.5 and 16) and bare `mount` statements to React Testing Library container queries, `rerender`, and `fireEvent` in packages using React 16 or 17 with RTL 10 to 12, React 15.5+ with RTL 12, or React 18 with RTL 16, adding RTL 12, or RTL 16 with its peer `@testing-library/dom` 10, where it is missing. This includes a shared `let` wrapper that each test assigns first, or that the last statement of a `beforeEach` assigns, where every test of it converts. On React 15, whose markup differs, `html()` and DOM nodes are left for review. Converts `shallow` wrappers the same way, without `simulate` or `html()`, where the component is imported from a source in the repository that creates host elements only and runs no effects, so a full render produces the DOM the shallow render does. Selectors are limited to HTML or SVG tag, class, ID, and pass-through attribute compounds and their descendant combinations. Reports remaining Enzyme usages for manual review. Requires an existing DOM test environment; props, snapshots, and shallow rendering of other components are left for review.";
|
|
373
394
|
this.forecast = {};
|
|
374
395
|
this.tests = [];
|
|
396
|
+
this.forecastBlockers = new Map();
|
|
375
397
|
this.dependencySteps = ADDS_RTL ? dependencySteps(this.forecast) : undefined;
|
|
376
398
|
this.snapshots = false;
|
|
377
399
|
this.usages = new rewrite_1.DataTable(enzyme_usage_1.ENZYME_USAGE_TABLE, "Enzyme migration inventory", "Remaining Enzyme usages and migration actions. Module rows include references whose call types may be unavailable; they are not counts of test cases.", enzyme_usage_1.EnzymeUsageRow);
|
|
378
400
|
}
|
|
379
401
|
initialValue() {
|
|
380
402
|
this.tests.length = 0;
|
|
381
|
-
|
|
403
|
+
this.forecastBlockers.clear();
|
|
404
|
+
return { packages: new Map(), components: new Map(), composites: new Map(), modules: new Map(), names: new Map(), nullSnapshots: new Set() };
|
|
382
405
|
}
|
|
383
406
|
scanner(scanned) {
|
|
384
407
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -390,6 +413,9 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
390
413
|
visitJsCompilationUnit(cu) {
|
|
391
414
|
return __awaiter(this, void 0, void 0, function* () {
|
|
392
415
|
scanned.components.set(cu.sourcePath, (0, enzyme_host_components_1.hostComponentExports)(cu));
|
|
416
|
+
const composite = (0, enzyme_host_components_1.compositeFacts)(cu);
|
|
417
|
+
if (composite)
|
|
418
|
+
scanned.composites.set(cu.sourcePath, composite);
|
|
393
419
|
scanned.modules.set(cu.sourcePath, (0, enzyme_portals_1.moduleFacts)(cu));
|
|
394
420
|
scanned.names.set(cu.sourcePath, (0, enzyme_selector_names_1.selectorNames)(cu));
|
|
395
421
|
if ((0, module_imports_1.importBindings)(cu).some(({ module }) => module === enzyme_usage_1.ENZYME))
|
|
@@ -523,6 +549,19 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
523
549
|
};
|
|
524
550
|
const usages = this.usages;
|
|
525
551
|
const steps = this.dependencySteps;
|
|
552
|
+
const forecastBlockers = this.forecastBlockers;
|
|
553
|
+
const notAdded = (sourcePath) => {
|
|
554
|
+
var _a, _b;
|
|
555
|
+
const target = rtlTarget(scanned.packages, sourcePath);
|
|
556
|
+
if (!target)
|
|
557
|
+
return new Map([[enzyme_usage_1.FILE_BLOCKER, (0, enzyme_render_blockers_1.blockedByFile)("rtlMissing")]]);
|
|
558
|
+
const outcome = !steps ? undefined : target.react18 ?
|
|
559
|
+
(_a = steps.dom18.outcomes.get(target.root)) !== null && _a !== void 0 ? _a : steps.rtl18.outcomes.get(target.root) : steps.rtl.outcomes.get(target.root);
|
|
560
|
+
const blockers = new Map([[enzyme_usage_1.FILE_BLOCKER, (0, enzyme_render_blockers_1.blockedByPackage)(target.root, outcome)]]);
|
|
561
|
+
if ((outcome === null || outcome === void 0 ? void 0 : outcome.kind) === "withheld")
|
|
562
|
+
(_b = forecastBlockers.get(sourcePath)) === null || _b === void 0 ? void 0 : _b.forEach((why, id) => blockers.set(id, why));
|
|
563
|
+
return blockers;
|
|
564
|
+
};
|
|
526
565
|
const untaggedPositions = this.untaggedSelectorPositions !== false;
|
|
527
566
|
const snapshots = this.snapshots;
|
|
528
567
|
return (0, rewrite_1.check)((0, rewrite_1.and)((0, rewrite_1.not)((0, javascript_1.isVendoredOrBundled)()), (0, rewrite_1.or)((0, javascript_1.usesMethod)("enzyme mount(..)"), (0, javascript_1.usesMethod)("enzyme shallow(..)"))), new class extends javascript_1.JavaScriptVisitor {
|
|
@@ -539,12 +578,14 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
539
578
|
this.mounts = new Map();
|
|
540
579
|
this.imports = new Map();
|
|
541
580
|
this.importedNames = new Set();
|
|
581
|
+
this.bindings = [];
|
|
542
582
|
this.declaredHost = new Set();
|
|
543
583
|
this.uses = new Map();
|
|
544
584
|
this.removedStatements = new Set();
|
|
545
585
|
this.unmounts = new Set();
|
|
546
586
|
this.declarations = new Set();
|
|
547
587
|
this.pending = new Set();
|
|
588
|
+
this.sharedRenders = new Set();
|
|
548
589
|
this.reformat = new Set();
|
|
549
590
|
this.hoists = new Map();
|
|
550
591
|
this.hoistedMounts = new Map();
|
|
@@ -561,13 +602,15 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
561
602
|
});
|
|
562
603
|
return __awaiter(this, void 0, void 0, function* () {
|
|
563
604
|
this.sourcePath = cu.sourcePath;
|
|
564
|
-
[this.mounts, this.uses, this.removedStatements, this.unmounts, this.declarations, this.pending, this.reformat].forEach(ids => ids.clear());
|
|
605
|
+
[this.mounts, this.uses, this.removedStatements, this.unmounts, this.declarations, this.pending, this.reformat, this.sharedRenders].forEach(ids => ids.clear());
|
|
565
606
|
this.hoists.clear();
|
|
566
607
|
this.hoistedMounts.clear();
|
|
567
608
|
this.rows.length = 0;
|
|
568
609
|
this.blockers.clear();
|
|
569
610
|
if (!dry)
|
|
570
611
|
enzyme_usage_1.RENDER_BLOCKERS.delete(cu.sourcePath);
|
|
612
|
+
if (!dry)
|
|
613
|
+
yield this.readSelectors(cu);
|
|
571
614
|
this.names = (0, javascript_1.namesUsedIn)(cu);
|
|
572
615
|
const prettierStyle = (0, rewrite_1.findMarker)(cu, javascript_1.StyleKind.PrettierStyle);
|
|
573
616
|
this.prettier = prettierStyle !== undefined && !prettierStyle.ignored && (yield formattedBy(cu, prettierStyle));
|
|
@@ -582,11 +625,14 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
582
625
|
this.enabled = this.reactMajor > 0 && (0, javascript_1.moduleBindings)(this).moduleSystem === "esm";
|
|
583
626
|
if (!this.enabled) {
|
|
584
627
|
const why = this.reactMajor === 0 ? incompatibility(scanned.packages, cu.sourcePath, landed) : "commonjs";
|
|
628
|
+
if (dry && why && why !== "rtlMissing")
|
|
629
|
+
forecastBlockers.set(cu.sourcePath, new Map([[enzyme_usage_1.FILE_BLOCKER, (0, enzyme_render_blockers_1.blockedByFile)(why)]]));
|
|
585
630
|
if (!dry && why)
|
|
586
|
-
enzyme_usage_1.RENDER_BLOCKERS.set(cu.sourcePath, new Map([[enzyme_usage_1.FILE_BLOCKER, (0, enzyme_render_blockers_1.blockedByFile)(why)]]));
|
|
631
|
+
enzyme_usage_1.RENDER_BLOCKERS.set(cu.sourcePath, why === "rtlMissing" ? notAdded(cu.sourcePath) : new Map([[enzyme_usage_1.FILE_BLOCKER, (0, enzyme_render_blockers_1.blockedByFile)(why)]]));
|
|
587
632
|
return cu;
|
|
588
633
|
}
|
|
589
634
|
this.imports = (0, enzyme_host_components_1.relativeImports)(cu, scanned.components);
|
|
635
|
+
this.bindings = (0, module_imports_1.importBindings)(cu);
|
|
590
636
|
this.importedNames = (0, enzyme_host_components_1.importedNames)(cu);
|
|
591
637
|
this.declaredHost = (0, enzyme_host_components_1.hostComponentsDeclared)(cu);
|
|
592
638
|
const foreign = prettierStyle !== undefined && !this.prettier;
|
|
@@ -601,9 +647,12 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
601
647
|
if (dry) {
|
|
602
648
|
if (this.rows.some(row => row.status === "CONVERTED"))
|
|
603
649
|
dry.converted.add(cu.sourcePath);
|
|
650
|
+
if (this.blockers.size > 0)
|
|
651
|
+
forecastBlockers.set(cu.sourcePath, new Map(this.blockers));
|
|
604
652
|
}
|
|
605
653
|
else {
|
|
606
654
|
this.rows.forEach(row => usages.insertRow(ctx, row));
|
|
655
|
+
yield this.blockShapes(cu, ctx);
|
|
607
656
|
if (this.blockers.size > 0)
|
|
608
657
|
enzyme_usage_1.RENDER_BLOCKERS.set(cu.sourcePath, new Map(this.blockers));
|
|
609
658
|
}
|
|
@@ -626,10 +675,26 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
626
675
|
this.cursor = new rewrite_1.Cursor(candidate, original.parent);
|
|
627
676
|
const converted = yield this.convertBlock(candidate, ctx);
|
|
628
677
|
this.cursor = original;
|
|
629
|
-
if (mounts.every(id => this.mounts.has(id) && !this.pending.has(id)))
|
|
678
|
+
if (mounts.every(({ id }) => this.mounts.has(id) && !this.pending.has(id)))
|
|
630
679
|
return this.renderedInHooks(converted, block, shared, ctx);
|
|
680
|
+
const kept = new Map();
|
|
681
|
+
for (const { id, from } of mounts) {
|
|
682
|
+
const why = this.blockers.get(id);
|
|
683
|
+
if (why && !kept.has(from))
|
|
684
|
+
kept.set(from, why);
|
|
685
|
+
}
|
|
686
|
+
for (const { id, from, name } of mounts) {
|
|
687
|
+
if (!kept.has(from) && this.mounts.has(id) && !this.pending.has(id))
|
|
688
|
+
kept.set(from, (0, enzyme_render_blockers_1.blockedByShared)(name));
|
|
689
|
+
}
|
|
631
690
|
this.restoreState(saved);
|
|
632
|
-
|
|
691
|
+
const plain = yield this.convertBlock(block, ctx);
|
|
692
|
+
mounts.forEach(({ from }) => this.sharedRenders.add(from));
|
|
693
|
+
kept.forEach((why, id) => {
|
|
694
|
+
if (!this.blockers.has(id))
|
|
695
|
+
this.blockers.set(id, why);
|
|
696
|
+
});
|
|
697
|
+
return plain;
|
|
633
698
|
});
|
|
634
699
|
}
|
|
635
700
|
renderedInHooks(block, original, shared, ctx) {
|
|
@@ -814,7 +879,7 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
814
879
|
const declared = yield declare.apply(statement.element, cursor);
|
|
815
880
|
if (!declared)
|
|
816
881
|
throw new Error(`Cannot declare ${name}`);
|
|
817
|
-
mounts.push(declared.variables[0].element.initializer.element.id);
|
|
882
|
+
mounts.push({ id: declared.variables[0].element.initializer.element.id, from: assignment.assignment.element.id, name });
|
|
818
883
|
statements.push(Object.assign(Object.assign({}, statement), { element: Object.assign(Object.assign({}, declared), { prefix: statement.element.prefix }) }));
|
|
819
884
|
}
|
|
820
885
|
return withoutStatements((0, mutative_1.create)(visited, draft => {
|
|
@@ -833,7 +898,7 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
833
898
|
const declared = yield declare.apply(first.element, cursor);
|
|
834
899
|
if (!declared)
|
|
835
900
|
throw new Error(`Cannot declare ${hooked.name}`);
|
|
836
|
-
mounts.push(declared.variables[0].element.initializer.element.id);
|
|
901
|
+
mounts.push({ id: declared.variables[0].element.initializer.element.id, from: hooked.mount.id, name: hooked.name });
|
|
837
902
|
const semicolon = test.statements.some(padded => padded.markers.markers.some(marker => marker.kind === java_1.J.Markers.Semicolon));
|
|
838
903
|
const padded = Object.assign(Object.assign({}, first), { element: Object.assign(Object.assign({}, declared), { prefix: first.element.prefix }), markers: Object.assign(Object.assign({}, first.markers), { markers: semicolon ? [{ kind: java_1.J.Markers.Semicolon, id: (0, rewrite_1.randomId)() }] : [] }) });
|
|
839
904
|
return (0, mutative_1.create)(test, draft => {
|
|
@@ -886,7 +951,7 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
886
951
|
const reads = READS[api];
|
|
887
952
|
const markup = this.reactMajor >= 16;
|
|
888
953
|
let blocking;
|
|
889
|
-
const scope = (0, enzyme_wrapper_scope_1.analyzeWrapperScope)(this.cursor, candidate, { events: reads.simulate ? this.events.events : new Set(), html: reads.html && markup, untaggedPositions, hostNames, snapshots: snapshots && markup, optionalChaining: this.optionalChaining,
|
|
954
|
+
const scope = (0, enzyme_wrapper_scope_1.analyzeWrapperScope)(this.cursor, candidate, { events: reads.simulate ? this.events.events : new Set(), html: reads.html && markup, untaggedPositions, hostNames, snapshots: snapshots && markup, optInSnapshots: !snapshots && markup, optionalChaining: this.optionalChaining,
|
|
890
955
|
constant: node => this.constantString(node), blocked: references => blocking = references });
|
|
891
956
|
if (!scope) {
|
|
892
957
|
if (blocking)
|
|
@@ -1181,7 +1246,7 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
1181
1246
|
const element = (_a = call.arguments.elements[0]) === null || _a === void 0 ? void 0 : _a.element;
|
|
1182
1247
|
if ((0, enzyme_host_components_1.rendersHostElements)(element, this.imports, scanned.components, this.importedNames, this.declaredHost))
|
|
1183
1248
|
return api;
|
|
1184
|
-
this.blockers.set(call.id, (0, enzyme_render_blockers_1.
|
|
1249
|
+
this.blockers.set(call.id, (0, enzyme_render_blockers_1.blockedByShallow)((0, enzyme_host_components_1.shallowMiss)(element, this.imports, scanned.components, scanned.composites, this.bindings)));
|
|
1185
1250
|
return undefined;
|
|
1186
1251
|
}
|
|
1187
1252
|
rendersPortal(call) {
|
|
@@ -1211,6 +1276,88 @@ class EnzymeToReactTestingLibrary extends rewrite_1.ScanningRecipe {
|
|
|
1211
1276
|
const declares = (name) => roots.some(root => scanned.packages.get(root).dependencies.has(name));
|
|
1212
1277
|
return { roots, declares, resolve: (0, enzyme_portals_1.resolver)(scanned.modules, [...new Set([...roots, ""])], declares) };
|
|
1213
1278
|
}
|
|
1279
|
+
blockShapes(cu, ctx) {
|
|
1280
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1281
|
+
const blockers = this.blockers;
|
|
1282
|
+
const mounts = this.mounts;
|
|
1283
|
+
const sharedRenders = this.sharedRenders;
|
|
1284
|
+
yield new class extends javascript_1.JavaScriptVisitor {
|
|
1285
|
+
visitMethodInvocation(method, ctx) {
|
|
1286
|
+
const _super = Object.create(null, {
|
|
1287
|
+
visitMethodInvocation: { get: () => super.visitMethodInvocation }
|
|
1288
|
+
});
|
|
1289
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1290
|
+
const api = (0, enzyme_usage_1.enzymeMethod)(method);
|
|
1291
|
+
if ((api === "mount" || api === "shallow") && !blockers.has(method.id) && !mounts.has(method.id) && !sharedRenders.has(method.id)) {
|
|
1292
|
+
const why = (0, enzyme_render_blockers_1.blockedByShape)(this.cursor);
|
|
1293
|
+
if (why)
|
|
1294
|
+
blockers.set(method.id, why);
|
|
1295
|
+
}
|
|
1296
|
+
return _super.visitMethodInvocation.call(this, method, ctx);
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
}().visit(cu, ctx);
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
readSelectors(cu) {
|
|
1303
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1304
|
+
enzyme_usage_1.SELECTOR_VALUES.delete(cu.sourcePath);
|
|
1305
|
+
const finds = [];
|
|
1306
|
+
(0, javascript_1.walk)(cu, tree => {
|
|
1307
|
+
if (tree.kind === java_1.J.Kind.MethodInvocation && (0, enzyme_usage_1.enzymeMethod)(tree) === "find" &&
|
|
1308
|
+
tree.arguments.elements.length === 1)
|
|
1309
|
+
finds.push(tree);
|
|
1310
|
+
return true;
|
|
1311
|
+
});
|
|
1312
|
+
const topLevel = new Set(cu.statements.map(({ element }) => { var _a; return element.kind === javascript_1.JS.Kind.ExportDeclaration ? (_a = element.exportClause) === null || _a === void 0 ? void 0 : _a.id : element.id; }));
|
|
1313
|
+
const nested = new Set();
|
|
1314
|
+
(0, javascript_1.walk)(cu, tree => {
|
|
1315
|
+
if (tree.kind !== java_1.J.Kind.VariableDeclarations || topLevel.has(tree.id))
|
|
1316
|
+
return true;
|
|
1317
|
+
const variables = tree;
|
|
1318
|
+
if (!variables.modifiers.some(modifier => modifier.keyword === "const"))
|
|
1319
|
+
return true;
|
|
1320
|
+
for (const { element: variable } of variables.variables) {
|
|
1321
|
+
if ((0, java_1.isIdentifier)(variable.name) && variable.initializer && (0, enzyme_constant_strings_1.stringParts)(variable.initializer.element))
|
|
1322
|
+
nested.add(variable.name.simpleName);
|
|
1323
|
+
}
|
|
1324
|
+
return true;
|
|
1325
|
+
});
|
|
1326
|
+
const reads = new Map();
|
|
1327
|
+
for (const find of finds) {
|
|
1328
|
+
const read = yield this.selectorRead(find.arguments.elements[0].element, nested);
|
|
1329
|
+
if (read)
|
|
1330
|
+
reads.set(find.id, read);
|
|
1331
|
+
}
|
|
1332
|
+
if (reads.size > 0)
|
|
1333
|
+
enzyme_usage_1.SELECTOR_VALUES.set(cu.sourcePath, reads);
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
selectorRead(selector, nested) {
|
|
1337
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1338
|
+
const named = (name) => (0, enzyme_constant_strings_1.evaluate)([{ name }], this.sourcePath, scanned.modules, this.moduleResolution().resolve);
|
|
1339
|
+
const printed = (node) => __awaiter(this, void 0, void 0, function* () { return (yield rewrite_1.TreePrinters.printer(javascript_1.JS.Kind.CompilationUnit).print(node)).trim().replace(/\s+/g, " "); });
|
|
1340
|
+
if (selector.kind === javascript_1.JS.Kind.TemplateExpression) {
|
|
1341
|
+
const value = this.constantString(selector);
|
|
1342
|
+
if (value !== undefined)
|
|
1343
|
+
return { value };
|
|
1344
|
+
for (const { element: span } of selector.spans) {
|
|
1345
|
+
const part = span.expression;
|
|
1346
|
+
if ((0, java_1.isIdentifier)(part) && nested.has(part.simpleName))
|
|
1347
|
+
return undefined;
|
|
1348
|
+
if (!(0, java_1.isIdentifier)(part) || named(part.simpleName) === undefined)
|
|
1349
|
+
return { unread: yield printed(part) };
|
|
1350
|
+
}
|
|
1351
|
+
return undefined;
|
|
1352
|
+
}
|
|
1353
|
+
const value = (0, java_1.isIdentifier)(selector) ? named(selector.simpleName) : undefined;
|
|
1354
|
+
if (value !== undefined)
|
|
1355
|
+
return { value };
|
|
1356
|
+
if (java_1.TypedTree.getType(selector) !== java_1.Type.Primitive.String || (0, java_1.isIdentifier)(selector) && nested.has(selector.simpleName))
|
|
1357
|
+
return undefined;
|
|
1358
|
+
return (0, java_1.isIdentifier)(selector) || selector.kind === java_1.J.Kind.FieldAccess ? { unread: yield printed(selector) } : undefined;
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1214
1361
|
constantString(node) {
|
|
1215
1362
|
const parts = (0, enzyme_constant_strings_1.stringParts)(node);
|
|
1216
1363
|
return parts && (0, enzyme_constant_strings_1.evaluate)(parts, this.sourcePath, scanned.modules, this.moduleResolution().resolve);
|