summaryrefslogtreecommitdiff
path: root/packages/astro/test/routing-priority.test.js
diff options
context:
space:
mode:
authorGravatar Bjorn Lu <bjornlu.dev@gmail.com> 2022-10-18 13:16:24 +0800
committerGravatar GitHub <noreply@github.com> 2022-10-18 13:16:24 +0800
commitef0c5431631665c9f6648ee5daee65a3ebf8e9ee (patch)
treee2539735a29b9e60f8d70c4ecfb2c5e3172322e6 /packages/astro/test/routing-priority.test.js
parent0edfdd325932b0b493b2228e3a121d217c38a727 (diff)
downloadastro-ef0c5431631665c9f6648ee5daee65a3ebf8e9ee.tar.gz
astro-ef0c5431631665c9f6648ee5daee65a3ebf8e9ee.tar.zst
astro-ef0c5431631665c9f6648ee5daee65a3ebf8e9ee.zip
Support spread parameters for server endpoints (#5106)
Diffstat (limited to '')
-rw-r--r--packages/astro/test/routing-priority.test.js60
1 files changed, 53 insertions, 7 deletions
diff --git a/packages/astro/test/routing-priority.test.js b/packages/astro/test/routing-priority.test.js
index dba4094a2..586978d4f 100644
--- a/packages/astro/test/routing-priority.test.js
+++ b/packages/astro/test/routing-priority.test.js
@@ -106,6 +106,21 @@ const routes = [
url: '/empty-slug/undefined',
fourOhFour: true,
},
+ {
+ description: 'matches /api/catch/a.json to api/catch/[...slug].json.ts',
+ url: '/api/catch/a.json',
+ htmlMatch: JSON.stringify({ path: 'a' }),
+ },
+ {
+ description: 'matches /api/catch/b/c.json to api/catch/[...slug].json.ts',
+ url: '/api/catch/b/c.json',
+ htmlMatch: JSON.stringify({ path: 'b/c' }),
+ },
+ {
+ description: 'matches /api/catch/a-b.json to api/catch/[foo]-[bar].json.ts',
+ url: '/api/catch/a-b.json',
+ htmlMatch: JSON.stringify({ foo: 'a', bar: 'b' }),
+ },
];
function appendForwardSlash(path) {
@@ -123,9 +138,11 @@ describe('Routing priority', () => {
await fixture.build();
});
- routes.forEach(({ description, url, fourOhFour, h1, p }) => {
+ routes.forEach(({ description, url, fourOhFour, h1, p, htmlMatch }) => {
+ const isEndpoint = htmlMatch && !h1 && !p;
+
it(description, async () => {
- const htmlFile = `${appendForwardSlash(url)}index.html`;
+ const htmlFile = isEndpoint ? url : `${appendForwardSlash(url)}index.html`;
if (fourOhFour) {
expect(fixture.pathExists(htmlFile)).to.be.false;
@@ -135,11 +152,17 @@ describe('Routing priority', () => {
const html = await fixture.readFile(htmlFile);
const $ = cheerioLoad(html);
- expect($('h1').text()).to.equal(h1);
+ if (h1) {
+ expect($('h1').text()).to.equal(h1);
+ }
if (p) {
expect($('p').text()).to.equal(p);
}
+
+ if (htmlMatch) {
+ expect(html).to.equal(htmlMatch);
+ }
});
});
});
@@ -160,7 +183,9 @@ describe('Routing priority', () => {
await devServer.stop();
});
- routes.forEach(({ description, url, fourOhFour, h1, p }) => {
+ routes.forEach(({ description, url, fourOhFour, h1, p, htmlMatch }) => {
+ const isEndpoint = htmlMatch && !h1 && !p;
+
// checks URLs as written above
it(description, async () => {
const html = await fixture.fetch(url).then((res) => res.text());
@@ -171,13 +196,22 @@ describe('Routing priority', () => {
return;
}
- expect($('h1').text()).to.equal(h1);
+ if (h1) {
+ expect($('h1').text()).to.equal(h1);
+ }
if (p) {
expect($('p').text()).to.equal(p);
}
+
+ if (htmlMatch) {
+ expect(html).to.equal(htmlMatch);
+ }
});
+ // skip for endpoint page test
+ if (isEndpoint) return;
+
// checks with trailing slashes, ex: '/de/' instead of '/de'
it(`${description} (trailing slash)`, async () => {
const html = await fixture.fetch(appendForwardSlash(url)).then((res) => res.text());
@@ -188,11 +222,17 @@ describe('Routing priority', () => {
return;
}
- expect($('h1').text()).to.equal(h1);
+ if (h1) {
+ expect($('h1').text()).to.equal(h1);
+ }
if (p) {
expect($('p').text()).to.equal(p);
}
+
+ if (htmlMatch) {
+ expect(html).to.equal(htmlMatch);
+ }
});
// checks with index.html, ex: '/de/index.html' instead of '/de'
@@ -207,11 +247,17 @@ describe('Routing priority', () => {
return;
}
- expect($('h1').text()).to.equal(h1);
+ if (h1) {
+ expect($('h1').text()).to.equal(h1);
+ }
if (p) {
expect($('p').text()).to.equal(p);
}
+
+ if (htmlMatch) {
+ expect(html).to.equal(htmlMatch);
+ }
});
});
});