diff options
author | 2022-06-22 12:02:42 -0400 | |
---|---|---|
committer | 2022-06-22 12:02:42 -0400 | |
commit | aeab890971e5f425f877545c674d1cb532cee754 (patch) | |
tree | 594679ebb346a1ec9f1c196ae5630881a822c7bd /packages/astro/test/astro-scripts.test.js | |
parent | ae7415612ed8f644b90a23c16843a8205cc1933b (diff) | |
download | astro-aeab890971e5f425f877545c674d1cb532cee754.tar.gz astro-aeab890971e5f425f877545c674d1cb532cee754.tar.zst astro-aeab890971e5f425f877545c674d1cb532cee754.zip |
Inline small hoisted scripts (#3658)
* Inline small hoisted scripts
This makes it so that small hoisted scripts get inlined into the page rather than be fetched externally.
* Ensure we don't inline when there are imports
* Fix ts
* Update tests with new url structure
* Adds a changeset
Diffstat (limited to '')
-rw-r--r-- | packages/astro/test/astro-scripts.test.js | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/packages/astro/test/astro-scripts.test.js b/packages/astro/test/astro-scripts.test.js index 90dba2997..79fff798e 100644 --- a/packages/astro/test/astro-scripts.test.js +++ b/packages/astro/test/astro-scripts.test.js @@ -37,15 +37,16 @@ describe('Scripts (hoisted and not)', () => { // Inline page let inline = await fixture.readFile('/inline/index.html'); let $ = cheerio.load(inline); + let $el = $('script'); // test 1: Just one entry module - expect($('script')).to.have.lengthOf(1); + expect($el).to.have.lengthOf(1); // test 2: attr removed - expect($('script').attr('data-astro')).to.equal(undefined); + expect($el.attr('data-astro')).to.equal(undefined); - const entryURL = $('script').attr('src'); - const inlineEntryJS = await fixture.readFile(entryURL); + expect($el.attr('src')).to.equal(undefined); + const inlineEntryJS = $el.text(); // test 3: the JS exists expect(inlineEntryJS).to.be.ok; @@ -57,6 +58,14 @@ describe('Scripts (hoisted and not)', () => { ); }); + it('Inline scripts that are shared by multiple pages create chunks, and aren\'t inlined into the HTML', async () => { + let html = await fixture.readFile('/inline-shared-one/index.html'); + let $ = cheerio.load(html); + + expect($('script')).to.have.lengthOf(1); + expect($('script').attr('src')).to.not.equal(undefined); + }); + it('External page builds the hoisted scripts to a single bundle', async () => { let external = await fixture.readFile('/external/index.html'); let $ = cheerio.load(external); @@ -65,8 +74,8 @@ describe('Scripts (hoisted and not)', () => { expect($('script')).to.have.lengthOf(2); let el = $('script').get(1); - let entryURL = $(el).attr('src'); - let externalEntryJS = await fixture.readFile(entryURL); + expect($(el).attr('src')).to.equal(undefined, 'This should have been inlined'); + let externalEntryJS = $(el).text(); // test 2: the JS exists expect(externalEntryJS).to.be.ok; |