-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: the docs command should not crash if given search terms (#6879)
* fix: the docs command should not crash if given search terms Fixes a regression accidentally introduced by #3735. * fixup! fix: the docs command should not crash if given search terms * Rename `command` positional to `search` to make it clearer what it is used for * fixup! fix: the docs command should not crash if given search terms
- Loading branch information
1 parent
b123f43
commit b27d8cb
Showing
6 changed files
with
141 additions
and
9 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,7 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
fix: the docs command should not crash if given search terms | ||
|
||
Fixes a regression accidentally introduced by #3735. |
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,124 @@ | ||
import { http, HttpResponse } from "msw"; | ||
import { afterEach, beforeEach, describe, test } from "vitest"; | ||
import openInBrowser from "../open-in-browser"; | ||
import { mockConsoleMethods } from "./helpers/mock-console"; | ||
import { msw } from "./helpers/msw"; | ||
import { runWrangler } from "./helpers/run-wrangler"; | ||
|
||
// NOTE: in production builds we "esbuild define" Algolia constants as globals | ||
// but in tests we have to attach mocks values to the globalThis object. | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
declare module globalThis { | ||
let ALGOLIA_APP_ID: string | undefined; | ||
let ALGOLIA_PUBLIC_KEY: string | undefined; | ||
} | ||
|
||
describe("wrangler docs", () => { | ||
const std = mockConsoleMethods(); | ||
|
||
beforeEach(() => { | ||
globalThis.ALGOLIA_APP_ID = "FAKE-ID"; | ||
globalThis.ALGOLIA_PUBLIC_KEY = "FAKE-KEY"; | ||
|
||
msw.use( | ||
http.post<Record<string, never>, { params: string | undefined }>( | ||
`*/1/indexes/developers-cloudflare2/query`, | ||
async ({ request }) => { | ||
return HttpResponse.json({ | ||
hits: [ | ||
{ | ||
url: `FAKE_DOCS_URL:${await request.text()}`, | ||
}, | ||
], | ||
}); | ||
}, | ||
{ once: true } | ||
) | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
delete globalThis.ALGOLIA_APP_ID; | ||
delete globalThis.ALGOLIA_PUBLIC_KEY; | ||
}); | ||
|
||
test("--help", async ({ expect }) => { | ||
const result = runWrangler("docs --help"); | ||
|
||
await expect(result).resolves.toBeUndefined(); | ||
expect(std.out).toMatchInlineSnapshot(` | ||
"wrangler docs [search..] | ||
📚 Open Wrangler's command documentation in your browser | ||
POSITIONALS | ||
search Enter search terms (e.g. the wrangler command) you want to know more about [array] [default: []] | ||
GLOBAL FLAGS | ||
-j, --experimental-json-config Experimental: support wrangler.json [boolean] | ||
-c, --config Path to .toml configuration file [string] | ||
-e, --env Environment to use for operations and .env files [string] | ||
-h, --help Show help [boolean] | ||
-v, --version Show version number [boolean] | ||
OPTIONS | ||
-y, --yes Takes you to the docs, even if search fails [boolean]" | ||
`); | ||
}); | ||
|
||
test("opens a browser to Cloudflare docs when given no search term", async ({ | ||
expect, | ||
}) => { | ||
await runWrangler("docs"); | ||
expect(std).toMatchInlineSnapshot(` | ||
Object { | ||
"debug": "", | ||
"err": "", | ||
"info": "", | ||
"out": "Opening a link in your default browser: https://developers.cloudflare.com/workers/wrangler/commands/", | ||
"warn": "", | ||
} | ||
`); | ||
expect(openInBrowser).toHaveBeenCalledWith( | ||
"https://developers.cloudflare.com/workers/wrangler/commands/" | ||
); | ||
}); | ||
|
||
test("opens a browser to Cloudflare docs when given a single search term", async ({ | ||
expect, | ||
}) => { | ||
await runWrangler("docs dev"); | ||
expect(std).toMatchInlineSnapshot(` | ||
Object { | ||
"debug": "", | ||
"err": "", | ||
"info": "", | ||
"out": "Opening a link in your default browser: FAKE_DOCS_URL:{\\"params\\":\\"query=dev&hitsPerPage=1&getRankingInfo=0\\"}", | ||
"warn": "", | ||
} | ||
`); | ||
expect(openInBrowser).toHaveBeenCalledWith( | ||
'FAKE_DOCS_URL:{"params":"query=dev&hitsPerPage=1&getRankingInfo=0"}' | ||
); | ||
}); | ||
|
||
test("opens a browser to Cloudflare docs when given multiple search terms", async ({ | ||
expect, | ||
}) => { | ||
await runWrangler("docs foo bar"); | ||
expect(std).toMatchInlineSnapshot(` | ||
Object { | ||
"debug": "", | ||
"err": "", | ||
"info": "", | ||
"out": "Opening a link in your default browser: FAKE_DOCS_URL:{\\"params\\":\\"query=foo+bar&hitsPerPage=1&getRankingInfo=0\\"}", | ||
"warn": "", | ||
} | ||
`); | ||
expect(openInBrowser).toHaveBeenCalledWith( | ||
'FAKE_DOCS_URL:{"params":"query=foo+bar&hitsPerPage=1&getRankingInfo=0"}' | ||
); | ||
}); | ||
}); |
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