Update tests for legacy build (#2746)

* move fast-build example into a test fixture for legacy build

* update tests for legacy build
This commit is contained in:
Fred K. Schott 2022-03-09 14:38:46 -08:00 committed by GitHub
parent c9d84af6b1
commit 2906110c04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 48 additions and 79 deletions

View file

@ -9,7 +9,6 @@
"@example/my-component": "0.0.1",
"@example/docs": "0.0.1",
"@example/env-vars": "0.0.1",
"@example/fast-build": "0.0.1",
"@example/framework-alpine": "0.0.1",
"@example/framework-lit": "0.0.1",
"@example/framework-multiple": "0.0.1",

View file

@ -1,2 +0,0 @@
# Expose Astro dependencies for `pnpm` users
shamefully-hoist=true

View file

@ -1,21 +0,0 @@
{
"name": "@example/fast-build",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "astro dev --experimental-static-build",
"start": "astro dev --experimental-static-build",
"build": "astro build --experimental-static-build",
"scan-build": "astro build",
"preview": "astro preview"
},
"devDependencies": {
"@astrojs/renderer-vue": "^0.4.0",
"@astrojs/renderer-preact": "^0.5.0",
"sass": "^1.49.8",
"astro": "^0.24.0-next.0",
"preact": "~10.6.5",
"unocss": "^0.15.5",
"vite-imagetools": "^4.0.1"
}
}

View file

@ -1,2 +0,0 @@
<div id="external-hoist"></div>
<script type="module" hoist src="/src/scripts/external-hoist"></script>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View file

@ -117,7 +117,6 @@ function resolveFlags(flags: Partial<Flags>): CLIFlags {
// eslint-disable-next-line no-console
console.warn(`Passing --experimental-static-build is no longer necessary and is now the default. The flag will be removed in a future version of Astro.`);
}
return {
projectRoot: typeof flags.projectRoot === 'string' ? flags.projectRoot : undefined,
site: typeof flags.site === 'string' ? flags.site : undefined,
@ -126,7 +125,6 @@ function resolveFlags(flags: Partial<Flags>): CLIFlags {
config: typeof flags.config === 'string' ? flags.config : undefined,
hostname: typeof flags.hostname === 'string' ? flags.hostname : undefined,
legacyBuild: typeof flags.legacyBuild === 'boolean' ? flags.legacyBuild : false,
experimentalStaticBuild: typeof flags.experimentalStaticBuild === 'boolean' ? flags.experimentalStaticBuild : true,
experimentalSsr: typeof flags.experimentalSsr === 'boolean' ? flags.experimentalSsr : false,
drafts: typeof flags.drafts === 'boolean' ? flags.drafts : false,
};
@ -140,11 +138,10 @@ function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags) {
if (typeof flags.site === 'string') astroConfig.buildOptions.site = flags.site;
if (typeof flags.port === 'number') astroConfig.devOptions.port = flags.port;
if (typeof flags.hostname === 'string') astroConfig.devOptions.hostname = flags.hostname;
if (typeof flags.experimentalStaticBuild === 'boolean') astroConfig.buildOptions.experimentalStaticBuild = flags.experimentalStaticBuild;
if (typeof flags.legacyBuild === 'boolean') astroConfig.buildOptions.legacyBuild = flags.legacyBuild;
if (typeof flags.experimentalSsr === 'boolean') {
astroConfig.buildOptions.experimentalSsr = flags.experimentalSsr;
if (flags.experimentalSsr) {
astroConfig.buildOptions.experimentalStaticBuild = true;
astroConfig.buildOptions.legacyBuild = false;
}
}

View file

@ -1,9 +1,4 @@
import { imagetools } from 'vite-imagetools';
// @ts-check
export default /** @type {import('astro').AstroUserConfig} */ ({
renderers: ['@astrojs/renderer-vue'],
vite: {
plugins: [imagetools()],
},
});

View file

@ -0,0 +1,10 @@
{
"name": "@astrojs/legacy-build",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/renderer-vue": "^0.4.0",
"astro": "workspace:*",
"preact": "~10.6.5"
}
}

View file

@ -2,9 +2,7 @@
import Greeting from '../components/Greeting.vue';
export async function getStaticPaths() {
const response = await fetch(`https://pokeapi.co/api/v2/pokemon?limit=2000`);
const result = await response.json();
const allPokemon = result.results;
const allPokemon = [{name: 'Charmander'}, {name: 'Charmander'}, {name: 'Charizard'}];
return allPokemon.map(pokemon => ({params: {pokemon: pokemon.name}, props: {pokemon}}));
}
---

View file

