Skip to content

Commit

Permalink
fix: route route module making it to the browser (remix-run#2652)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-ebey authored Apr 5, 2022
1 parent ef7fff6 commit 640cec8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
45 changes: 40 additions & 5 deletions integration/fetcher-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,41 @@ describe("useFetcher", () => {
beforeAll(async () => {
fixture = await createFixture({
files: {
"app/routes/resource-route-action-only.ts": js`
import { json } from "@remix-run/node";
export function action() {
return json("${CHEESESTEAK}");
}
`,

"app/routes/fetcher-action-only-call.tsx": js`
import { useFetcher } from "@remix-run/react";
export default function FetcherActionOnlyCall() {
let fetcher = useFetcher();
let executeFetcher = () => {
fetcher.submit(new URLSearchParams(), {
method: 'post',
action: '/resource-route-action-only',
});
};
return (
<>
<button id="fetcher-submit" onClick={executeFetcher}>Click Me</button>
{fetcher.data && <pre>{fetcher.data}</pre>}
</>
);
}
`,

"app/routes/resource-route.jsx": js`
export function loader() {
return "${LUNCH}"
return "${LUNCH}";
}
export function action() {
return "${CHEESESTEAK}"
return "${CHEESESTEAK}";
}
`,

Expand All @@ -31,21 +60,21 @@ describe("useFetcher", () => {
<button type="submit" formMethod="post">post</button>
</fetcher.Form>
<button id="fetcher-load" type="button" onClick={() => {
fetcher.load('/resource-route')
fetcher.load('/resource-route');
}}>
load
</button>
<button id="fetcher-submit" type="button" onClick={() => {
fetcher.submit(new URLSearchParams(), {
method: 'post',
action: '/resource-route'
})
});
}}>
submit
</button>
<pre>{fetcher.data}</pre>
</>
)
);
}
`,
},
Expand Down Expand Up @@ -93,4 +122,10 @@ describe("useFetcher", () => {
await app.clickElement("#fetcher-submit");
expect(await app.getHtml("pre")).toMatch(CHEESESTEAK);
});

test("submit can hit an action only route", async () => {
await app.goto("/fetcher-action-only-call");
await app.clickElement("#fetcher-submit");
expect(await app.getHtml("pre")).toMatch(CHEESESTEAK);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ export function browserRouteModulesPlugin(
],
};
}
let spec =
theExports.length > 0 ? `{ ${theExports.join(", ")} }` : "*";
let contents = `export ${spec} from ${JSON.stringify(file)};`;

let contents = "module.exports = {};";
if (theExports.length !== 0) {
let spec = `{ ${theExports.join(", ")} }`;
contents = `export ${spec} from ${JSON.stringify(file)};`;
}

return {
contents,
Expand Down

0 comments on commit 640cec8

Please sign in to comment.