assets.test.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import * as assert from 'node:assert/strict';
  2. import { describe, it, before, after } from 'node:test';
  3. import nodejs from '../dist/index.js';
  4. import { loadFixture } from './test-utils.js';
  5. import * as cheerio from 'cheerio';
  6. describe('Assets', () => {
  7. /** @type {import('./test-utils').Fixture} */
  8. let fixture;
  9. let devPreview;
  10. before(async () => {
  11. fixture = await loadFixture({
  12. root: './fixtures/image/',
  13. output: 'server',
  14. adapter: nodejs({ mode: 'standalone' }),
  15. vite: {
  16. build: {
  17. assetsInlineLimit: 0,
  18. },
  19. },
  20. });
  21. await fixture.build();
  22. devPreview = await fixture.preview();
  23. });
  24. after(async () => {
  25. await devPreview.stop();
  26. });
  27. it('Assets within the _astro folder should be given immutable headers', async () => {
  28. let response = await fixture.fetch('/text-file');
  29. let cacheControl = response.headers.get('cache-control');
  30. assert.equal(cacheControl, null);
  31. const html = await response.text();
  32. const $ = cheerio.load(html);
  33. // Fetch the asset
  34. const fileURL = $('a').attr('href');
  35. response = await fixture.fetch(fileURL);
  36. cacheControl = response.headers.get('cache-control');
  37. assert.equal(cacheControl, 'public, max-age=31536000, immutable');
  38. });
  39. });