summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/react-component/astro.config.mjs7
-rw-r--r--test/fixtures/react-component/astro/components/Hello.jsx5
-rw-r--r--test/fixtures/react-component/astro/pages/index.hmx10
-rw-r--r--test/fixtures/react-component/snowpack.config.js5
-rw-r--r--test/react-component.test.js40
-rw-r--r--test/snowpack-integration.test.js24
6 files changed, 81 insertions, 10 deletions
diff --git a/test/fixtures/react-component/astro.config.mjs b/test/fixtures/react-component/astro.config.mjs
new file mode 100644
index 000000000..3a3006dd8
--- /dev/null
+++ b/test/fixtures/react-component/astro.config.mjs
@@ -0,0 +1,7 @@
+
+export default {
+ projectRoot: '.',
+ hmxRoot: './astro',
+ dist: './_site'
+ // No extensions needed, React is the default.
+} \ No newline at end of file
diff --git a/test/fixtures/react-component/astro/components/Hello.jsx b/test/fixtures/react-component/astro/components/Hello.jsx
new file mode 100644
index 000000000..d4be8a8fb
--- /dev/null
+++ b/test/fixtures/react-component/astro/components/Hello.jsx
@@ -0,0 +1,5 @@
+import React from 'react';
+
+export default function({ name }) {
+ return <h2>Hello {name}!</h2>
+} \ No newline at end of file
diff --git a/test/fixtures/react-component/astro/pages/index.hmx b/test/fixtures/react-component/astro/pages/index.hmx
new file mode 100644
index 000000000..8616754ca
--- /dev/null
+++ b/test/fixtures/react-component/astro/pages/index.hmx
@@ -0,0 +1,10 @@
+<script astro>
+ import Hello from '../components/Hello.jsx';
+</script>
+
+<astro:head>
+ <!-- Head Stuff -->
+</astro:head>
+
+<h1>My page</h1>
+<Hello name="world" /> \ No newline at end of file
diff --git a/test/fixtures/react-component/snowpack.config.js b/test/fixtures/react-component/snowpack.config.js
new file mode 100644
index 000000000..2cbf0ef07
--- /dev/null
+++ b/test/fixtures/react-component/snowpack.config.js
@@ -0,0 +1,5 @@
+export default {
+ mount: {
+
+ }
+};
diff --git a/test/react-component.test.js b/test/react-component.test.js
new file mode 100644
index 000000000..0b6273922
--- /dev/null
+++ b/test/react-component.test.js
@@ -0,0 +1,40 @@
+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 React = suite('React Components');
+
+let runtime;
+
+React.before(async () => {
+ const astroConfig = await loadConfig(new URL('./fixtures/react-component', import.meta.url).pathname);
+
+ const logging = {
+ level: 'error',
+ dest: process.stderr
+ };
+
+ try {
+ runtime = await createRuntime(astroConfig, logging);
+ } catch(err) {
+ console.error(err);
+ throw err;
+ }
+});
+
+React.after(async () => {
+ await runtime.shutdown();
+});
+
+React('Can load hmx page', async () => {
+ const result = await runtime.load('/');
+
+ assert.equal(result.statusCode, 200);
+
+ const $ = doc(result.contents);
+ assert.equal($('h2').text(), 'Hello world!');
+});
+
+React.run(); \ No newline at end of file
diff --git a/test/snowpack-integration.test.js b/test/snowpack-integration.test.js
index c851e8bdb..8547ee7cd 100644
--- a/test/snowpack-integration.test.js
+++ b/test/snowpack-integration.test.js
@@ -1,35 +1,39 @@
import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import { createRuntime } from '../lib/runtime.js';
+import { loadConfig } from '../lib/config.js';
import { promises as fsPromises } from 'fs';
import { relative as pathRelative } from 'path';
import { doc } from './test-utils.js';
const { readdir, stat } = fsPromises;
-// Bug: Snowpack config is still loaded relative to the current working directory.
-process.chdir(new URL('../examples/snowpack/', import.meta.url).pathname);
-
const SnowpackDev = suite('snowpack.dev');
-let runtime;
+let runtime, cwd;
SnowpackDev.before(async () => {
- const astroConfig = {
- projectRoot: new URL('../examples/snowpack/', import.meta.url),
- hmxRoot: new URL('../examples/snowpack/astro/', import.meta.url),
- dist: './_site',
- };
+// Bug: Snowpack config is still loaded relative to the current working directory.
+ cwd = process.cwd();
+ process.chdir(new URL('../examples/snowpack/', import.meta.url).pathname);
+
+ const astroConfig = await loadConfig(new URL('../examples/snowpack', import.meta.url).pathname);
const logging = {
level: 'error',
dest: process.stderr,
};
- runtime = await createRuntime(astroConfig, logging);
+ try {
+ runtime = await createRuntime(astroConfig, logging);
+ } catch(err) {
+ console.error(err);
+ throw err;
+ }
});
SnowpackDev.after(async () => {
+ process.chdir(cwd);
await runtime && runtime.shutdown();
});