mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-31 03:29:43 -06:00
docs: url tag now throws if given undefined href
This commit is contained in:
@@ -168,7 +168,19 @@ function validateLocalFile (sidebar, href, source, render) {
|
||||
})
|
||||
}
|
||||
|
||||
function validateAndGetUrl (sidebar, href, source, render) {
|
||||
function validateAndGetUrl (sidebar, href, source, text, render) {
|
||||
if (!href) {
|
||||
// if we dont have a hash
|
||||
return Promise.reject(
|
||||
new Error(`A url tag was not passed an href argument.
|
||||
|
||||
> The source file was: ${source}
|
||||
|
||||
> url tag's text was: ${text}
|
||||
`)
|
||||
)
|
||||
}
|
||||
|
||||
// do we already have a cache for this href?
|
||||
const cachedValue = cache[href]
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ hexo.extend.tag.register('url', function (args) {
|
||||
return hexo.render.render({ text, engine: 'markdown' })
|
||||
}
|
||||
|
||||
return urlGenerator.validateAndGetUrl(sidebar, attrs.href, this.full_source, onRender)
|
||||
return urlGenerator.validateAndGetUrl(sidebar, attrs.href, this.full_source, props.text, onRender)
|
||||
.then((href) => {
|
||||
attrs.href = href
|
||||
|
||||
|
||||
@@ -95,6 +95,21 @@ describe "lib/url_generator", ->
|
||||
expect(err.message).to.include("Could not find a valid doc file in the sidebar.yml for: foo")
|
||||
|
||||
context ".validateAndGetUrl", ->
|
||||
it "fails when given undefined href", ->
|
||||
render = (str) ->
|
||||
return Promise.resolve("<html><div id='notes'>notes</div></html>")
|
||||
|
||||
urlGenerator.validateAndGetUrl(data, undefined, 'foo', 'content', render )
|
||||
.then ->
|
||||
throw new Error("should have caught error")
|
||||
.catch (err) ->
|
||||
[
|
||||
"A url tag was not passed an href argument."
|
||||
"The source file was: foo"
|
||||
"url tag's text was: content",
|
||||
].forEach (msg) ->
|
||||
expect(err.message).to.include(msg)
|
||||
|
||||
it "fails when external returns non 2xx", ->
|
||||
nock("https://www.google.com")
|
||||
.get("/")
|
||||
@@ -116,11 +131,11 @@ describe "lib/url_generator", ->
|
||||
|
||||
@sandbox.stub(fs, "readFile").returns(Promise.resolve(markdown))
|
||||
|
||||
urlGenerator.validateAndGetUrl(data, "and#notes", "", render)
|
||||
urlGenerator.validateAndGetUrl(data, "and#notes", "", "", render)
|
||||
.then (pathToFile) ->
|
||||
expect(pathToFile).to.eq("/api/commands/and.html#notes")
|
||||
|
||||
urlGenerator.validateAndGetUrl(data, "and#notes", "", render)
|
||||
urlGenerator.validateAndGetUrl(data, "and#notes", "", "", render)
|
||||
.then (pathToFile) ->
|
||||
expect(pathToFile).to.eq("/api/commands/and.html#notes")
|
||||
|
||||
@@ -164,7 +179,7 @@ describe "lib/url_generator", ->
|
||||
|
||||
@sandbox.stub(fs, "readFile").returns(Promise.resolve(""))
|
||||
|
||||
urlGenerator.validateAndGetUrl(data, "and#foo", "guides/core-concepts/bar.md", render)
|
||||
urlGenerator.validateAndGetUrl(data, "and#foo", "guides/core-concepts/bar.md", "content", render)
|
||||
.then ->
|
||||
throw new Error("should have caught error")
|
||||
.catch (err) ->
|
||||
|
||||
Reference in New Issue
Block a user