Skip to content

Commit

Permalink
Update tests for legacy build (#2746)
Browse files Browse the repository at this point in the history
* move fast-build example into a test fixture for legacy build

* update tests for legacy build
  • Loading branch information
FredKSchott committed Mar 9, 2022
1 parent c9d84af commit 2906110
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 79 deletions.
1 change: 0 additions & 1 deletion .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions examples/fast-build/.npmrc

This file was deleted.

21 changes: 0 additions & 21 deletions examples/fast-build/package.json

This file was deleted.

2 changes: 0 additions & 2 deletions examples/fast-build/src/components/ExternalHoisted.astro

This file was deleted.

Binary file removed examples/fast-build/src/images/penguin.jpg
Binary file not shown.
Binary file removed examples/fast-build/src/images/random.jpg
Binary file not shown.
5 changes: 1 addition & 4 deletions packages/astro/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { imagetools } from 'vite-imagetools';

// @ts-check
export default /** @type {import('astro').AstroUserConfig} */ ({
renderers: ['@astrojs/renderer-vue'],
vite: {
plugins: [imagetools()],
},
});
10 changes: 10 additions & 0 deletions packages/astro/test/fixtures/legacy-build/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}}));
}
---
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand All @@ -61,7 +47,6 @@ import ExternalHoisted from '../components/ExternalHoisted.astro';
<section>
<h1>Hoisted scripts</h1>
<InlineHoisted />
<ExternalHoisted />
</section>

<section class="define-vars">
Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions packages/astro/test/legacy-build.test.js
Original file line number Diff line number Diff line change
@@ -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');
});

});
});
4 changes: 1 addition & 3 deletions packages/astro/test/static-build-code-component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
4 changes: 1 addition & 3 deletions packages/astro/test/static-build-frameworks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
1 change: 0 additions & 1 deletion packages/astro/test/static-build-page-url-format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe("Static build - pageUrlFormat: 'file'", () => {
projectRoot: './fixtures/static-build-page-url-format/',
renderers: [],
buildOptions: {
experimentalStaticBuild: true,
site: 'http:https://example.com/subpath/',
pageUrlFormat: 'file',
},
Expand Down
1 change: 0 additions & 1 deletion packages/astro/test/static-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('Static build', () => {
projectRoot: './fixtures/static build/',
renderers: ['@astrojs/renderer-preact'],
buildOptions: {
experimentalStaticBuild: true,
site: 'http:https://example.com/subpath/',
},
ssr: {
Expand Down
29 changes: 11 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2906110

Please sign in to comment.