This commit is contained in:
lilnasy 2023-10-11 01:15:00 +00:00
parent 4eeca70fc6
commit 44c89b17e0
No known key found for this signature in database
GPG key ID: B09B8AE8D3751F1F
6 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,8 @@
{
"name": "@test/preloading",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,5 @@
<script>
import { shared } from "../to-be-preloaded.js"
console.log(shared)
</script>
<p></p>

View file

@ -0,0 +1,5 @@
<script>
import { shared } from "../to-be-preloaded.js"
console.log(shared)
</script>
<p></p>

View file

@ -0,0 +1 @@
export const shared = {}

View file

@ -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');
});
});

View file

@ -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: