summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/astro-basic.test.js26
-rw-r--r--test/astro-search.test.js41
-rw-r--r--test/fixtures/astro-basic/astro/layouts/base.astro17
-rw-r--r--test/fixtures/astro-basic/astro/pages/index.astro4
-rw-r--r--test/fixtures/astro-basic/astro/pages/nested-astro/index.astro12
-rw-r--r--test/fixtures/astro-basic/astro/pages/nested-md/index.md6
-rw-r--r--test/fixtures/astro-basic/astro/pages/news.astro12
7 files changed, 94 insertions, 24 deletions
diff --git a/test/astro-basic.test.js b/test/astro-basic.test.js
index b06cdfcd0..053bf2fbb 100644
--- a/test/astro-basic.test.js
+++ b/test/astro-basic.test.js
@@ -1,29 +1,13 @@
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';
+import { setup } from './helpers.js';
-const Basics = suite('HMX Basics');
+const Basics = suite('Search paths');
-let runtime;
+setup(Basics, './fixtures/astro-basic');
-Basics.before(async () => {
- const astroConfig = await loadConfig(new URL('./fixtures/astro-basics', import.meta.url).pathname);
-
- const logging = {
- level: 'error',
- dest: process.stderr,
- };
-
- runtime = await createRuntime(astroConfig, { logging });
-});
-
-Basics.after(async () => {
- (await runtime) && runtime.shutdown();
-});
-
-Basics('Can load page', async () => {
+Basics('Can load page', async ({ runtime }) => {
const result = await runtime.load('/');
assert.equal(result.statusCode, 200);
@@ -32,4 +16,4 @@ Basics('Can load page', async () => {
assert.equal($('h1').text(), 'Hello world!');
});
-Basics.run();
+Basics.run(); \ No newline at end of file
diff --git a/test/astro-search.test.js b/test/astro-search.test.js
new file mode 100644
index 000000000..415bc4432
--- /dev/null
+++ b/test/astro-search.test.js
@@ -0,0 +1,41 @@
+import { suite } from 'uvu';
+import * as assert from 'uvu/assert';
+import { setup } from './helpers.js';
+
+const Search = suite('Search paths');
+
+setup(Search, './fixtures/astro-basic');
+
+Search('Finds the root page', async ({ runtime }) => {
+ const result = await runtime.load('/');
+ assert.equal(result.statusCode, 200);
+});
+
+Search('Matches pathname to filename', async ({ runtime }) => {
+ const result = await runtime.load('/news');
+ assert.equal(result.statusCode, 200);
+});
+
+Search('A URL with a trailing slash can match a folder with an index.astro', async ({ runtime }) => {
+ const result = await runtime.load('/nested-astro/');
+ assert.equal(result.statusCode, 200);
+});
+
+Search('A URL with a trailing slash can match a folder with an index.md', async ({ runtime }) => {
+ const result = await runtime.load('/nested-md/');
+ assert.equal(result.statusCode, 200);
+});
+
+Search('A URL without a trailing slash can redirect to a folder with an index.astro', async ({ runtime }) => {
+ const result = await runtime.load('/nested-astro');
+ assert.equal(result.statusCode, 301);
+ assert.equal(result.location, '/nested-astro/');
+});
+
+Search('A URL without a trailing slash can redirect to a folder with an index.md', async ({ runtime }) => {
+ const result = await runtime.load('/nested-md');
+ assert.equal(result.statusCode, 301);
+ assert.equal(result.location, '/nested-md/');
+});
+
+Search.run();
diff --git a/test/fixtures/astro-basic/astro/layouts/base.astro b/test/fixtures/astro-basic/astro/layouts/base.astro
new file mode 100644
index 000000000..ec996a32f
--- /dev/null
+++ b/test/fixtures/astro-basic/astro/layouts/base.astro
@@ -0,0 +1,17 @@
+---
+export let content: any;
+---
+
+<!doctype html>
+<html lang="en">
+<head>
+ <title>{content.title}</title>
+ <meta charset="utf-8">
+</head>
+
+<body>
+ <h1>{content.title}</h1>
+
+ <main><slot></slot></main>
+</body>
+</html> \ No newline at end of file
diff --git a/test/fixtures/astro-basic/astro/pages/index.astro b/test/fixtures/astro-basic/astro/pages/index.astro
index e6b8a1235..5ae5380c5 100644
--- a/test/fixtures/astro-basic/astro/pages/index.astro
+++ b/test/fixtures/astro-basic/astro/pages/index.astro
@@ -1,7 +1,5 @@
---
- export function setup() {
- return {props: {}}
- }
+let title = 'My App'
---
<html>
diff --git a/test/fixtures/astro-basic/astro/pages/nested-astro/index.astro b/test/fixtures/astro-basic/astro/pages/nested-astro/index.astro
new file mode 100644
index 000000000..a28992ee6
--- /dev/null
+++ b/test/fixtures/astro-basic/astro/pages/nested-astro/index.astro
@@ -0,0 +1,12 @@
+---
+let title = 'Nested page'
+---
+
+<html>
+ <head>
+ <!-- Head Stuff -->
+ </head>
+ <body>
+ <h1>{title}</h1>
+ </body>
+</html>
diff --git a/test/fixtures/astro-basic/astro/pages/nested-md/index.md b/test/fixtures/astro-basic/astro/pages/nested-md/index.md
new file mode 100644
index 000000000..23374f9b8
--- /dev/null
+++ b/test/fixtures/astro-basic/astro/pages/nested-md/index.md
@@ -0,0 +1,6 @@
+---
+layout: ../../layouts/base.astro
+title: My Page
+---
+
+Hello world \ No newline at end of file
diff --git a/test/fixtures/astro-basic/astro/pages/news.astro b/test/fixtures/astro-basic/astro/pages/news.astro
new file mode 100644
index 000000000..71a00b8a9
--- /dev/null
+++ b/test/fixtures/astro-basic/astro/pages/news.astro
@@ -0,0 +1,12 @@
+---
+let title = 'The News'
+---
+
+<html lang="en">
+ <head>
+ <title>{title}</title>
+ </head>
+ <body>
+ <h1>Hello world!</h1>
+ </body>
+</html>