-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(server): ensure consistency between CLI serve entrypoints regardi…
…ng help and strict (#9809) This PR aims to fix inconsistencies across all the CLI entry points around `--help` and strict. This PR is technically breaking but I feel like most users would consider many of these things to be bug fixes (e.g. `--help` runs the server 😂). @Tobbe we can talk in more detail about all the changes. Here's a non exhaustive list of all the changes - the `api-root-path` alias was added to `@redwoodjs/api-server` to make the options the same across `yarn rw serve` and `yarn rw-server` - refactored `@redwoodjs/api-server` entrypoint to handle `--help` and yargs strict mode and; we also moved parsing into the if block cause it was running too early (during import) - for the CLI (`yarn rw ...`) yargs strict mode wasn’t exiting with exit code 1 when unknown arguments were passed; now it does and it prints to stderr in the case there is an error - for `@redwoodjs/web-server`, passing `--help` would just run the server since we were using `yargsParser` instead of `yargs`; also added strict mode here and like the others; kept the options the same between the entrypoints - updated the server-tests tests to handle all these cases - spiked out some more tests to write to ensure we're covering all the similarities and differences before refactoring everything --------- Co-authored-by: Tobbe Lundberg <[email protected]>
- Loading branch information
Showing
11 changed files
with
470 additions
and
298 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
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
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
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
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
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
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
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,51 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`serve web (/Users/dom/projects/redwood/redwood/packages/web-server/dist/server.js) errors out on unknown args 1`] = ` | ||
"rw-web-server | ||
Start server for serving only the web side | ||
Options: | ||
--help Show help [boolean] | ||
--version Show version number [boolean] | ||
-p, --port [number] [default: 8910] | ||
--socket [string] | ||
--apiHost, --api-host Forward requests from the apiUrl, defined in | ||
redwood.toml, to this host [string] | ||
Unknown arguments: foo, bar, baz | ||
" | ||
`; | ||
|
||
exports[`serve web (/Users/dom/projects/redwood/redwood/packages/web-server/dist/server.js) fails if apiHost isn't set and apiUrl isn't fully qualified 1`] = ` | ||
"Error: If you don't provide apiHost, apiUrl needs to be a fully-qualified URL. But apiUrl is /.redwood/functions. | ||
" | ||
`; | ||
|
||
exports[`serve web ([ | ||
'/Users/dom/projects/redwood/redwood/packages/api-server/dist/index.js', | ||
'web' | ||
]) errors out on unknown args 1`] = ` | ||
"rw-server web | ||
Start server for serving only the web side | ||
Options: | ||
--help Show help [boolean] | ||
--version Show version number [boolean] | ||
-p, --port [number] [default: 8910] | ||
--socket [string] | ||
--apiHost, --api-host Forward requests from the apiUrl, defined in | ||
redwood.toml, to this host [string] | ||
Unknown arguments: foo, bar, baz | ||
" | ||
`; | ||
|
||
exports[`serve web ([ | ||
'/Users/dom/projects/redwood/redwood/packages/api-server/dist/index.js', | ||
'web' | ||
]) fails if apiHost isn't set and apiUrl isn't fully qualified 1`] = ` | ||
"[31mError[39m: If you don't provide [35mapiHost[39m, [35mapiUrl[39m needs to be a fully-qualified URL. But [35mapiUrl[39m is [33m/.redwood/functions[39m. | ||
" | ||
`; |
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,7 +1,9 @@ | ||
/** @type {import('jest').Config} */ | ||
const config = { | ||
rootDir: '.', | ||
testMatch: ['<rootDir>/*.test.mjs'], | ||
testTimeout: 5_000 * 2, | ||
transform: {}, | ||
} | ||
|
||
module.exports = config |
Oops, something went wrong.