diff options
author | 2023-09-06 06:43:53 +0200 | |
---|---|---|
committer | 2023-09-06 05:43:53 +0100 | |
commit | 9ffa1a84e81f52d55ffe07826b8b1f10fc023ee9 (patch) | |
tree | 00c13135d268e4705357a69b9949ae3d9c2340ed /packages/integrations/vercel/test | |
parent | 61ad70fdc52035964c43ecdb4cf7468f6c2b61e7 (diff) | |
download | astro-9ffa1a84e81f52d55ffe07826b8b1f10fc023ee9.tar.gz astro-9ffa1a84e81f52d55ffe07826b8b1f10fc023ee9.tar.zst astro-9ffa1a84e81f52d55ffe07826b8b1f10fc023ee9.zip |
fix: include route prefix in vercel func names, fix #8401 (#8408)
* fix: include route prefix in vercel func names
* chore: add changeset
* chore: update pnpm lockfile
* refactor: simplify logic that generates vercel func names
* fix: properly remove entryFile prefix from func name
* refactor: change how vercel function names are generated
---------
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
Diffstat (limited to 'packages/integrations/vercel/test')
7 files changed, 73 insertions, 0 deletions
diff --git a/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/astro.config.mjs b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/astro.config.mjs new file mode 100644 index 000000000..f5a86e609 --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/astro.config.mjs @@ -0,0 +1,10 @@ +import { defineConfig } from 'astro/config'; +import vercel from '@astrojs/vercel/serverless'; + +export default defineConfig({ + adapter: vercel({ + // Pass some value to make sure it doesn't error out + includeFiles: ['included.js'], + }), + output: 'server' +}); diff --git a/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/included.js b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/included.js new file mode 100644 index 000000000..4e64b2d61 --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/included.js @@ -0,0 +1 @@ +'works'
\ No newline at end of file diff --git a/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/package.json b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/package.json new file mode 100644 index 000000000..e22a7e932 --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/astro-vercel-serverless-with-dynamic-routes", + "version": "0.0.0", + "private": true, + "dependencies": { + "@astrojs/vercel": "workspace:*", + "astro": "workspace:*" + } +} diff --git a/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/src/pages/[id]/index.astro b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/src/pages/[id]/index.astro new file mode 100644 index 000000000..4eab5952d --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/src/pages/[id]/index.astro @@ -0,0 +1,12 @@ +--- +export const prerender = false; +--- + +<html> + <head> + <title>testing {Astro.params.id}</title> + </head> + <body> + <h1>testing {Astro.params.id}</h1> + </body> +</html> diff --git a/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/src/pages/api/[id].js b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/src/pages/api/[id].js new file mode 100644 index 000000000..f54e673a8 --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/src/pages/api/[id].js @@ -0,0 +1,7 @@ +export const prerender = false; + +export async function GET({ params }) { + return Response.json({ + id: params.id + }); +} diff --git a/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/src/pages/index.astro b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/src/pages/index.astro new file mode 100644 index 000000000..b6b833e53 --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/src/pages/index.astro @@ -0,0 +1,12 @@ +--- +export const prerender = import.meta.env.PRERENDER; +--- + +<html> + <head> + <title>testing</title> + </head> + <body> + <h1>testing</h1> + </body> +</html> diff --git a/packages/integrations/vercel/test/serverless-with-dynamic-routes.test.js b/packages/integrations/vercel/test/serverless-with-dynamic-routes.test.js new file mode 100644 index 000000000..325f9c5b0 --- /dev/null +++ b/packages/integrations/vercel/test/serverless-with-dynamic-routes.test.js @@ -0,0 +1,22 @@ +import { expect } from 'chai'; +import { loadFixture } from './test-utils.js'; + +describe('Serverless with dynamic routes', () => { + /** @type {import('./test-utils.js').Fixture} */ + let fixture; + + before(async () => { + process.env.PRERENDER = true; + fixture = await loadFixture({ + root: './fixtures/serverless-with-dynamic-routes/', + output: 'hybrid', + }); + await fixture.build(); + }); + + it('build successful', async () => { + expect(await fixture.readFile('../.vercel/output/static/index.html')).to.be.ok; + expect(await fixture.readFile('../.vercel/output/functions/[id]/index.astro.func/.vc-config.json')).to.be.ok; + expect(await fixture.readFile('../.vercel/output/functions/api/[id].js.func/.vc-config.json')).to.be.ok; + }); +}); |