@ -1,11 +1,7 @@
---
import imgUrl from '../images/penguin.jpg';
import grayscaleUrl from '../images/random.jpg?grayscale=true';
import Greeting from '../components/Greeting.vue';
import Counter from '../components/Counter.vue';
// import { Code } from 'astro/components';
import InlineHoisted from '../components/InlineHoisted.astro';
import ExternalHoisted from '../components/ExternalHoisted.astro';
---
<html>
@ -29,12 +25,6 @@ import ExternalHoisted from '../components/ExternalHoisted.astro';
</style>
</head>
<body>
<section>
<h1>Images</h1>
<h2>Imported in JS</h2>
<img src={imgUrl} />
</section>
<section>
<h1>Component CSS</h1>
@ -43,14 +33,10 @@ import ExternalHoisted from '../components/ExternalHoisted.astro';
<section>
<h1>ImageTools</h1>
<img src={grayscaleUrl} />
</section>
<section>
<h1>Astro components</h1>
<!-- <Code lang="css" code={`body {
color: salmon;
}`} /> -->
</section>
<section>
@ -61,7 +47,6 @@ import ExternalHoisted from '../components/ExternalHoisted.astro';
<section>
<h1>Hoisted scripts</h1>
<InlineHoisted />
<ExternalHoisted />
</section>
<section class="define-vars">

View file

@ -0,0 +1,23 @@
import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
describe('Legacy Build', () => {
let fixture;
before(async () => {
fixture = await loadFixture({
projectRoot: './fixtures/legacy-build/',
});
await fixture.build({buildOptions: {legacyBuild: true}});
});
describe('build', () => {
it('is successful', async () => {
const html = await fixture.readFile(`/index.html`);
const $ = cheerio.load(html);
expect($('title').text()).to.equal('Demo app');
});
});
});

View file

@ -9,9 +9,7 @@ describe('Code component inside static build', () => {
fixture = await loadFixture({
projectRoot: './fixtures/static-build-code-component/',
renderers: [],
buildOptions: {
experimentalStaticBuild: true,
},
buildOptions: {},
});
await fixture.build();
});

View file

@ -13,9 +13,7 @@ describe('Static build - frameworks', () => {
fixture = await loadFixture({
projectRoot: './fixtures/static-build-frameworks/',
renderers: ['@astrojs/renderer-preact', '@astrojs/renderer-react'],
buildOptions: {
experimentalStaticBuild: true,
},
buildOptions: {},
});
await fixture.build();
});

View file

@ -14,7 +14,6 @@ describe("Static build - pageUrlFormat: 'file'", () => {
projectRoot: './fixtures/static-build-page-url-format/',
renderers: [],
buildOptions: {
experimentalStaticBuild: true,
site: 'http://example.com/subpath/',
pageUrlFormat: 'file',
},

View file

@ -14,7 +14,6 @@ describe('Static build', () => {
projectRoot: './fixtures/static build/',
renderers: ['@astrojs/renderer-preact'],
buildOptions: {
experimentalStaticBuild: true,
site: 'http://example.com/subpath/',
},
ssr: {

View file

@ -105,24 +105,6 @@ importers:
devDependencies:
astro: link:../../packages/astro
examples/fast-build:
specifiers:
'@astrojs/renderer-preact': ^0.5.0
'@astrojs/renderer-vue': ^0.4.0
astro: ^0.24.0-next.0
preact: ~10.6.5
sass: ^1.49.8
unocss: ^0.15.5
vite-imagetools: ^4.0.1
devDependencies:
'@astrojs/renderer-preact': link:../../packages/renderers/renderer-preact
'@astrojs/renderer-vue': link:../../packages/renderers/renderer-vue
astro: link:../../packages/astro
preact: 10.6.6
sass: 1.49.9
unocss: 0.15.6
vite-imagetools: 4.0.3
examples/framework-alpine:
specifiers:
astro: ^0.24.0-next.0
@ -815,6 +797,16 @@ importers:
dependencies:
astro: link:../../..
packages/astro/test/fixtures/legacy-build:
specifiers:
'@astrojs/renderer-vue': ^0.4.0
astro: workspace:*
preact: ~10.6.5
dependencies:
'@astrojs/renderer-vue': link:../../../../renderers/renderer-vue
astro: link:../../..
preact: 10.6.6
packages/astro/test/fixtures/lit-element:
specifiers:
'@astrojs/renderer-lit': workspace:*
@ -8005,6 +7997,7 @@ packages:
/preact/10.6.6:
resolution: {integrity: sha512-dgxpTFV2vs4vizwKohYKkk7g7rmp1wOOcfd4Tz3IB3Wi+ivZzsn/SpeKJhRENSE+n8sUfsAl4S3HiCVT923ABw==}
dev: false
/prebuild-install/7.0.1:
resolution: {integrity: sha512-QBSab31WqkyxpnMWQxubYAHR5S9B2+r81ucocew34Fkl98FhvKIF50jIJnNOBmAZfyNV7vE5T6gd3hTVWgY6tg==}