diff --git a/packages/astro/test/fixtures/preloading/package.json b/packages/astro/test/fixtures/preloading/package.json new file mode 100644 index 000000000..9c7b3abb8 --- /dev/null +++ b/packages/astro/test/fixtures/preloading/package.json @@ -0,0 +1,8 @@ +{ + "name": "@test/preloading", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/preloading/src/pages/module1.astro b/packages/astro/test/fixtures/preloading/src/pages/module1.astro new file mode 100644 index 000000000..aaadd9c98 --- /dev/null +++ b/packages/astro/test/fixtures/preloading/src/pages/module1.astro @@ -0,0 +1,5 @@ + +

\ No newline at end of file diff --git a/packages/astro/test/fixtures/preloading/src/pages/module2.astro b/packages/astro/test/fixtures/preloading/src/pages/module2.astro new file mode 100644 index 000000000..aaadd9c98 --- /dev/null +++ b/packages/astro/test/fixtures/preloading/src/pages/module2.astro @@ -0,0 +1,5 @@ + +

\ No newline at end of file diff --git a/packages/astro/test/fixtures/preloading/src/to-be-preloaded.js b/packages/astro/test/fixtures/preloading/src/to-be-preloaded.js new file mode 100644 index 000000000..551392a7b --- /dev/null +++ b/packages/astro/test/fixtures/preloading/src/to-be-preloaded.js @@ -0,0 +1 @@ +export const shared = {} diff --git a/packages/astro/test/preloading.test.js b/packages/astro/test/preloading.test.js new file mode 100644 index 000000000..a112ee930 --- /dev/null +++ b/packages/astro/test/preloading.test.js @@ -0,0 +1,23 @@ +import { expect } from 'chai'; +import { loadFixture } from './test-utils.js'; +import * as cheerio from 'cheerio'; + +describe('preloading', () => { + /** @type {import('./test-utils.js').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/preloading/', + }); + await fixture.build() + }); + + it('rendered page includes a link rel=modulepreload', async () => { + const html = await fixture.readFile('/module1/index.html'); + const $ = cheerio.load(html); + const link = $('link')[0]; + expect(link.attribs).to.deep.include({ rel: 'modulepreload' }); + expect(link.attribs.href).to.include('to-be-preloaded'); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4d662e17b..0cb79631e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3016,6 +3016,12 @@ importers: specifier: ^10.17.1 version: 10.17.1 + packages/astro/test/fixtures/preloading: + dependencies: + astro: + specifier: workspace:* + version: link:../../.. + packages/astro/test/fixtures/public-base-404: dependencies: astro: