summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/hmx-markdown/astro.config.mjs9
-rw-r--r--test/fixtures/hmx-markdown/astro/components/Example.jsx5
-rw-r--r--test/fixtures/hmx-markdown/astro/layouts/content.hmx3
-rw-r--r--test/fixtures/hmx-markdown/astro/pages/index.hmx13
-rw-r--r--test/fixtures/hmx-markdown/astro/pages/post.md13
-rw-r--r--test/fixtures/hmx-markdown/snowpack.config.js5
-rw-r--r--test/hmx-markdown.test.js45
-rw-r--r--test/react-component.test.js8
-rw-r--r--test/snowpack-integration.test.js8
9 files changed, 105 insertions, 4 deletions
diff --git a/test/fixtures/hmx-markdown/astro.config.mjs b/test/fixtures/hmx-markdown/astro.config.mjs
new file mode 100644
index 000000000..0f0be4b94
--- /dev/null
+++ b/test/fixtures/hmx-markdown/astro.config.mjs
@@ -0,0 +1,9 @@
+
+export default {
+ projectRoot: '.',
+ hmxRoot: './astro',
+ dist: './_site',
+ extensions: {
+ '.jsx': 'preact'
+ }
+} \ No newline at end of file
diff --git a/test/fixtures/hmx-markdown/astro/components/Example.jsx b/test/fixtures/hmx-markdown/astro/components/Example.jsx
new file mode 100644
index 000000000..57bde3a95
--- /dev/null
+++ b/test/fixtures/hmx-markdown/astro/components/Example.jsx
@@ -0,0 +1,5 @@
+import { h } from 'preact';
+
+export default function() {
+ return <div id="test">Testing</div>
+} \ No newline at end of file
diff --git a/test/fixtures/hmx-markdown/astro/layouts/content.hmx b/test/fixtures/hmx-markdown/astro/layouts/content.hmx
new file mode 100644
index 000000000..52f79400c
--- /dev/null
+++ b/test/fixtures/hmx-markdown/astro/layouts/content.hmx
@@ -0,0 +1,3 @@
+<div class="container">
+ <slot></slot>
+</div> \ No newline at end of file
diff --git a/test/fixtures/hmx-markdown/astro/pages/index.hmx b/test/fixtures/hmx-markdown/astro/pages/index.hmx
new file mode 100644
index 000000000..19f888e04
--- /dev/null
+++ b/test/fixtures/hmx-markdown/astro/pages/index.hmx
@@ -0,0 +1,13 @@
+<script astro>
+ export function setup() {
+ return {
+ props: {}
+ }
+ }
+</script>
+
+<astro:head>
+ <!-- Head Stuff -->
+</astro:head>
+
+<h1>Hello world!</h1> \ No newline at end of file
diff --git a/test/fixtures/hmx-markdown/astro/pages/post.md b/test/fixtures/hmx-markdown/astro/pages/post.md
new file mode 100644
index 000000000..057b1febb
--- /dev/null
+++ b/test/fixtures/hmx-markdown/astro/pages/post.md
@@ -0,0 +1,13 @@
+---
+layout: layouts/content.hmx
+title: My Blog Post
+description: This is a post about some stuff.
+import:
+ Example: '../components/Example.jsx'
+---
+
+## Interesting Topic
+
+<div id="first">Some content</div>
+
+<Example /> \ No newline at end of file
diff --git a/test/fixtures/hmx-markdown/snowpack.config.js b/test/fixtures/hmx-markdown/snowpack.config.js
new file mode 100644
index 000000000..2cbf0ef07
--- /dev/null
+++ b/test/fixtures/hmx-markdown/snowpack.config.js
@@ -0,0 +1,5 @@
+export default {
+ mount: {
+
+ }
+};
diff --git a/test/hmx-markdown.test.js b/test/hmx-markdown.test.js
new file mode 100644
index 000000000..1a3a2e11c
--- /dev/null
+++ b/test/hmx-markdown.test.js
@@ -0,0 +1,45 @@
+import { suite } from 'uvu';
+import * as assert from 'uvu/assert';
+import { createRuntime } from '../lib/runtime.js';
+import { loadConfig } from '../lib/config.js';
+import { doc } from './test-utils.js';
+
+const HMXMD = suite('HMX Markdown');
+
+let runtime, setupError;
+
+HMXMD.before(async () => {
+ const astroConfig = await loadConfig(new URL('./fixtures/hmx-markdown', import.meta.url).pathname);
+
+ const logging = {
+ level: 'error',
+ dest: process.stderr
+ };
+
+ try {
+ runtime = await createRuntime(astroConfig, logging);
+ } catch(err) {
+ console.error(err);
+ setupError = err;
+ }
+});
+
+HMXMD.after(async () => {
+ runtime && runtime.shutdown();
+});
+
+HMXMD('No errors creating a runtime', () => {
+ assert.equal(setupError, undefined);
+});
+
+HMXMD('Can load markdown pages with hmx', async () => {
+ const result = await runtime.load('/post');
+
+ assert.equal(result.statusCode, 200);
+
+ const $ = doc(result.contents);
+ assert.ok($('#first').length, 'There is a div added in markdown');
+ assert.ok($('#test').length, 'There is a div added via a component from markdown');
+});
+
+HMXMD.run(); \ No newline at end of file
diff --git a/test/react-component.test.js b/test/react-component.test.js
index 0b6273922..d901c62b0 100644
--- a/test/react-component.test.js
+++ b/test/react-component.test.js
@@ -6,7 +6,7 @@ import { doc } from './test-utils.js';
const React = suite('React Components');
-let runtime;
+let runtime, setupError;
React.before(async () => {
const astroConfig = await loadConfig(new URL('./fixtures/react-component', import.meta.url).pathname);
@@ -20,7 +20,7 @@ React.before(async () => {
runtime = await createRuntime(astroConfig, logging);
} catch(err) {
console.error(err);
- throw err;
+ setupError = err;
}
});
@@ -28,6 +28,10 @@ React.after(async () => {
await runtime.shutdown();
});
+React('No error creating the runtime', () => {
+ assert.equal(setupError, undefined);
+});
+
React('Can load hmx page', async () => {
const result = await runtime.load('/');
diff --git a/test/snowpack-integration.test.js b/test/snowpack-integration.test.js
index 8547ee7cd..033f5587d 100644
--- a/test/snowpack-integration.test.js
+++ b/test/snowpack-integration.test.js
@@ -10,7 +10,7 @@ const { readdir, stat } = fsPromises;
const SnowpackDev = suite('snowpack.dev');
-let runtime, cwd;
+let runtime, cwd, setupError;
SnowpackDev.before(async () => {
// Bug: Snowpack config is still loaded relative to the current working directory.
@@ -28,7 +28,7 @@ SnowpackDev.before(async () => {
runtime = await createRuntime(astroConfig, logging);
} catch(err) {
console.error(err);
- throw err;
+ setupError = err;
}
});
@@ -58,6 +58,10 @@ async function* allPages(root) {
}
}
+SnowpackDev('No error creating the runtime', () => {
+ assert.equal(setupError, undefined);
+});
+
SnowpackDev('Can load every page', async () => {
const failed = [];