Skip to content

Commit

Permalink
Update tests for legacy build (withastro#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 f1e7093 commit 9a56e76
Show file tree
Hide file tree
Showing 16 changed files with 181 additions and 12 deletions.
5 changes: 1 addition & 4 deletions 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
4 changes: 4 additions & 0 deletions test/fixtures/legacy-build/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-check
export default /** @type {import('astro').AstroUserConfig} */ ({
renderers: ['@astrojs/renderer-vue'],
});
10 changes: 10 additions & 0 deletions 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"
}
}
24 changes: 24 additions & 0 deletions test/fixtures/legacy-build/src/components/Counter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<template>
<div id="vue" class="counter">
<button @click="subtract()">-</button>
<pre>{{ count }}</pre>
<button @click="add()">+</button>
</div>
</template>

<script>
import { ref } from 'vue';
export default {
setup() {
const count = ref(0);
const add = () => (count.value = count.value + 1);
const subtract = () => (count.value = count.value - 1);
return {
count,
add,
subtract,
};
},
};
</script>
20 changes: 20 additions & 0 deletions test/fixtures/legacy-build/src/components/Greeting.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script>
export default {
data() {
return {
greeting: 'Hello World!',
};
},
};
</script>

<template>
<p class="greeting">{{ greeting }}</p>
</template>

<style>
.greeting {
color: red;
font-weight: bold;
}
</style>
13 changes: 13 additions & 0 deletions test/fixtures/legacy-build/src/components/InlineHoisted.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script type="module" hoist>
import { h, render } from 'preact';


const mount = document.querySelector('#inline-hoist');

function App() {
return h('strong', null, 'Hello again');
}

render(h(App), mount);
</script>
<div id="inline-hoist"></div>
18 changes: 18 additions & 0 deletions test/fixtures/legacy-build/src/pages/[pokemon].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
import Greeting from '../components/Greeting.vue';
export async function getStaticPaths() {
const allPokemon = [{name: 'Charmander'}, {name: 'Charmander'}, {name: 'Charizard'}];
return allPokemon.map(pokemon => ({params: {pokemon: pokemon.name}, props: {pokemon}}));
}
---
<html lang="en">
<head>
<title>Hello</title>
</head>

<body>
<h1>{Astro.props.pokemon.name}</h1>
<Greeting client:load />
</body>
</html>
60 changes: 60 additions & 0 deletions test/fixtures/legacy-build/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
import Greeting from '../components/Greeting.vue';
import Counter from '../components/Counter.vue';
import InlineHoisted from '../components/InlineHoisted.astro';
---

<html>
<head>
<title>Demo app</title>
<style>
h1 {
color: salmon;
}
</style>
<style lang="scss">
@import "../styles/_global.scss";
h2 {
color: $color;
}
</style>
<style define:vars={{ color: 'blue' }}>
.define-vars h1 {
color: var(--color);
}
</style>
</head>
<body>

<section>
<h1>Component CSS</h1>
<Greeting />
</section>

<section>
<h1>ImageTools</h1>
</section>

<section>
<h1>Astro components</h1>
</section>

<section>
<h1>Hydrated component</h1>
<Counter client:idle />
</section>

<section>
<h1>Hoisted scripts</h1>
<InlineHoisted />
</section>

<section class="define-vars">
<h1>define:vars</h1>
<h2></h2>
<script define:vars={{ color: 'blue' }}>
document.querySelector('.define-vars h2').textContent = `Color: ${color}`;
</script>
</section>
</body>
</html>
2 changes: 2 additions & 0 deletions test/fixtures/legacy-build/src/scripts/external-hoist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const el = document.querySelector('#external-hoist');
el.textContent = `This was loaded externally`;
1 change: 1 addition & 0 deletions test/fixtures/legacy-build/src/styles/_global.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$color: tan;
3 changes: 3 additions & 0 deletions test/fixtures/legacy-build/src/styles/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: lightcoral;
}
23 changes: 23 additions & 0 deletions 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 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 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 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 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

0 comments on commit 9a56e76

Please sign in to comment.