-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error message for endpoint getStaticPaths with undefined value (
#6353) Co-authored-by: bluwy <[email protected]> Co-authored-by: wuls <[email protected]>
- Loading branch information
1 parent
328c671
commit 4bf87c6
Showing
9 changed files
with
135 additions
and
1 deletion.
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 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Throw better error when a dynamic endpoint without additional extensions is prerendered with `undefined` params. |
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,52 @@ | ||
import { expect } from 'chai'; | ||
import { load as cheerioLoad } from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Dynamic endpoint collision', () => { | ||
describe('build', () => { | ||
let fixture; | ||
let errorMsg; | ||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/dynamic-endpoint-collision/', | ||
}); | ||
try { | ||
await fixture.build(); | ||
} catch (error) { | ||
errorMsg = error; | ||
} | ||
}); | ||
|
||
it('throw error when dynamic endpoint has path collision', async () => { | ||
expect(errorMsg.errorCode).to.eq(3026); | ||
}); | ||
}); | ||
|
||
describe('dev', () => { | ||
let fixture; | ||
let devServer; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/dynamic-endpoint-collision/', | ||
}); | ||
|
||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
after(async () => { | ||
await devServer.stop(); | ||
}); | ||
|
||
it('throw error when dynamic endpoint has path collision', async () => { | ||
const html = await fixture.fetch('/api/catch').then((res) => res.text()); | ||
const $ = cheerioLoad(html); | ||
expect($('title').text()).to.equal('PrerenderDynamicEndpointPathCollide'); | ||
}); | ||
|
||
it("don't throw error when dynamic endpoint doesn't load the colliding path", async () => { | ||
const res = await fixture.fetch('/api/catch/one').then((r) => r.text()); | ||
expect(res).to.equal('{"slug":"one"}'); | ||
}); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/astro/test/fixtures/dynamic-endpoint-collision/astro.config.mjs
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 @@ | ||
import { defineConfig } from 'astro/config'; | ||
|
||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
|
||
}); |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/dynamic-endpoint-collision/package.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@test/dynamic-endpoint-collision", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/astro/test/fixtures/dynamic-endpoint-collision/src/pages/api/catch/[...slug].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,15 @@ | ||
import type { APIRoute } from "astro"; | ||
|
||
const slugs = ["one", undefined]; | ||
|
||
export const get: APIRoute = ({ params }) => { | ||
return { | ||
body: JSON.stringify({ | ||
slug: params.slug || "index", | ||
}), | ||
}; | ||
}; | ||
|
||
export function getStaticPaths() { | ||
return slugs.map((u) => ({ params: { slug: u } })); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.