From b4ad11b5690f6835afbd6cd8efdb2d72fa6df9a0 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 1 Apr 2022 13:32:22 -0400 Subject: [PATCH] Add tests for using buildConfig (#2960) --- .../test/ssr-adapter-build-config.test.js | 71 +++++++++++++++++++ packages/astro/test/ssr-api-route.test.js | 2 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 packages/astro/test/ssr-adapter-build-config.test.js diff --git a/packages/astro/test/ssr-adapter-build-config.test.js b/packages/astro/test/ssr-adapter-build-config.test.js new file mode 100644 index 000000000..a6feab8cd --- /dev/null +++ b/packages/astro/test/ssr-adapter-build-config.test.js @@ -0,0 +1,71 @@ +import { expect } from 'chai'; +import { load as cheerioLoad } from 'cheerio'; +import { loadFixture } from './test-utils.js'; +import { viteID } from '../dist/core/util.js'; + +// Asset bundling +describe('Integration buildConfig hook', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + let _config; + fixture = await loadFixture({ + projectRoot: './fixtures/ssr-request/', + buildOptions: { + experimentalSsr: true, + }, + adapter: { + name: 'my-ssr-adapter', + hooks: { + 'astro:config:setup': ({ updateConfig }) => { + updateConfig({ + vite: { + plugins: [ + { + resolveId(id) { + if (id === '@my-ssr') { + return id; + } else if (id === 'astro/app') { + const id = viteID(new URL('../dist/core/app/index.js', import.meta.url)); + return id; + } + }, + load(id) { + if (id === '@my-ssr') { + return `import { App } from 'astro/app';export function createExports(manifest) { return { manifest, createApp: () => new App(manifest) }; }`; + } + }, + }, + ], + }, + }); + }, + 'astro:build:start': ({ buildConfig }) => { + buildConfig.server = new URL('./dist/.root/server/', _config.projectRoot); + buildConfig.client = new URL('./dist/.root/client/', _config.projectRoot); + }, + 'astro:config:done': ({ config, setAdapter }) => { + _config = config; + setAdapter({ + name: 'my-ssr-adapter', + serverEntrypoint: '@my-ssr', + exports: ['manifest', 'createApp'], + }); + }, + }, + }, + }); + await fixture.build(); + }); + + it('Puts client files in the client folder', async () => { + let data = await fixture.readFile('/.root/client/cars.json'); + expect(data).to.not.be.undefined; + }); + + it('Puts the server entry into the server folder', async () => { + let data = await fixture.readFile('/.root/server/entry.mjs'); + expect(data).to.not.be.undefined; + }) +}); diff --git a/packages/astro/test/ssr-api-route.test.js b/packages/astro/test/ssr-api-route.test.js index 6bf8fcd20..5ed37f0c5 100644 --- a/packages/astro/test/ssr-api-route.test.js +++ b/packages/astro/test/ssr-api-route.test.js @@ -35,7 +35,7 @@ describe('API routes in SSR', () => { expect(body.length).to.equal(3); }); - describe('Dev', () => { + describe('API Routes - Dev', () => { let devServer; before(async () => { devServer = await fixture.startDevServer();