test: unskip passing E2E tests #47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Tests | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 45 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| # TODO: Re-enable type checking after fixing remaining TypeScript errors | |
| # Tracked in follow-up issue | |
| # - name: Type check | |
| # run: npm run type-check | |
| - name: Run unit tests | |
| run: npm test | |
| - name: Build core package | |
| run: npm run build:core | |
| - name: Deploy to Cloudflare Workers Preview | |
| id: deploy | |
| run: | | |
| cd my-sonicjs-app | |
| # Deploy to preview with unique name based on PR/branch | |
| BRANCH_NAME="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" | |
| SAFE_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9-]/-/g' | cut -c1-50) | |
| # Deploy and capture the URL (don't exit on error) | |
| set +e | |
| echo "Deploying to preview environment: pr-${SAFE_BRANCH}" | |
| DEPLOY_OUTPUT=$(npx wrangler deploy --name "sonicjs-pr-${SAFE_BRANCH}" 2>&1) | |
| DEPLOY_EXIT_CODE=$? | |
| set -e | |
| echo "=== Wrangler Deploy Output ===" | |
| echo "$DEPLOY_OUTPUT" | |
| echo "=== End Deploy Output ===" | |
| if [ $DEPLOY_EXIT_CODE -ne 0 ]; then | |
| echo "Error: Wrangler deploy failed with exit code $DEPLOY_EXIT_CODE" | |
| exit 1 | |
| fi | |
| # Extract the URL from wrangler output | |
| PREVIEW_URL=$(echo "$DEPLOY_OUTPUT" | grep -oP 'https://[^\s]+\.workers\.dev' | head -1) | |
| if [ -z "$PREVIEW_URL" ]; then | |
| echo "Failed to extract preview URL from wrangler output" | |
| exit 1 | |
| fi | |
| echo "Preview URL: $PREVIEW_URL" | |
| echo "preview_url=$PREVIEW_URL" >> $GITHUB_OUTPUT | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| - name: Wait for preview deployment | |
| run: | | |
| echo "Waiting for preview to be ready..." | |
| for i in {1..30}; do | |
| if curl -s -o /dev/null -w "%{http_code}" "${{ steps.deploy.outputs.preview_url }}" | grep -q "200\|301\|302"; then | |
| echo "Preview is ready!" | |
| exit 0 | |
| fi | |
| echo "Attempt $i/30: Preview not ready yet, waiting..." | |
| sleep 10 | |
| done | |
| echo "Preview failed to become ready" | |
| exit 1 | |
| - name: Install Playwright browsers | |
| run: npx playwright install --with-deps chromium | |
| - name: Run E2E tests against preview | |
| run: npm run e2e | |
| env: | |
| CI: true | |
| BASE_URL: ${{ steps.deploy.outputs.preview_url }} | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: playwright-report | |
| path: playwright-report/ | |
| retention-days: 7 | |
| - name: Upload test videos | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-videos | |
| path: test-results/ | |
| retention-days: 7 |