hoisted-imports.test.js — astro Source File
Architecture documentation for hoisted-imports.test.js, a javascript file in the astro codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 988c9110_25aa_fa1e_cc16_f8dc772a72b6["hoisted-imports.test.js"] 0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"] 988c9110_25aa_fa1e_cc16_f8dc772a72b6 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15 dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"] 988c9110_25aa_fa1e_cc16_f8dc772a72b6 --> dd4f09ce_3fd7_8295_f616_8876cda4555c e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"] 988c9110_25aa_fa1e_cc16_f8dc772a72b6 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607 6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"] 988c9110_25aa_fa1e_cc16_f8dc772a72b6 --> 6b0635f9_51ea_77aa_767b_7857878e98a6 deb87372_5629_35f8_9a54_e755a08f776a["cheerio"] 988c9110_25aa_fa1e_cc16_f8dc772a72b6 --> deb87372_5629_35f8_9a54_e755a08f776a style 988c9110_25aa_fa1e_cc16_f8dc772a72b6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
describe('Hoisted Imports', () => {
let fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/hoisted-imports/',
});
});
async function getAllScriptText(page) {
const html = await fixture.readFile(page);
const $ = cheerio.load(html);
return $('script')
.map((_, el) => $(el).text())
.toArray()
.join('\n');
}
describe('build', () => {
before(async () => {
await fixture.build();
});
function expectScript(scripts, letter) {
const regex = new RegExp(`console.log\\(['"]${letter}['"]\\)`);
assert.match(scripts, regex, 'missing component ' + letter);
}
function expectNotScript(scripts, letter) {
const regex = new RegExp(`console.log\\(['"]${letter}['"]\\)`);
assert.doesNotMatch(scripts, regex, "shouldn't include component " + letter);
}
it('includes all imported scripts', async () => {
const scripts = await getAllScriptText('/all/index.html');
expectScript(scripts, 'A');
expectScript(scripts, 'B');
expectScript(scripts, 'C');
expectScript(scripts, 'D');
expectScript(scripts, 'E');
});
it('includes no scripts when none imported', async () => {
const scripts = await getAllScriptText('/none/index.html');
expectNotScript(scripts, 'A');
expectNotScript(scripts, 'B');
expectNotScript(scripts, 'C');
expectNotScript(scripts, 'D');
expectNotScript(scripts, 'E');
});
it('includes some scripts', async () => {
const scripts = await getAllScriptText('/some/index.html');
expectScript(scripts, 'A');
expectNotScript(scripts, 'B');
expectScript(scripts, 'C');
expectNotScript(scripts, 'D');
expectNotScript(scripts, 'E');
});
it('deduplicates already rendered scripts', async () => {
const scripts = await getAllScriptText('/dedupe/index.html');
expectScript(scripts, 'A');
const html = await fixture.readFile('/dedupe/index.html');
const $ = cheerio.load(html);
assert.equal($('script').length, 1);
});
it('does not inline if script is larger than vite.assetInlineLimit: 100', async () => {
const html = await fixture.readFile('/no-inline/index.html');
const $ = cheerio.load(html);
const scripts = $('script');
assert.equal(scripts.length, 1);
assert.ok(scripts[0].attribs.src);
});
it('does not inline if script it has shared chunks', async () => {
const html = await fixture.readFile('/no-inline-if-shared/index.html');
const $ = cheerio.load(html);
const scripts = $('script');
assert.equal(scripts.length, 2);
assert.ok(scripts[0].attribs.src);
assert.ok(scripts[1].attribs.src);
});
it('renders styles if imported from the script', async () => {
const html = await fixture.readFile('/script-import-style/index.html');
const $ = cheerio.load(html);
const styles = $('style');
assert.equal(styles.length, 1);
// There should be no script because it's empty (contains only CSS import)
const scripts = $('scripts');
assert.equal(scripts.length, 0);
});
});
});
Domain
Dependencies
- cheerio
- loadFixture
- node:test
- strict
- test-utils.js
Source
Frequently Asked Questions
What does hoisted-imports.test.js do?
hoisted-imports.test.js is a source file in the astro codebase, written in javascript. It belongs to the IntegrationAdapters domain.
What does hoisted-imports.test.js depend on?
hoisted-imports.test.js imports 5 module(s): cheerio, loadFixture, node:test, strict, test-utils.js.
Where is hoisted-imports.test.js in the architecture?
hoisted-imports.test.js is located at packages/astro/test/hoisted-imports.test.js (domain: IntegrationAdapters, directory: packages/astro/test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free