From 9a56e76e129bfb6515cbcdef2b68459522fe690e Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Wed, 9 Mar 2022 14:38:46 -0800 Subject: [PATCH] Update tests for legacy build (#2746) * move fast-build example into a test fixture for legacy build * update tests for legacy build --- src/core/config.ts | 5 +- test/fixtures/legacy-build/astro.config.mjs | 4 ++ test/fixtures/legacy-build/package.json | 10 ++++ .../legacy-build/src/components/Counter.vue | 24 ++++++++ .../legacy-build/src/components/Greeting.vue | 20 +++++++ .../src/components/InlineHoisted.astro | 13 ++++ .../legacy-build/src/pages/[pokemon].astro | 18 ++++++ .../legacy-build/src/pages/index.astro | 60 +++++++++++++++++++ .../src/scripts/external-hoist.ts | 2 + .../legacy-build/src/styles/_global.scss | 1 + .../legacy-build/src/styles/global.css | 3 + test/legacy-build.test.js | 23 +++++++ test/static-build-code-component.test.js | 4 +- test/static-build-frameworks.test.js | 4 +- test/static-build-page-url-format.test.js | 1 - test/static-build.test.js | 1 - 16 files changed, 181 insertions(+), 12 deletions(-) create mode 100644 test/fixtures/legacy-build/astro.config.mjs create mode 100644 test/fixtures/legacy-build/package.json create mode 100644 test/fixtures/legacy-build/src/components/Counter.vue create mode 100644 test/fixtures/legacy-build/src/components/Greeting.vue create mode 100644 test/fixtures/legacy-build/src/components/InlineHoisted.astro create mode 100644 test/fixtures/legacy-build/src/pages/[pokemon].astro create mode 100644 test/fixtures/legacy-build/src/pages/index.astro create mode 100644 test/fixtures/legacy-build/src/scripts/external-hoist.ts create mode 100644 test/fixtures/legacy-build/src/styles/_global.scss create mode 100644 test/fixtures/legacy-build/src/styles/global.css create mode 100644 test/legacy-build.test.js diff --git a/src/core/config.ts b/src/core/config.ts index e2cccff41f98..5f5ca042e1c6 100644 --- a/src/core/config.ts +++ b/src/core/config.ts @@ -117,7 +117,6 @@ function resolveFlags(flags: Partial): 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): 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; } } diff --git a/test/fixtures/legacy-build/astro.config.mjs b/test/fixtures/legacy-build/astro.config.mjs new file mode 100644 index 000000000000..72cd775875f4 --- /dev/null +++ b/test/fixtures/legacy-build/astro.config.mjs @@ -0,0 +1,4 @@ +// @ts-check +export default /** @type {import('astro').AstroUserConfig} */ ({ + renderers: ['@astrojs/renderer-vue'], +}); diff --git a/test/fixtures/legacy-build/package.json b/test/fixtures/legacy-build/package.json new file mode 100644 index 000000000000..77f85d531eb1 --- /dev/null +++ b/test/fixtures/legacy-build/package.json @@ -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" + } +} diff --git a/test/fixtures/legacy-build/src/components/Counter.vue b/test/fixtures/legacy-build/src/components/Counter.vue new file mode 100644 index 000000000000..599bcf615f51 --- /dev/null +++ b/test/fixtures/legacy-build/src/components/Counter.vue @@ -0,0 +1,24 @@ + + + diff --git a/test/fixtures/legacy-build/src/components/Greeting.vue b/test/fixtures/legacy-build/src/components/Greeting.vue new file mode 100644 index 000000000000..a94f586bf8fb --- /dev/null +++ b/test/fixtures/legacy-build/src/components/Greeting.vue @@ -0,0 +1,20 @@ + + + + + diff --git a/test/fixtures/legacy-build/src/components/InlineHoisted.astro b/test/fixtures/legacy-build/src/components/InlineHoisted.astro new file mode 100644 index 000000000000..ba6c0ab4d4e0 --- /dev/null +++ b/test/fixtures/legacy-build/src/components/InlineHoisted.astro @@ -0,0 +1,13 @@ + +
diff --git a/test/fixtures/legacy-build/src/pages/[pokemon].astro b/test/fixtures/legacy-build/src/pages/[pokemon].astro new file mode 100644 index 000000000000..bb3372123533 --- /dev/null +++ b/test/fixtures/legacy-build/src/pages/[pokemon].astro @@ -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}})); +} +--- + + + Hello + + + +

