Skip to content

Commit

Permalink
test(e2e): setup initial e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pawcoding committed Jan 26, 2025
1 parent fd0ca18 commit 9504355
Show file tree
Hide file tree
Showing 14 changed files with 452 additions and 11 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ jobs:

# Install dependencies
- name: 📦 Install dependencies
run: |
npm ci
run: npm ci

# Lint code
- name: 🧹 Lint code
Expand All @@ -44,3 +43,23 @@ jobs:
# Run tests
- name: 🧪 Run tests
run: npm test

# Setup PocketBase
- name: 🗄️ Download and setup PocketBase
run: npm run test:e2e:setup

# Start PocketBase
- name: 🚀 Start PocketBase
run: ./.pocketbase/pocketbase serve &

# Wait for PocketBase to be ready
- name: ⏳ Wait for PocketBase
run: |
until curl -s --fail http://localhost:8090/api/health; do
echo 'Waiting for PocketBase...'
sleep 5
done
# Run tests
- name: 🧪 Run e2e tests
run: npm run test:e2e
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# build output
dist/
coverage/
.eslintcache
# generated types
.astro/

Expand All @@ -13,7 +14,6 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production
Expand All @@ -23,3 +23,6 @@ pnpm-debug.log*

# jetbrains setting folder
.idea/

# PocketBase folder
.pocketbase/
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import tseslint from "typescript-eslint";

const config = tseslint.config({
files: ["**/*.{js,mjs,cjs,ts}"],
ignores: [".pocketbase/**/*"],
languageOptions: {
globals: { ...globals.browser, ...globals.node }
},
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
"src"
],
"scripts": {
"lint": "npx eslint",
"lint": "npx eslint --cache",
"prepare": "husky",
"test": "vitest run",
"test:watch": "vitest watch",
"test:ui": "vitest --ui",
"test:coverage": "vitest run --coverage"
"test:coverage": "vitest run --coverage",
"test:e2e": "vitest run --config vitest.config-e2e.ts",
"test:e2e:watch": "vitest watch --config vitest.config-e2e.ts",
"test:e2e:setup": "./scripts/setup-pocketbase.sh",
"test:e2e:pocketbase": "./.pocketbase/pocketbase serve"
},
"peerDependencies": {
"astro": "^5.0.0"
Expand Down
64 changes: 64 additions & 0 deletions scripts/setup-pocketbase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# Define the local .pocketbase directory
POCKETBASE_DIR="$(pwd)/.pocketbase"

# Remove the existing .pocketbase directory if it exists
rm -rf "$POCKETBASE_DIR"

# Create the .pocketbase directory if it doesn't exist
mkdir -p "$POCKETBASE_DIR"

# Change to the .pocketbase directory
cd "$POCKETBASE_DIR"

# Get the latest release tag from PocketBase GitHub releases
latest_release=$(curl -s https://api.github.com/repos/pocketbase/pocketbase/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')

# Determine the architecture
arch=$(uname -m)
if [ "$arch" == "x86_64" ]; then
arch="amd64"
elif [ "$arch" == "aarch64" ]; then
arch="arm64"
else
echo "Unsupported architecture: $arch"
exit 1
fi

# Construct the download URL
download_url="https://github.com/pocketbase/pocketbase/releases/download/${latest_release}/pocketbase_${latest_release#v}_linux_${arch}.zip"

# Download the latest release
echo "Downloading PocketBase ${latest_release}..."
curl -s -L -o pocketbase.zip $download_url

# Check if the download was successful
if [ $? -ne 0 ]; then
echo "Failed to download PocketBase release."
exit 1
fi

# Extract the executable from the zip file
echo "Extracting PocketBase ${latest_release}..."
unzip -qq pocketbase.zip
if [ $? -ne 0 ]; then
echo "Failed to unzip PocketBase release."
exit 1
fi

# Make the executable file executable
chmod +x pocketbase

# Clean up
rm pocketbase.zip

# Setup admin user
echo "Setting up admin user..."
./pocketbase superuser upsert [email protected] test1234
if [ $? -ne 0 ]; then
echo "Failed to setup admin user."
exit 1
fi

echo "PocketBase ${latest_release} has been downloaded and is ready to use."
9 changes: 9 additions & 0 deletions test/_mocks/check-e2e-connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export async function checkE2eConnection(): Promise<void> {
try {
await fetch("http://localhost:8090/api/health");
} catch {
throw new Error(
"E2E connection failed. Make sure the PocketBase instance is running on http://localhost:8090."
);
}
}
6 changes: 5 additions & 1 deletion test/_mocks/create-loader-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ export function createLoaderOptions(
options?: Partial<PocketBaseLoaderOptions>
): PocketBaseLoaderOptions {
return {
url: "https://example.com",
url: "http://127.0.0.1:8090",
collectionName: "test",
superuserCredentials: {
email: "[email protected]",
password: "test1234"
},
...options
};
}
1 change: 1 addition & 0 deletions test/_mocks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./check-e2e-connection";
export * from "./create-loader-context";
export * from "./create-loader-options";
export * from "./create-pocketbase-entry";
Expand Down
Loading

0 comments on commit 9504355

Please sign in to comment.