Add tests for using buildConfig (#2960)

This commit is contained in:
Matthew Phillips 2022-04-01 13:32:22 -04:00 committed by GitHub
parent 645e1f2ac9
commit b4ad11b569
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 1 deletions

View file

@ -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;
})
});

View file

@ -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();