{Astro.props.pokemon.name}

+ + + \ No newline at end of file diff --git a/test/fixtures/legacy-build/src/pages/index.astro b/test/fixtures/legacy-build/src/pages/index.astro new file mode 100644 index 000000000000..ef93bf5535d0 --- /dev/null +++ b/test/fixtures/legacy-build/src/pages/index.astro @@ -0,0 +1,60 @@ +--- +import Greeting from '../components/Greeting.vue'; +import Counter from '../components/Counter.vue'; +import InlineHoisted from '../components/InlineHoisted.astro'; +--- + + + + Demo app + + + + + + +
+

Component CSS

+ +
+ +
+

ImageTools

+
+ +
+

Astro components

+
+ +
+

Hydrated component

+ +
+ +
+

Hoisted scripts

+ +
+ +
+

define:vars

+

+ +
+ + diff --git a/test/fixtures/legacy-build/src/scripts/external-hoist.ts b/test/fixtures/legacy-build/src/scripts/external-hoist.ts new file mode 100644 index 000000000000..ff7ee0bcfd19 --- /dev/null +++ b/test/fixtures/legacy-build/src/scripts/external-hoist.ts @@ -0,0 +1,2 @@ +const el = document.querySelector('#external-hoist'); +el.textContent = `This was loaded externally`; diff --git a/test/fixtures/legacy-build/src/styles/_global.scss b/test/fixtures/legacy-build/src/styles/_global.scss new file mode 100644 index 000000000000..27620a7460f2 --- /dev/null +++ b/test/fixtures/legacy-build/src/styles/_global.scss @@ -0,0 +1 @@ +$color: tan; diff --git a/test/fixtures/legacy-build/src/styles/global.css b/test/fixtures/legacy-build/src/styles/global.css new file mode 100644 index 000000000000..ab5ca9bfe44e --- /dev/null +++ b/test/fixtures/legacy-build/src/styles/global.css @@ -0,0 +1,3 @@ +body { + background: lightcoral; +} diff --git a/test/legacy-build.test.js b/test/legacy-build.test.js new file mode 100644 index 000000000000..1b3224493a67 --- /dev/null +++ b/test/legacy-build.test.js @@ -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'); + }); + + }); +}); diff --git a/test/static-build-code-component.test.js b/test/static-build-code-component.test.js index c81a686e464f..4c712f2ab67b 100644 --- a/test/static-build-code-component.test.js +++ b/test/static-build-code-component.test.js @@ -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(); }); diff --git a/test/static-build-frameworks.test.js b/test/static-build-frameworks.test.js index aea427898bb1..bea8fb11bb1b 100644 --- a/test/static-build-frameworks.test.js +++ b/test/static-build-frameworks.test.js @@ -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(); }); diff --git a/test/static-build-page-url-format.test.js b/test/static-build-page-url-format.test.js index 6e36ba61d0c8..6f43a441bd5e 100644 --- a/test/static-build-page-url-format.test.js +++ b/test/static-build-page-url-format.test.js @@ -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', }, diff --git a/test/static-build.test.js b/test/static-build.test.js index 81473bd0e9ec..6ca4fd8c71e5 100644 --- a/test/static-build.test.js +++ b/test/static-build.test.js @@ -14,7 +14,6 @@ describe('Static build', () => { projectRoot: './fixtures/static build/', renderers: ['@astrojs/renderer-preact'], buildOptions: { - experimentalStaticBuild: true, site: 'http://example.com/subpath/', }, ssr: {