From 7c28dee7e9e17b6184586357c15dfc86db0279d6 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Mon, 28 Feb 2022 10:27:46 -0500 Subject: [PATCH 1/7] Move some tests over to the static build --- packages/astro/test/astro-assets.test.js | 3 +- packages/astro/test/astro-basic.test.js | 1 - packages/astro/test/astro-client-only.test.js | 1 - packages/astro/test/astro-components.test.js | 56 ------------------- packages/astro/test/astro-dynamic.test.js | 3 +- .../src/components/Component.astro | 11 ---- .../src/components/Component.jsx | 5 -- .../src/components/Component.svelte | 3 - .../src/components/Component.vue | 9 --- .../src/components/Props-Component.astro | 6 -- .../astro-components/src/pages/client.astro | 9 --- .../src/pages/frontmatter-component.astro | 6 -- .../astro-components/src/pages/index.astro | 9 --- .../src/pages/props-shadowing.astro | 4 -- .../src/pages/undefined-component.astro | 11 ---- 15 files changed, 2 insertions(+), 135 deletions(-) delete mode 100644 packages/astro/test/astro-components.test.js delete mode 100644 packages/astro/test/fixtures/astro-components/src/components/Component.astro delete mode 100644 packages/astro/test/fixtures/astro-components/src/components/Component.jsx delete mode 100644 packages/astro/test/fixtures/astro-components/src/components/Component.svelte delete mode 100644 packages/astro/test/fixtures/astro-components/src/components/Component.vue delete mode 100644 packages/astro/test/fixtures/astro-components/src/components/Props-Component.astro delete mode 100644 packages/astro/test/fixtures/astro-components/src/pages/client.astro delete mode 100644 packages/astro/test/fixtures/astro-components/src/pages/frontmatter-component.astro delete mode 100644 packages/astro/test/fixtures/astro-components/src/pages/index.astro delete mode 100644 packages/astro/test/fixtures/astro-components/src/pages/props-shadowing.astro delete mode 100644 packages/astro/test/fixtures/astro-components/src/pages/undefined-component.astro diff --git a/packages/astro/test/astro-assets.test.js b/packages/astro/test/astro-assets.test.js index b80e4d114437..d73451f9ff76 100644 --- a/packages/astro/test/astro-assets.test.js +++ b/packages/astro/test/astro-assets.test.js @@ -12,8 +12,7 @@ describe('Assets', () => { before(async () => { fixture = await loadFixture({ - projectRoot: './fixtures/astro-assets/', - buildOptions: { legacyBuild: true } // TODO make this test work without legacyBuild + projectRoot: './fixtures/astro-assets/' }); await fixture.build(); }); diff --git a/packages/astro/test/astro-basic.test.js b/packages/astro/test/astro-basic.test.js index 10904b09b101..eab0a077ecab 100644 --- a/packages/astro/test/astro-basic.test.js +++ b/packages/astro/test/astro-basic.test.js @@ -9,7 +9,6 @@ describe('Astro basics', () => { before(async () => { fixture = await loadFixture({ projectRoot: './fixtures/astro-basic/', - buildOptions: { legacyBuild: true } // TODO make this test work without legacyBuild }); await fixture.build(); previewServer = await fixture.preview(); diff --git a/packages/astro/test/astro-client-only.test.js b/packages/astro/test/astro-client-only.test.js index 3f3766652065..e5b0710f511b 100644 --- a/packages/astro/test/astro-client-only.test.js +++ b/packages/astro/test/astro-client-only.test.js @@ -8,7 +8,6 @@ describe('Client only components', () => { before(async () => { fixture = await loadFixture({ projectRoot: './fixtures/astro-client-only/', - buildOptions: { legacyBuild: true } // TODO make this test work without legacyBuild }); await fixture.build(); }); diff --git a/packages/astro/test/astro-components.test.js b/packages/astro/test/astro-components.test.js deleted file mode 100644 index f3a193ae757e..000000000000 --- a/packages/astro/test/astro-components.test.js +++ /dev/null @@ -1,56 +0,0 @@ -/** - * UNCOMMENT: add support for functional components in frontmatter -import { expect } from 'chai'; -import cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; - -let fixture; - -before(async () => { - fixture = await loadFixture({ projectRoot: './fixtures/astro-components/' }); - await fixture.build(); -}); - -// TODO: add support for functional components in frontmatter -describe('Components tests', () => { - it('Astro components are able to render framework components', async () => { - const html = await fixture.readFile('/index.html'); - const $ = cheerio.load(html); - - // test 1: Renders Astro component - const $astro = $('#astro'); - expect($astro.children()).to.have.lengthOf(3); - - // test 2: Renders React component - const $react = $('#react'); - expect($react).not.to.have.lengthOf(0); - - // test 3: Renders Vue component - const $vue = $('#vue'); - expect($vue).not.to.have.lengthOf(0); - - // test 4: Renders Svelte component - const $svelte = $('#svelte'); - expect($svelte).not.to.have.lengthOf(0); - }); - - it('Allows Components defined in frontmatter', async () => { - const html = await fixture.readFile('/frontmatter-component/index.html'); - const $ = cheerio.load(html); - - expect($('h1')).to.have.lengthOf(1); - }); - - it('Still throws an error for undefined components', async () => { - const result = await fixture.readFile('/undefined-component/index.html'); - expect(result.status).to.equal(500); - }); - - it('Client attrs not added', async () => { - const html = await fixture.readFile('/client/index.html'); - expect(html).not.to.include(`"client:load": true`); - }); -}); -*/ - -it.skip('is skipped', () => {}); diff --git a/packages/astro/test/astro-dynamic.test.js b/packages/astro/test/astro-dynamic.test.js index 229625ed123e..c02c2a6e280d 100644 --- a/packages/astro/test/astro-dynamic.test.js +++ b/packages/astro/test/astro-dynamic.test.js @@ -7,8 +7,7 @@ describe('Dynamic components', () => { before(async () => { fixture = await loadFixture({ - projectRoot: './fixtures/astro-dynamic/', - buildOptions: { legacyBuild: true } // TODO make this test work without legacyBuild + projectRoot: './fixtures/astro-dynamic/' }); await fixture.build(); }); diff --git a/packages/astro/test/fixtures/astro-components/src/components/Component.astro b/packages/astro/test/fixtures/astro-components/src/components/Component.astro deleted file mode 100644 index 36dec11a2562..000000000000 --- a/packages/astro/test/fixtures/astro-components/src/components/Component.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- -import ReactComponent from './Component.jsx'; -import VueComponent from './Component.vue'; -import SvelteComponent from './Component.svelte'; ---- - -
- - - -
diff --git a/packages/astro/test/fixtures/astro-components/src/components/Component.jsx b/packages/astro/test/fixtures/astro-components/src/components/Component.jsx deleted file mode 100644 index f251761923bb..000000000000 --- a/packages/astro/test/fixtures/astro-components/src/components/Component.jsx +++ /dev/null @@ -1,5 +0,0 @@ -import { h } from 'preact'; - -export default function PreactComponent({ children }) { - return
{children}
; -} diff --git a/packages/astro/test/fixtures/astro-components/src/components/Component.svelte b/packages/astro/test/fixtures/astro-components/src/components/Component.svelte deleted file mode 100644 index 4276a78b80f0..000000000000 --- a/packages/astro/test/fixtures/astro-components/src/components/Component.svelte +++ /dev/null @@ -1,3 +0,0 @@ -
- -
diff --git a/packages/astro/test/fixtures/astro-components/src/components/Component.vue b/packages/astro/test/fixtures/astro-components/src/components/Component.vue deleted file mode 100644 index 22e6e11433bb..000000000000 --- a/packages/astro/test/fixtures/astro-components/src/components/Component.vue +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/packages/astro/test/fixtures/astro-components/src/components/Props-Component.astro b/packages/astro/test/fixtures/astro-components/src/components/Props-Component.astro deleted file mode 100644 index 5c32430f0dd1..000000000000 --- a/packages/astro/test/fixtures/astro-components/src/components/Props-Component.astro +++ /dev/null @@ -1,6 +0,0 @@ ---- -export interface Props { - test: string; -} ---- -

{props.test}

diff --git a/packages/astro/test/fixtures/astro-components/src/pages/client.astro b/packages/astro/test/fixtures/astro-components/src/pages/client.astro deleted file mode 100644 index eb1c2abf2247..000000000000 --- a/packages/astro/test/fixtures/astro-components/src/pages/client.astro +++ /dev/null @@ -1,9 +0,0 @@ ---- -import SvelteComponent from '../components/Component.svelte'; ---- - -Components - - - - diff --git a/packages/astro/test/fixtures/astro-components/src/pages/frontmatter-component.astro b/packages/astro/test/fixtures/astro-components/src/pages/frontmatter-component.astro deleted file mode 100644 index 69f7085051db..000000000000 --- a/packages/astro/test/fixtures/astro-components/src/pages/frontmatter-component.astro +++ /dev/null @@ -1,6 +0,0 @@ ---- -const { level = 1 } = Astro.props; -const Element = `h${level}`; ---- - -Hello world! diff --git a/packages/astro/test/fixtures/astro-components/src/pages/index.astro b/packages/astro/test/fixtures/astro-components/src/pages/index.astro deleted file mode 100644 index 4cadb30e67fb..000000000000 --- a/packages/astro/test/fixtures/astro-components/src/pages/index.astro +++ /dev/null @@ -1,9 +0,0 @@ ---- -import AstroComponent from '../components/Component.astro'; ---- - -Components - - - - diff --git a/packages/astro/test/fixtures/astro-components/src/pages/props-shadowing.astro b/packages/astro/test/fixtures/astro-components/src/pages/props-shadowing.astro deleted file mode 100644 index 3704933f25c6..000000000000 --- a/packages/astro/test/fixtures/astro-components/src/pages/props-shadowing.astro +++ /dev/null @@ -1,4 +0,0 @@ ---- -import PropsComponent from "../components/Props-Component.astro" ---- - diff --git a/packages/astro/test/fixtures/astro-components/src/pages/undefined-component.astro b/packages/astro/test/fixtures/astro-components/src/pages/undefined-component.astro deleted file mode 100644 index bdf9424bc455..000000000000 --- a/packages/astro/test/fixtures/astro-components/src/pages/undefined-component.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- -function FnComponent() { - const lame = 'ugh'; - return

Hey

-} -const Defined = 'h1' ---- - - -Hello world! - From 28a16f8819991e970523ea9c407604b0ef33de54 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Mon, 28 Feb 2022 10:40:10 -0500 Subject: [PATCH 2/7] Fix assets tests --- packages/astro/src/core/build/static-build.ts | 1 + packages/astro/test/astro-assets.test.js | 17 +++++++++++------ .../fixtures/astro-assets/src/pages/index.astro | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index f8253f36fa04..6a3e4df27f1a 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -181,6 +181,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp logLevel: 'error', mode: 'production', build: { + ...viteConfig.build, emptyOutDir: false, manifest: ssr, minify: false, diff --git a/packages/astro/test/astro-assets.test.js b/packages/astro/test/astro-assets.test.js index d73451f9ff76..9905ff27de91 100644 --- a/packages/astro/test/astro-assets.test.js +++ b/packages/astro/test/astro-assets.test.js @@ -12,7 +12,12 @@ describe('Assets', () => { before(async () => { fixture = await loadFixture({ - projectRoot: './fixtures/astro-assets/' + projectRoot: './fixtures/astro-assets/', + vite: { + build: { + assetsInlineLimit: 0 + } + } }); await fixture.build(); }); @@ -21,7 +26,7 @@ describe('Assets', () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); const imgPath = $('img').attr('src'); - const data = await fixture.readFile('/' + imgPath); + const data = await fixture.readFile( imgPath); expect(!!data).to.equal(true); }); @@ -31,7 +36,7 @@ describe('Assets', () => { const srcset = $('img').attr('srcset'); const candidates = matchSrcset(srcset); const match = candidates.find((a) => a.density === 2); - const data = await fixture.readFile('/' + match.url); + const data = await fixture.readFile(match.url); expect(!!data).to.equal(true); }); @@ -41,14 +46,14 @@ describe('Assets', () => { const srcset = $('img').attr('srcset'); const candidates = matchSrcset(srcset); const match = candidates.find((a) => a.density === 3); - const data = await fixture.readFile('/' + match.url); + const data = await fixture.readFile(match.url); expect(!!data).to.equal(true); }); it('built image from an import specifier', async () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); - const src = '/' + $('#import-no-url').attr('src'); + const src = $('#import-no-url').attr('src'); const data = await fixture.readFile(src); expect(!!data).to.equal(true); }); @@ -56,7 +61,7 @@ describe('Assets', () => { it('built image from an import specifier using ?url', async () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); - const src = '/' + $('#import-url').attr('src'); + const src = $('#import-url').attr('src'); const data = await fixture.readFile(src); expect(!!data).to.equal(true); }); diff --git a/packages/astro/test/fixtures/astro-assets/src/pages/index.astro b/packages/astro/test/fixtures/astro-assets/src/pages/index.astro index b509f3fb955e..341f2744c592 100644 --- a/packages/astro/test/fixtures/astro-assets/src/pages/index.astro +++ b/packages/astro/test/fixtures/astro-assets/src/pages/index.astro @@ -9,7 +9,7 @@ import p2Url from '../images/penguin2.jpg?url';

Icons

- +