summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/astro-dynamic.test.js13
-rw-r--r--test/fixtures/astro-dynamic/astro/components/SvelteCounter.svelte22
-rw-r--r--test/fixtures/astro-dynamic/astro/pages/index.astro3
-rw-r--r--test/helpers.js27
4 files changed, 63 insertions, 2 deletions
diff --git a/test/astro-dynamic.test.js b/test/astro-dynamic.test.js
index 0dcc30654..6c726131c 100644
--- a/test/astro-dynamic.test.js
+++ b/test/astro-dynamic.test.js
@@ -1,11 +1,12 @@
import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import { doc } from './test-utils.js';
-import { setup } from './helpers.js';
+import { setup, setupBuild } from './helpers.js';
const DynamicComponents = suite('Dynamic components tests');
setup(DynamicComponents, './fixtures/astro-dynamic');
+setupBuild(DynamicComponents, './fixtures/astro-dynamic');
DynamicComponents('Loads client-only packages', async ({ runtime }) => {
let result = await runtime.load('/');
@@ -27,4 +28,14 @@ DynamicComponents('Loads client-only packages', async ({ runtime }) => {
assert.equal(result.statusCode, 200, 'Can load react-dom');
});
+DynamicComponents('Can be built', async ({ build }) => {
+ try {
+ await build();
+ assert.ok(true, 'Can build a project with svelte dynamic components');
+ } catch(err) {
+ console.log(err);
+ assert.ok(false, 'build threw');
+ }
+});
+
DynamicComponents.run();
diff --git a/test/fixtures/astro-dynamic/astro/components/SvelteCounter.svelte b/test/fixtures/astro-dynamic/astro/components/SvelteCounter.svelte
new file mode 100644
index 000000000..8d6b3f5e1
--- /dev/null
+++ b/test/fixtures/astro-dynamic/astro/components/SvelteCounter.svelte
@@ -0,0 +1,22 @@
+
+<script>
+ let children;
+ let count = 0;
+
+ function add() {
+ count += 1;
+ }
+
+ function subtract() {
+ count -= 1;
+ }
+</script>
+
+<div class="counter">
+ <button on:click={subtract}>-</button>
+ <pre>{ count }</pre>
+ <button on:click={add}>+</button>
+</div>
+<div class="children">
+ <slot />
+</div>
diff --git a/test/fixtures/astro-dynamic/astro/pages/index.astro b/test/fixtures/astro-dynamic/astro/pages/index.astro
index 12932901f..c4d0fef17 100644
--- a/test/fixtures/astro-dynamic/astro/pages/index.astro
+++ b/test/fixtures/astro-dynamic/astro/pages/index.astro
@@ -1,9 +1,12 @@
---
import Counter from '../components/Counter.jsx';
+import SvelteCounter from '../components/SvelteCounter.svelte';
---
<html>
<head><title>Dynamic pages</title></head>
<body>
<Counter:load />
+
+ <SvelteCounter:load />
</body>
</html> \ No newline at end of file
diff --git a/test/helpers.js b/test/helpers.js
index aa2e31714..ab4c28f30 100644
--- a/test/helpers.js
+++ b/test/helpers.js
@@ -1,6 +1,7 @@
import { fileURLToPath } from 'url';
-import { createRuntime } from '../lib/runtime.js';
+import { build as astroBuild } from '../lib/build.js';
import { loadConfig } from '../lib/config.js';
+import { createRuntime } from '../lib/runtime.js';
import * as assert from 'uvu/assert';
/** setup fixtures for tests */
export function setup(Suite, fixturePath) {
@@ -32,3 +33,27 @@ export function setup(Suite, fixturePath) {
assert.equal(setupError, undefined);
});
}
+
+export function setupBuild(Suite, fixturePath) {
+ let build, setupError;
+
+ Suite.before(async (context) => {
+ const astroConfig = await loadConfig(fileURLToPath(new URL(fixturePath, import.meta.url)));
+
+ const logging = {
+ level: 'error',
+ dest: process.stderr,
+ };
+
+ build = (...args) => astroBuild(astroConfig, ...args);
+ context.build = build;
+ });
+
+ Suite.after(async () => {
+ // Shutdown i guess.
+ });
+
+ Suite('No errors creating a runtime', () => {
+ assert.equal(setupError, undefined);
+ });
+} \ No newline at end of file