Skip to content

Commit

Permalink
Add tests for using buildConfig (withastro#2960)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Apr 1, 2022
1 parent 4f43f82 commit afa678d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
71 changes: 71 additions & 0 deletions test/ssr-adapter-build-config.test.js
Original file line number Diff line number Diff line change
@@ -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;
})
});
2 changes: 1 addition & 1 deletion test/ssr-api-route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit afa678d

Please sign in to comment.