diff options
author | 2021-04-13 13:04:01 -0400 | |
---|---|---|
committer | 2021-04-13 13:04:01 -0400 | |
commit | ac22d94e1170bce5f1f50abfdf46052369a0edf8 (patch) | |
tree | 26aed00d93b2244f1e3b02fbb4aca46a2623709a /test/astro-markdown.test.js | |
parent | b5885813969fcc4d6bffff84609cb53ffd84bac7 (diff) | |
download | astro-ac22d94e1170bce5f1f50abfdf46052369a0edf8.tar.gz astro-ac22d94e1170bce5f1f50abfdf46052369a0edf8.tar.zst astro-ac22d94e1170bce5f1f50abfdf46052369a0edf8.zip |
fix: bundle client-side code for components used in .md pages (#78)
Diffstat (limited to 'test/astro-markdown.test.js')
-rw-r--r-- | test/astro-markdown.test.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/test/astro-markdown.test.js b/test/astro-markdown.test.js index 572569466..1651a0a6f 100644 --- a/test/astro-markdown.test.js +++ b/test/astro-markdown.test.js @@ -1,15 +1,22 @@ +import { existsSync, promises as fsPromises } from 'fs'; +import { join } from 'path'; import { suite } from 'uvu'; import * as assert from 'uvu/assert'; import { createRuntime } from '../lib/runtime.js'; +import { build } from '../lib/build.js'; import { loadConfig } from '../lib/config.js'; import { doc } from './test-utils.js'; +const { rmdir, readFile } = fsPromises; + const Markdown = suite('Astro Markdown'); -let runtime, setupError; +let runtime, setupError, fixturePath, astroConfig; Markdown.before(async () => { - const astroConfig = await loadConfig(new URL('./fixtures/astro-markdown', import.meta.url).pathname); + fixturePath = new URL('./fixtures/astro-markdown', import.meta.url).pathname; + + astroConfig = await loadConfig(fixturePath); const logging = { level: 'error', @@ -26,6 +33,7 @@ Markdown.before(async () => { Markdown.after(async () => { (await runtime) && runtime.shutdown(); + rmdir(join(fixturePath, '_site'), { recursive: true }); }); Markdown('No errors creating a runtime', () => { @@ -50,4 +58,13 @@ Markdown('Can load more complex jsxy stuff', async () => { assert.equal($el.text(), 'Hello world'); }); +Markdown('Bundles client-side JS for prod', async () => { + await build(astroConfig); + + const complexHtml = await readFile(join(fixturePath, './_site/complex/index.html'), 'utf-8'); + + assert.match(complexHtml, `import("/_astro/components/Counter.js"`); + assert.ok(existsSync(join(fixturePath, `./_site/_astro/components/Counter.js`)), 'Counter.jsx is bundled for prod'); +}); + Markdown.run(); |