From d7896263b7936de25e4302c9f179353bea4fd27c Mon Sep 17 00:00:00 2001 From: Tony Sullivan Date: Fri, 22 Apr 2022 17:59:20 +0000 Subject: [PATCH] Support custom svelte compiler options in @astrojs/svelte (#3181) * updating svelte integration to allow custom user config * test: adding a test to verify that svelte options are piped through the integration * updating the README with docs on overridding svelte options * chore: adding changeset * fix: copy/paste bug in test validation * removing temporary debug scripts --- test/fixtures/svelte-component/astro.config.mjs | 4 +++- test/fixtures/svelte-component/src/components/Custom.sve | 5 +++++ test/fixtures/svelte-component/src/pages/typescript.astro | 5 +++++ test/svelte-component.test.js | 7 +++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/svelte-component/src/components/Custom.sve diff --git a/test/fixtures/svelte-component/astro.config.mjs b/test/fixtures/svelte-component/astro.config.mjs index dbf6d6b8fa46..b1aeede15aac 100644 --- a/test/fixtures/svelte-component/astro.config.mjs +++ b/test/fixtures/svelte-component/astro.config.mjs @@ -3,5 +3,7 @@ import svelte from '@astrojs/svelte'; // https://astro.build/config export default defineConfig({ - integrations: [svelte()], + integrations: [svelte({ + extensions: ['.svelte', '.sve'] + })], }); \ No newline at end of file diff --git a/test/fixtures/svelte-component/src/components/Custom.sve b/test/fixtures/svelte-component/src/components/Custom.sve new file mode 100644 index 000000000000..f61026424e88 --- /dev/null +++ b/test/fixtures/svelte-component/src/components/Custom.sve @@ -0,0 +1,5 @@ + + +
{ message }
diff --git a/test/fixtures/svelte-component/src/pages/typescript.astro b/test/fixtures/svelte-component/src/pages/typescript.astro index d6b4167564d4..2de86df16cf1 100644 --- a/test/fixtures/svelte-component/src/pages/typescript.astro +++ b/test/fixtures/svelte-component/src/pages/typescript.astro @@ -1,5 +1,9 @@ --- import TypeScript from '../components/TypeScript.svelte' + +// Using a custom extension to verify svelte options +// in astro.config.mjs are passed properly to the svelte integration +import Custom from '../components/Custom.sve' --- @@ -20,6 +24,7 @@ import TypeScript from '../components/TypeScript.svelte'
+
diff --git a/test/svelte-component.test.js b/test/svelte-component.test.js index 36ba35b51beb..a68acd92432e 100644 --- a/test/svelte-component.test.js +++ b/test/svelte-component.test.js @@ -22,6 +22,13 @@ describe('Svelte component', () => { expect($('#svelte-ts').text()).to.equal('Hello, TypeScript'); }); + + it('Works with custom Svelte config', async () => { + const html = await fixture.readFile('/typescript/index.html'); + const $ = cheerio.load(html); + + expect($('#svelte-custom-ext').text()).to.equal('Hello, Custom Extensions'); + }); }); if (isWindows) return;