mirror of
https://github.com/langchain-ai/create-agent-chat-app.git
synced 2026-06-30 21:37:54 -04:00
feat: Add e2e testing
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
name: E2E Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
pull_request:
|
||||
workflow_dispatch: # Allows triggering the workflow manually in GitHub UI
|
||||
|
||||
# If another push to the same PR or branch happens while this workflow is still running,
|
||||
# cancel the earlier run in favor of the next run.
|
||||
#
|
||||
# There's no point in testing an outdated version of the code. GitHub only allows
|
||||
# a limited number of job runners to be active at the same time, so it's better to cancel
|
||||
# pointless jobs early so that more useful jobs can run sooner.
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test-create-command:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [16.x, 18.x, 20.x, 22.x]
|
||||
package-manager: [npm, yarn, pnpm]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: "yarn"
|
||||
|
||||
- name: Setup pnpm
|
||||
if: matrix.package-manager == 'pnpm'
|
||||
uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 8
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
|
||||
- name: Build package
|
||||
run: yarn build
|
||||
|
||||
- name: Create test directory
|
||||
run: mkdir -p /tmp/test-${{ matrix.package-manager }}
|
||||
|
||||
- name: Run create-agent-chat-app command
|
||||
run: ./scripts/test-create-command.sh ${{ matrix.package-manager }}
|
||||
|
||||
- name: Test build in created project
|
||||
run: ./scripts/test-build.sh ${{ matrix.package-manager }}
|
||||
+6
-1
@@ -30,7 +30,12 @@
|
||||
"format": "prettier --write . --ignore-path .prettierignore",
|
||||
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
||||
"lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix",
|
||||
"format:check": "prettier --check . --ignore-path .prettierignore"
|
||||
"format:check": "prettier --check . --ignore-path .prettierignore",
|
||||
"e2e": "./scripts/run-all-e2e-local.sh",
|
||||
"e2e:npm": "./scripts/run-e2e-local.sh npm cleanup",
|
||||
"e2e:yarn": "./scripts/run-e2e-local.sh yarn cleanup",
|
||||
"e2e:pnpm": "./scripts/run-e2e-local.sh pnpm cleanup",
|
||||
"e2e:cleanup": "./scripts/cleanup-tests.sh"
|
||||
},
|
||||
"dependencies": {
|
||||
"@clack/prompts": "^0.10.0",
|
||||
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "Cleaning up test directories..."
|
||||
|
||||
# Clean up test directories for all package managers
|
||||
rm -rf /tmp/test-npm /tmp/test-yarn /tmp/test-pnpm
|
||||
|
||||
echo "Cleanup completed successfully!"
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Run tests for each package manager
|
||||
echo "Running E2E tests for all package managers..."
|
||||
|
||||
# Test npm
|
||||
echo "=== Testing with npm ==="
|
||||
"$SCRIPT_DIR/run-e2e-local.sh" npm
|
||||
|
||||
# Test yarn
|
||||
echo "=== Testing with yarn ==="
|
||||
"$SCRIPT_DIR/run-e2e-local.sh" yarn
|
||||
|
||||
# Test pnpm
|
||||
echo "=== Testing with pnpm ==="
|
||||
"$SCRIPT_DIR/run-e2e-local.sh" pnpm
|
||||
|
||||
# Clean up after all tests
|
||||
echo "Cleaning up test directories..."
|
||||
"$SCRIPT_DIR/cleanup-tests.sh"
|
||||
|
||||
echo "All E2E tests completed successfully!"
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Check if package manager is provided
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: $0 <package-manager> [cleanup]"
|
||||
echo " package-manager: npm, yarn, or pnpm"
|
||||
echo " cleanup: add 'cleanup' as second argument to clean up test directories after tests"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PACKAGE_MANAGER=$1
|
||||
CLEANUP=$2
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
# Build the package first
|
||||
echo "Building package..."
|
||||
cd "$PROJECT_ROOT"
|
||||
yarn build
|
||||
|
||||
# Run the test scripts
|
||||
echo "Running E2E tests for $PACKAGE_MANAGER..."
|
||||
"$SCRIPT_DIR/test-create-command.sh" "$PACKAGE_MANAGER"
|
||||
"$SCRIPT_DIR/test-build.sh" "$PACKAGE_MANAGER"
|
||||
|
||||
# Clean up if requested
|
||||
if [ "$CLEANUP" = "cleanup" ]; then
|
||||
echo "Cleaning up test directories..."
|
||||
"$SCRIPT_DIR/cleanup-tests.sh"
|
||||
fi
|
||||
|
||||
echo "E2E tests for $PACKAGE_MANAGER completed successfully!"
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Get the package manager from the first argument
|
||||
PACKAGE_MANAGER=$1
|
||||
TEST_DIR="/tmp/test-${PACKAGE_MANAGER}"
|
||||
PROJECT_NAME="test-agent-chat-app"
|
||||
PROJECT_DIR="${TEST_DIR}/${PROJECT_NAME}"
|
||||
|
||||
echo "Testing build in created project with package manager: ${PACKAGE_MANAGER}"
|
||||
|
||||
# Navigate to the project directory
|
||||
cd "${PROJECT_DIR}"
|
||||
|
||||
# Run the build command based on the package manager
|
||||
echo "Building project..."
|
||||
case "${PACKAGE_MANAGER}" in
|
||||
npm)
|
||||
npm run build
|
||||
;;
|
||||
yarn)
|
||||
yarn build
|
||||
;;
|
||||
pnpm)
|
||||
pnpm build
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported package manager: ${PACKAGE_MANAGER}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Check if the build was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Build completed successfully!"
|
||||
else
|
||||
echo "Build failed!"
|
||||
exit 1
|
||||
fi
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Get the package manager from the first argument
|
||||
PACKAGE_MANAGER=$1
|
||||
TEST_DIR="/tmp/test-${PACKAGE_MANAGER}"
|
||||
PROJECT_NAME="test-agent-chat-app"
|
||||
PROJECT_DIR="${TEST_DIR}/${PROJECT_NAME}"
|
||||
|
||||
echo "Testing create-agent-chat-app with package manager: ${PACKAGE_MANAGER}"
|
||||
|
||||
# Clean up any previous test directory
|
||||
rm -rf "${PROJECT_DIR}"
|
||||
mkdir -p "${TEST_DIR}"
|
||||
cd "${TEST_DIR}"
|
||||
|
||||
# Determine the project root in local environment or CI
|
||||
PROJECT_ROOT=${GITHUB_WORKSPACE:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)}
|
||||
|
||||
# Run the create command with the specified package manager
|
||||
echo "Running create-agent-chat-app command..."
|
||||
cd "${TEST_DIR}"
|
||||
|
||||
# Run the command directly using node with the local index.js file
|
||||
echo "Using local package from ${PROJECT_ROOT}"
|
||||
node "${PROJECT_ROOT}/index.js" -Y --project-name="${PROJECT_NAME}" --package-manager="${PACKAGE_MANAGER}"
|
||||
|
||||
# Verify the project was created
|
||||
if [ ! -d "${PROJECT_DIR}" ]; then
|
||||
echo "Error: Project directory was not created at ${PROJECT_DIR}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Project created successfully at ${PROJECT_DIR}"
|
||||
Reference in New Issue
Block a user