mirror of
https://github.com/withastro/astro.git
synced 2025-04-07 23:41:43 -05:00
test: Ensure that when we build with server islands that the baseURL is added
This commit is contained in:
parent
d8f9f94233
commit
03b145bf2d
1 changed files with 103 additions and 0 deletions
|
@ -77,6 +77,61 @@ describe('Server islands', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('SSR (change base URL)', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
let fixture;
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/server-islands/ssr',
|
||||
adapter: testAdapter(),
|
||||
integrations: [
|
||||
{
|
||||
name: 'change-base-url',
|
||||
hooks: {
|
||||
'astro:config:setup': async ({ updateConfig, command }) => {
|
||||
if (command === 'build') {
|
||||
updateConfig({
|
||||
serverIslandDynamicBase: 'https://api.example.com',
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
describe('prod', () => {
|
||||
before(async () => {
|
||||
process.env.ASTRO_KEY = 'eKBaVEuI7YjfanEXHuJe/pwZKKt3LkAHeMxvTU7aR0M=';
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
delete process.env.ASTRO_KEY;
|
||||
});
|
||||
|
||||
it('server island script has base URL', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/');
|
||||
const response = await app.render(request);
|
||||
const html = await response.text();
|
||||
|
||||
const $ = cheerio.load(html);
|
||||
const serverIslandEl = $('h2#island');
|
||||
assert.equal(serverIslandEl.length, 0);
|
||||
|
||||
const serverIslandScript = $('script[data-island-id]');
|
||||
assert.equal(serverIslandScript.length, 1, 'has the island script');
|
||||
|
||||
assert.match(
|
||||
serverIslandScript.text(),
|
||||
/await fetch\('https:\/\/api.example.com\/_server-islands\//i,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Hybrid mode', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
let fixture;
|
||||
|
@ -118,4 +173,52 @@ describe('Server islands', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Hybrid mode (change base URL)', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
let fixture;
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/server-islands/hybrid',
|
||||
integrations: [
|
||||
{
|
||||
name: 'change-base-url',
|
||||
hooks: {
|
||||
'astro:config:setup': async ({ updateConfig, command }) => {
|
||||
if (command === 'build') {
|
||||
updateConfig({
|
||||
serverIslandDynamicBase: 'https://api.example.com',
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
describe('build', () => {
|
||||
before(async () => {
|
||||
await fixture.build({
|
||||
adapter: testAdapter(),
|
||||
});
|
||||
});
|
||||
|
||||
it('Omits the island HTML from the static HTML', async () => {
|
||||
let html = await fixture.readFile('/client/index.html');
|
||||
|
||||
const $ = cheerio.load(html);
|
||||
const serverIslandEl = $('h2#island');
|
||||
assert.equal(serverIslandEl.length, 0);
|
||||
|
||||
const serverIslandScript = $('script[data-island-id]');
|
||||
assert.equal(serverIslandScript.length, 1, 'has the island script');
|
||||
|
||||
assert.match(
|
||||
serverIslandScript.text(),
|
||||
/await fetch\('https:\/\/api.example.com\/_server-islands\//i,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue