@@ -92,8 +92,30 @@ describe("transform", () => {
9292)
9393const expected = removeWhitespace ( `
9494import { withLoaderWrapper as _withLoaderWrapper } from "react-router-devtools/server";
95- import { loader } from "./loader.js";
96- export { loader as _loader };
95+ import { loader as _loader } from "./loader.js";
96+ export const loader = _withLoaderWrapper(_loader, "test");
97+ ` )
98+ expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
99+ } )
100+
101+ it ( "should wrap the loader export when it's imported from another file and exported and used" , ( ) => {
102+ const result = augmentDataFetchingFunctions (
103+ `
104+ import { loader } from "./loader.js";
105+ const test = () => {
106+ const data = loader();
107+ }
108+ export { loader };
109+ ` ,
110+ "test" ,
111+ "/file/path"
112+ )
113+ const expected = removeWhitespace ( `
114+ import { withLoaderWrapper as _withLoaderWrapper } from "react-router-devtools/server";
115+ import { loader as _loader } from "./loader.js";
116+ const test = () => {
117+ const data = _loader();
118+ };
97119export const loader = _withLoaderWrapper(_loader, "test");
98120` )
99121expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
@@ -217,8 +239,30 @@ describe("transform", () => {
217239)
218240const expected = removeWhitespace ( `
219241import { withClientLoaderWrapper as _withClientLoaderWrapper } from "react-router-devtools/client";
220- import { clientLoader } from "./client-loader.js";
221- export { clientLoader as _clientLoader };
242+ import { clientLoader as _clientLoader } from "./client-loader.js";
243+ export const clientLoader = _withClientLoaderWrapper(_clientLoader, "test");
244+ ` )
245+ expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
246+ } )
247+
248+ it ( "should wrap the client loader export when it's re-exported from another file and used by other code" , ( ) => {
249+ const result = augmentDataFetchingFunctions (
250+ `
251+ import { clientLoader } from "./client-loader.js";
252+ const test = () => {
253+ const data = clientLoader();
254+ }
255+ export { clientLoader };
256+ ` ,
257+ "test" ,
258+ "/file/path"
259+ )
260+ const expected = removeWhitespace ( `
261+ import { withClientLoaderWrapper as _withClientLoaderWrapper } from "react-router-devtools/client";
262+ import { clientLoader as _clientLoader } from "./client-loader.js";
263+ const test = () => {
264+ const data = _clientLoader();
265+ };
222266export const clientLoader = _withClientLoaderWrapper(_clientLoader, "test");
223267` )
224268expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
@@ -235,8 +279,30 @@ describe("transform", () => {
235279)
236280const expected = removeWhitespace ( `
237281import { withClientLoaderWrapper as _withClientLoaderWrapper } from "react-router-devtools/client";
238- import { clientLoader } from "./client-loader.js";
239- export { clientLoader as _clientLoader };
282+ import { clientLoader as _clientLoader } from "./client-loader.js";
283+ export const clientLoader = _withClientLoaderWrapper(_clientLoader, "test");
284+ ` )
285+ expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
286+ } )
287+
288+ it ( "should wrap the client loader export when it's imported from another file and exported and used by other code" , ( ) => {
289+ const result = augmentDataFetchingFunctions (
290+ `
291+ import { clientLoader } from "./client-loader.js";
292+ const test = () => {
293+ const data = clientLoader();
294+ }
295+ export { clientLoader };
296+ ` ,
297+ "test" ,
298+ "/file/path"
299+ )
300+ const expected = removeWhitespace ( `
301+ import { withClientLoaderWrapper as _withClientLoaderWrapper } from "react-router-devtools/client";
302+ import { clientLoader as _clientLoader } from "./client-loader.js";
303+ const test = () => {
304+ const data = _clientLoader();
305+ };
240306export const clientLoader = _withClientLoaderWrapper(_clientLoader, "test");
241307` )
242308expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
@@ -373,8 +439,30 @@ describe("transform", () => {
373439)
374440const expected = removeWhitespace ( `
375441import { withActionWrapper as _withActionWrapper } from "react-router-devtools/server";
376- import { action } from "./action.js";
377- export { action as _action };
442+ import { action as _action } from "./action.js";
443+ export const action = _withActionWrapper(_action, "test");
444+ ` )
445+ expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
446+ } )
447+
448+ it ( "should wrap the action export when it's imported from another file and exported and used by other code" , ( ) => {
449+ const result = augmentDataFetchingFunctions (
450+ `
451+ import { action } from "./action.js";
452+ const test = () => {
453+ const data = action();
454+ }
455+ export { action };
456+ ` ,
457+ "test" ,
458+ "/file/path"
459+ )
460+ const expected = removeWhitespace ( `
461+ import { withActionWrapper as _withActionWrapper } from "react-router-devtools/server";
462+ import { action as _action } from "./action.js";
463+ const test = () => {
464+ const data = _action();
465+ };
378466export const action = _withActionWrapper(_action, "test");
379467` )
380468expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
@@ -478,8 +566,31 @@ describe("transform", () => {
478566)
479567const expected = removeWhitespace ( `
480568import { withClientActionWrapper as _withClientActionWrapper } from "react-router-devtools/client";
481- import { clientAction } from "./client-action.js";
482- export { clientAction as _clientAction };
569+ import { clientAction as _clientAction } from "./client-action.js";
570+ export const clientAction = _withClientActionWrapper(_clientAction, "test");
571+ ` )
572+ expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
573+ } )
574+
575+ it ( "should transform the client action export when it's re-exported from another file and keep it working if used somewhere" , ( ) => {
576+ const result = augmentDataFetchingFunctions (
577+ `
578+ import { clientAction } from "./client-action.js";
579+
580+ const test = () => {
581+ const data = clientAction();
582+ }
583+ export { clientAction };
584+ ` ,
585+ "test" ,
586+ "/file/path"
587+ )
588+ const expected = removeWhitespace ( `
589+ import { withClientActionWrapper as _withClientActionWrapper } from "react-router-devtools/client";
590+ import { clientAction as _clientAction } from "./client-action.js";
591+ const test = () => {
592+ const data = _clientAction();
593+ };
483594export const clientAction = _withClientActionWrapper(_clientAction, "test");
484595` )
485596expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
@@ -512,13 +623,77 @@ describe("transform", () => {
512623)
513624const expected = removeWhitespace ( `
514625import { withClientActionWrapper as _withClientActionWrapper } from "react-router-devtools/client";
515- import { clientAction } from "./client-action.js";
516- export { clientAction as _clientAction };
626+ import { clientAction as _clientAction } from "./client-action.js";
517627export const clientAction = _withClientActionWrapper(_clientAction, "test");
518628` )
519629expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
520630} )
521631
632+ it ( "should transform the client action export when it's imported from another file and exported and used by other code" , ( ) => {
633+ const result = augmentDataFetchingFunctions (
634+ `
635+ import { clientAction } from "./client-action.js";
636+ const test = () => {
637+ const data = clientAction();
638+ }
639+ export { clientAction };
640+ ` ,
641+ "test" ,
642+ "/file/path"
643+ )
644+ const expected = removeWhitespace ( `
645+ import { withClientActionWrapper as _withClientActionWrapper } from "react-router-devtools/client";
646+ import { clientAction as _clientAction } from "./client-action.js";
647+ const test = () => {
648+ const data = _clientAction();
649+ };
650+ export const clientAction = _withClientActionWrapper(_clientAction, "test");
651+ ` )
652+ expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
653+ } )
654+
655+ it ( "should transform the client action export when it's imported from another file and exported and keep the export around if more things are exported" , ( ) => {
656+ const result = augmentDataFetchingFunctions (
657+ `
658+ import { clientAction } from "./client-action.js";
659+ const test = () => {
660+ const data = clientAction();
661+ }
662+ export { clientAction, test };
663+ ` ,
664+ "test" ,
665+ "/file/path"
666+ )
667+ const expected = removeWhitespace ( `
668+ import { withClientActionWrapper as _withClientActionWrapper } from "react-router-devtools/client";
669+ import { clientAction as _clientAction } from "./client-action.js";
670+ const test = () => {
671+ const data = _clientAction();
672+ };
673+ export { test };
674+ export const clientAction = _withClientActionWrapper(_clientAction, "test");
675+ ` )
676+ expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
677+ } )
678+ it ( "should transform the client action export when it's imported from another file and exported and keep the export around if more things are exported" , ( ) => {
679+ const result = augmentDataFetchingFunctions (
680+ `
681+ import { withClientActionContextWrapper as _withClientActionContextWrapper } from "react-router-devtools/context";
682+ import { clientAction as _clientAction } from "./client-action.js";
683+ export const clientAction = _withClientActionContextWrapper(_clientAction, "test");
684+ ` ,
685+ "test" ,
686+ "/file/path"
687+ )
688+ const expected = removeWhitespace ( `
689+ import { withClientActionWrapper as _withClientActionWrapper } from "react-router-devtools/client";
690+ import { withClientActionContextWrapper as _withClientActionContextWrapper } from "react-router-devtools/context";
691+ import { clientAction as _clientAction } from "./client-action.js";
692+ export const clientAction = _withClientActionWrapper(_withClientActionContextWrapper(_clientAction, "test"), "test");
693+ ` )
694+ expect ( removeWhitespace ( result . code ) ) . toStrictEqual ( expected )
695+ } )
696+
522697it ( "should wrap the clientAction export when it's exported via export { clientAction } and declared within the file" , ( ) => {
523698const result = augmentDataFetchingFunctions (
524699`