summaryrefslogtreecommitdiff
path: root/packages/astro/test/astro-scripts.test.js
diff options
context:
space:
mode:
authorGravatar André Alves <71379045+andremralves@users.noreply.github.com> 2023-06-06 12:08:38 -0300
committerGravatar GitHub <noreply@github.com> 2023-06-06 10:08:38 -0500
commit144813f7308dcb9de64ebe3f0f2c6cba9ad81eb1 (patch)
treefcfeca039e2a222978ab0754e8640664baab8d16 /packages/astro/test/astro-scripts.test.js
parent67c8f34a99f3a50f7f402462bd5f74b477c8d663 (diff)
downloadastro-144813f7308dcb9de64ebe3f0f2c6cba9ad81eb1.tar.gz
astro-144813f7308dcb9de64ebe3f0f2c6cba9ad81eb1.tar.zst
astro-144813f7308dcb9de64ebe3f0f2c6cba9ad81eb1.zip
Fix injected scripts not injected to injected routes (#7262)
* Fix injected scripts not injected to injected routes * chore: changeset --------- Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
Diffstat (limited to 'packages/astro/test/astro-scripts.test.js')
-rw-r--r--packages/astro/test/astro-scripts.test.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/astro/test/astro-scripts.test.js b/packages/astro/test/astro-scripts.test.js
index 14b224a69..5420ec0f9 100644
--- a/packages/astro/test/astro-scripts.test.js
+++ b/packages/astro/test/astro-scripts.test.js
@@ -1,6 +1,7 @@
import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
+import { tailwind } from './fixtures/astro-scripts/deps.mjs';
describe('Scripts (hoisted and not)', () => {
describe('Build', () => {
@@ -139,6 +140,21 @@ describe('Scripts (hoisted and not)', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-scripts/',
+ integrations: [
+ tailwind(),
+ {
+ name: 'test-script-injection-with-injected-route',
+ hooks: {
+ 'astro:config:setup': ({ injectRoute, injectScript }) => {
+ injectScript(
+ 'page',
+ `import '/src/scripts/something.js';`
+ );
+ injectRoute({ pattern: 'injected-route', entryPoint: 'src/external-page.astro' });
+ },
+ },
+ }
+ ],
vite: {
build: {
assetsInlineLimit: 0,
@@ -182,5 +198,19 @@ describe('Scripts (hoisted and not)', () => {
});
expect(found).to.equal(1);
});
+
+ it('Injected scripts are injected to injected routes', async () => {
+ let res = await fixture.fetch('/injected-route');
+ let html = await res.text();
+ let $ = cheerio.load(html);
+ let found = 0;
+ let moduleScripts = $('[type=module]');
+ moduleScripts.each((i, el) => {
+ if ($(el).attr('src').includes('@id/astro:scripts/page.js')) {
+ found++;
+ }
+ });
+ expect(found).to.equal(1);
+ });
});
});