summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/with-vitest/.gitignore19
-rw-r--r--examples/with-vitest/.npmrc2
-rw-r--r--examples/with-vitest/.stackblitzrc6
-rw-r--r--examples/with-vitest/README.md9
-rw-r--r--examples/with-vitest/astro.config.ts4
-rw-r--r--examples/with-vitest/package.json17
-rw-r--r--examples/with-vitest/public/favicon.icobin0 -> 4286 bytes
-rw-r--r--examples/with-vitest/sandbox.config.json11
-rw-r--r--examples/with-vitest/src/pages/index.astro13
-rw-r--r--examples/with-vitest/test/basic.test.ts21
-rw-r--r--examples/with-vitest/tsconfig.json18
-rw-r--r--examples/with-vitest/vitest.config.ts9
12 files changed, 129 insertions, 0 deletions
diff --git a/examples/with-vitest/.gitignore b/examples/with-vitest/.gitignore
new file mode 100644
index 000000000..02f6e50b4
--- /dev/null
+++ b/examples/with-vitest/.gitignore
@@ -0,0 +1,19 @@
+# build output
+dist/
+
+# dependencies
+node_modules/
+
+# logs
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+
+
+# environment variables
+.env
+.env.production
+
+# macOS-specific files
+.DS_Store
diff --git a/examples/with-vitest/.npmrc b/examples/with-vitest/.npmrc
new file mode 100644
index 000000000..ef83021af
--- /dev/null
+++ b/examples/with-vitest/.npmrc
@@ -0,0 +1,2 @@
+# Expose Astro dependencies for `pnpm` users
+shamefully-hoist=true
diff --git a/examples/with-vitest/.stackblitzrc b/examples/with-vitest/.stackblitzrc
new file mode 100644
index 000000000..43798ecff
--- /dev/null
+++ b/examples/with-vitest/.stackblitzrc
@@ -0,0 +1,6 @@
+{
+ "startCommand": "npm start",
+ "env": {
+ "ENABLE_CJS_IMPORTS": true
+ }
+} \ No newline at end of file
diff --git a/examples/with-vitest/README.md b/examples/with-vitest/README.md
new file mode 100644
index 000000000..8f1f2e6a0
--- /dev/null
+++ b/examples/with-vitest/README.md
@@ -0,0 +1,9 @@
+# Astro + [Vitest](https://vitest.dev/) Example
+
+```
+npm init astro -- --template with-vitest
+```
+
+[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/with-vitest)
+
+This example showcases Astro working with [Vitest](https://vitest.dev/).
diff --git a/examples/with-vitest/astro.config.ts b/examples/with-vitest/astro.config.ts
new file mode 100644
index 000000000..ad7965b1a
--- /dev/null
+++ b/examples/with-vitest/astro.config.ts
@@ -0,0 +1,4 @@
+import { defineConfig } from 'astro/config';
+
+// https://astro.build/config
+export default defineConfig();
diff --git a/examples/with-vitest/package.json b/examples/with-vitest/package.json
new file mode 100644
index 000000000..c445064c9
--- /dev/null
+++ b/examples/with-vitest/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "@example/with-vitest",
+ "version": "0.0.1",
+ "type": "module",
+ "private": true,
+ "scripts": {
+ "dev": "astro dev",
+ "start": "astro dev",
+ "build": "astro build",
+ "preview": "astro preview",
+ "test": "vitest"
+ },
+ "devDependencies": {
+ "astro": "^1.0.0-rc.4",
+ "vitest": "^0.20.3"
+ }
+}
diff --git a/examples/with-vitest/public/favicon.ico b/examples/with-vitest/public/favicon.ico
new file mode 100644
index 000000000..578ad458b
--- /dev/null
+++ b/examples/with-vitest/public/favicon.ico
Binary files differ
diff --git a/examples/with-vitest/sandbox.config.json b/examples/with-vitest/sandbox.config.json
new file mode 100644
index 000000000..9178af77d
--- /dev/null
+++ b/examples/with-vitest/sandbox.config.json
@@ -0,0 +1,11 @@
+{
+ "infiniteLoopProtection": true,
+ "hardReloadOnChange": false,
+ "view": "browser",
+ "template": "node",
+ "container": {
+ "port": 3000,
+ "startScript": "start",
+ "node": "14"
+ }
+}
diff --git a/examples/with-vitest/src/pages/index.astro b/examples/with-vitest/src/pages/index.astro
new file mode 100644
index 000000000..4389d5d25
--- /dev/null
+++ b/examples/with-vitest/src/pages/index.astro
@@ -0,0 +1,13 @@
+---
+---
+
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width" />
+ <title>Astro</title>
+ </head>
+ <body>
+ <h1>Astro</h1>
+ </body>
+</html>
diff --git a/examples/with-vitest/test/basic.test.ts b/examples/with-vitest/test/basic.test.ts
new file mode 100644
index 000000000..0f6d96168
--- /dev/null
+++ b/examples/with-vitest/test/basic.test.ts
@@ -0,0 +1,21 @@
+import { assert, expect, test } from 'vitest'
+
+// Edit an assertion and save to see HMR in action
+
+test('Math.sqrt()', () => {
+ expect(Math.sqrt(4)).toBe(2)
+ expect(Math.sqrt(144)).toBe(12)
+ expect(Math.sqrt(2)).toBe(Math.SQRT2)
+})
+
+test('JSON', () => {
+ const input = {
+ foo: 'hello',
+ bar: 'world',
+ }
+
+ const output = JSON.stringify(input)
+
+ expect(output).eq('{"foo":"hello","bar":"world"}')
+ assert.deepEqual(JSON.parse(output), input, 'matches original')
+})
diff --git a/examples/with-vitest/tsconfig.json b/examples/with-vitest/tsconfig.json
new file mode 100644
index 000000000..be8e3ea96
--- /dev/null
+++ b/examples/with-vitest/tsconfig.json
@@ -0,0 +1,18 @@
+{
+ "compilerOptions": {
+ // Preact specific settings
+ "jsx": "react-jsx",
+ "jsxImportSource": "preact",
+ // Enable top-level await, and other modern ESM features.
+ "target": "ESNext",
+ "module": "ESNext",
+ // Enable node-style module resolution, for things like npm package imports.
+ "moduleResolution": "node",
+ // Enable JSON imports.
+ "resolveJsonModule": true,
+ // Enable stricter transpilation for better output.
+ "isolatedModules": true,
+ // Add type definitions for our Astro runtime.
+ "types": ["astro/client"]
+ }
+}
diff --git a/examples/with-vitest/vitest.config.ts b/examples/with-vitest/vitest.config.ts
new file mode 100644
index 000000000..a34f19bb1
--- /dev/null
+++ b/examples/with-vitest/vitest.config.ts
@@ -0,0 +1,9 @@
+/// <reference types="vitest" />
+import { getViteConfig } from 'astro/config';
+
+export default getViteConfig({
+ test: {
+ /* for example, use global to avoid globals imports (describe, test, expect): */
+ // globals: true,
+ },
+});