-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5b2641
commit c364bd4
Showing
16 changed files
with
142 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@react-router/dev": patch | ||
--- | ||
|
||
Fix `reveal` and `routes` CLI commands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import path from "node:path"; | ||
import fse from "fs-extra"; | ||
import execa from "execa"; | ||
|
||
function getProjectDir() { | ||
let projectDir = path.join( | ||
__dirname, | ||
".tmp", | ||
`reveal-test-${Math.random().toString(32).slice(2)}` | ||
); | ||
fse.copySync(path.join(__dirname, "fixtures", "basic"), projectDir); | ||
return projectDir; | ||
} | ||
|
||
async function runCli(cwd: string, args: string[]) { | ||
return await execa( | ||
"node", | ||
[ | ||
"--require", | ||
require.resolve("esbuild-register"), | ||
path.resolve(__dirname, "../cli/index.ts"), | ||
...args, | ||
], | ||
{ cwd } | ||
); | ||
} | ||
|
||
describe("the reveal command", () => { | ||
it("generates an entry.server.tsx file in the app directory", async () => { | ||
let projectDir = getProjectDir(); | ||
|
||
let entryClientFile = path.join(projectDir, "app", "entry.client.tsx"); | ||
let entryServerFile = path.join(projectDir, "app", "entry.server.tsx"); | ||
|
||
expect(fse.existsSync(entryServerFile)).toBeFalsy(); | ||
expect(fse.existsSync(entryClientFile)).toBeFalsy(); | ||
|
||
await runCli(projectDir, ["reveal"]); | ||
|
||
expect(fse.existsSync(entryServerFile)).toBeTruthy(); | ||
expect(fse.existsSync(entryClientFile)).toBeTruthy(); | ||
}); | ||
|
||
it("generates an entry.server.tsx file in the app directory when specific entries are provided", async () => { | ||
let projectDir = getProjectDir(); | ||
|
||
let entryClientFile = path.join(projectDir, "app", "entry.client.tsx"); | ||
let entryServerFile = path.join(projectDir, "app", "entry.server.tsx"); | ||
|
||
expect(fse.existsSync(entryServerFile)).toBeFalsy(); | ||
expect(fse.existsSync(entryClientFile)).toBeFalsy(); | ||
|
||
await runCli(projectDir, ["reveal", "entry.server"]); | ||
expect(fse.existsSync(entryServerFile)).toBeTruthy(); | ||
expect(fse.existsSync(entryClientFile)).toBeFalsy(); | ||
fse.removeSync(entryServerFile); | ||
|
||
await runCli(projectDir, ["reveal", "entry.client"]); | ||
expect(fse.existsSync(entryClientFile)).toBeTruthy(); | ||
expect(fse.existsSync(entryServerFile)).toBeFalsy(); | ||
}); | ||
|
||
it("generates an entry.server.jsx file in the app directory", async () => { | ||
let projectDir = getProjectDir(); | ||
|
||
let entryClientFile = path.join(projectDir, "app", "entry.client.jsx"); | ||
let entryServerFile = path.join(projectDir, "app", "entry.server.jsx"); | ||
|
||
expect(fse.existsSync(entryServerFile)).toBeFalsy(); | ||
expect(fse.existsSync(entryClientFile)).toBeFalsy(); | ||
|
||
await runCli(projectDir, ["reveal", "--no-typescript"]); | ||
|
||
expect(fse.existsSync(entryServerFile)).toBeTruthy(); | ||
expect(fse.existsSync(entryClientFile)).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import path from "node:path"; | ||
import execa from "execa"; | ||
|
||
async function runCli(cwd: string, args: string[]) { | ||
return await execa( | ||
"node", | ||
[ | ||
"--require", | ||
require.resolve("esbuild-register"), | ||
path.resolve(__dirname, "../cli/index.ts"), | ||
...args, | ||
], | ||
{ cwd } | ||
); | ||
} | ||
|
||
describe("the routes command", () => { | ||
it("displays routes", async () => { | ||
let projectDir = path.join(__dirname, "fixtures", "basic"); | ||
|
||
let result = await runCli(projectDir, ["routes"]); | ||
|
||
expect(result.stdout).toMatchInlineSnapshot(` | ||
"<Routes> | ||
<Route file="root.tsx"> | ||
<Route index file="routes/_index.tsx" /> | ||
</Route> | ||
</Routes>" | ||
`); | ||
}); | ||
}); |
4 changes: 2 additions & 2 deletions
4
...er-dev/__tests__/fixtures/node/.gitignore → ...r-dev/__tests__/fixtures/basic/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
node_modules | ||
|
||
/.cache | ||
/build | ||
/public/build | ||
.env | ||
|
||
.react-router/ |
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
packages/react-router-dev/__tests__/fixtures/basic/app/routes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Note that since this is used in a unit test context, we don't have access to | ||
// the `dev` build yet, so we can't import from `@react-router/dev/routes`. | ||
const routes = [{ file: "routes/_index.tsx", index: true }]; | ||
|
||
export default routes; |
File renamed without changes.
File renamed without changes.
Binary file added
BIN
+14.7 KB
packages/react-router-dev/__tests__/fixtures/basic/public/favicon.ico
Binary file not shown.
3 changes: 2 additions & 1 deletion
3
...dev/__tests__/fixtures/node/tsconfig.json → ...ev/__tests__/fixtures/basic/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
packages/react-router-dev/__tests__/fixtures/node/README.md
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-16.6 KB
packages/react-router-dev/__tests__/fixtures/node/public/favicon.ico
Binary file not shown.
2 changes: 0 additions & 2 deletions
2
packages/react-router-dev/__tests__/fixtures/node/remix.env.d.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.