2024-02-13 08:23:07 -05:00
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { describe, it } from 'node:test';
|
2023-08-01 18:06:50 -05:00
|
|
|
import { loadFixture } from './test-utils.js';
|
|
|
|
|
|
|
|
describe('Static Assets', () => {
|
|
|
|
/** @type {import('../../../astro/test/test-utils.js').Fixture} */
|
|
|
|
let fixture;
|
|
|
|
|
|
|
|
const VALID_CACHE_CONTROL = 'public, max-age=31536000, immutable';
|
|
|
|
|
2023-11-07 09:01:04 -05:00
|
|
|
async function build({ adapter, assets, output }) {
|
2023-08-01 18:06:50 -05:00
|
|
|
fixture = await loadFixture({
|
|
|
|
root: './fixtures/static-assets/',
|
2023-11-07 09:01:04 -05:00
|
|
|
output,
|
2023-08-01 18:06:50 -05:00
|
|
|
adapter,
|
|
|
|
build: {
|
|
|
|
assets,
|
2023-08-01 18:09:10 -05:00
|
|
|
},
|
2023-08-01 18:06:50 -05:00
|
|
|
});
|
|
|
|
await fixture.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getConfig() {
|
|
|
|
const json = await fixture.readFile('../.vercel/output/config.json');
|
|
|
|
const config = JSON.parse(json);
|
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getAssets() {
|
|
|
|
return fixture.config.build.assets;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function checkValidCacheControl(assets) {
|
|
|
|
const config = await getConfig();
|
2024-02-13 08:23:07 -05:00
|
|
|
const theAssets = assets ?? (await getAssets());
|
2023-08-01 18:06:50 -05:00
|
|
|
|
2024-02-13 08:23:07 -05:00
|
|
|
const route = config.routes.find((r) => r.src === `^/${theAssets}/(.*)$`);
|
|
|
|
assert.equal(route.headers['cache-control'], VALID_CACHE_CONTROL);
|
|
|
|
assert.equal(route.continue, true);
|
2023-08-01 18:06:50 -05:00
|
|
|
}
|
|
|
|
|
2024-02-13 08:23:07 -05:00
|
|
|
describe('static adapter', () => {
|
2023-08-01 18:06:50 -05:00
|
|
|
it('has cache control', async () => {
|
2024-02-13 08:23:07 -05:00
|
|
|
const { default: vercel } = await import('@astrojs/vercel/static');
|
2023-11-07 09:01:04 -05:00
|
|
|
await build({ adapter: vercel() });
|
2024-02-13 08:23:07 -05:00
|
|
|
await checkValidCacheControl();
|
2023-08-01 18:06:50 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('has cache control other assets', async () => {
|
2024-02-13 08:23:07 -05:00
|
|
|
const { default: vercel } = await import('@astrojs/vercel/static');
|
2023-08-01 18:06:50 -05:00
|
|
|
const assets = '_foo';
|
2023-11-07 09:01:04 -05:00
|
|
|
await build({ adapter: vercel(), assets });
|
2024-02-13 08:23:07 -05:00
|
|
|
await checkValidCacheControl(assets);
|
2023-08-01 18:06:50 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-02-13 08:23:07 -05:00
|
|
|
describe('serverless adapter', () => {
|
2023-08-01 18:06:50 -05:00
|
|
|
it('has cache control', async () => {
|
2024-02-13 08:23:07 -05:00
|
|
|
const { default: vercel } = await import('@astrojs/vercel/serverless');
|
2023-11-07 09:03:45 -05:00
|
|
|
await build({ output: 'server', adapter: vercel() });
|
2024-02-13 08:23:07 -05:00
|
|
|
await checkValidCacheControl();
|
2023-08-01 18:06:50 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('has cache control other assets', async () => {
|
2024-02-13 08:23:07 -05:00
|
|
|
const { default: vercel } = await import('@astrojs/vercel/serverless');
|
2023-08-01 18:06:50 -05:00
|
|
|
const assets = '_foo';
|
2023-11-07 09:03:45 -05:00
|
|
|
await build({ output: 'server', adapter: vercel(), assets });
|
2024-02-13 08:23:07 -05:00
|
|
|
await checkValidCacheControl(assets);
|
2023-08-01 18:06:50 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|