|
| 1 | +name: Test Init Command |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + test-init: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout CLI repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Setup Node.js |
| 19 | + uses: actions/setup-node@v4 |
| 20 | + with: |
| 21 | + node-version: '20' |
| 22 | + cache: 'npm' |
| 23 | + |
| 24 | + - name: Install CLI dependencies |
| 25 | + run: npm ci |
| 26 | + |
| 27 | + - name: Create test directory |
| 28 | + run: | |
| 29 | + mkdir -p /tmp/test-init-project |
| 30 | + cd /tmp/test-init-project |
| 31 | + |
| 32 | + - name: Run init command (skip prompts) |
| 33 | + working-directory: /tmp/test-init-project |
| 34 | + run: | |
| 35 | + # Create .env with API key first to skip the prompt |
| 36 | + echo "TD_API_KEY=${{ secrets.TD_API_KEY }}" > .env |
| 37 | + |
| 38 | + # Run init command using the CLI from the repo |
| 39 | + node ${{ github.workspace }}/bin/testdriverai.js init |
| 40 | + env: |
| 41 | + TD_API_KEY: ${{ secrets.TD_API_KEY }} |
| 42 | + |
| 43 | + - name: Verify project structure |
| 44 | + working-directory: /tmp/test-init-project |
| 45 | + run: | |
| 46 | + echo "Checking generated files..." |
| 47 | + |
| 48 | + # Check for package.json |
| 49 | + if [ ! -f "package.json" ]; then |
| 50 | + echo "❌ package.json not found" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + echo "✓ package.json exists" |
| 54 | + |
| 55 | + # Check for vitest config |
| 56 | + if [ ! -f "vitest.config.js" ]; then |
| 57 | + echo "❌ vitest.config.js not found" |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | + echo "✓ vitest.config.js exists" |
| 61 | + |
| 62 | + # Check for test file |
| 63 | + if [ ! -f "tests/example.test.js" ]; then |
| 64 | + echo "❌ tests/example.test.js not found" |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | + echo "✓ tests/example.test.js exists" |
| 68 | + |
| 69 | + # Check for .env file |
| 70 | + if [ ! -f ".env" ]; then |
| 71 | + echo "❌ .env not found" |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | + echo "✓ .env exists" |
| 75 | + |
| 76 | + # Check for .gitignore |
| 77 | + if [ ! -f ".gitignore" ]; then |
| 78 | + echo "❌ .gitignore not found" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + echo "✓ .gitignore exists" |
| 82 | + |
| 83 | + # Check for GitHub workflow |
| 84 | + if [ ! -f ".github/workflows/testdriver.yml" ]; then |
| 85 | + echo "❌ .github/workflows/testdriver.yml not found" |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | + echo "✓ .github/workflows/testdriver.yml exists" |
| 89 | + |
| 90 | + - name: Verify vitest config contents |
| 91 | + working-directory: /tmp/test-init-project |
| 92 | + run: | |
| 93 | + echo "Checking vitest.config.js contents..." |
| 94 | + |
| 95 | + # Check for TestDriver reporter |
| 96 | + if ! grep -q "TestDriver()" vitest.config.js; then |
| 97 | + echo "❌ TestDriver reporter not found in vitest.config.js" |
| 98 | + cat vitest.config.js |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | + echo "✓ TestDriver reporter is configured" |
| 102 | + |
| 103 | + # Check for setupFiles |
| 104 | + if ! grep -q "setupFiles.*testdriverai/vitest/setup" vitest.config.js; then |
| 105 | + echo "❌ setupFiles not configured correctly" |
| 106 | + cat vitest.config.js |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | + echo "✓ setupFiles is configured" |
| 110 | + |
| 111 | + - name: Verify test file contents |
| 112 | + working-directory: /tmp/test-init-project |
| 113 | + run: | |
| 114 | + echo "Checking test file contents..." |
| 115 | + |
| 116 | + # Check for .provision usage |
| 117 | + if ! grep -q "\.provision\.chrome" tests/example.test.js; then |
| 118 | + echo "❌ Test does not use .provision.chrome" |
| 119 | + cat tests/example.test.js |
| 120 | + exit 1 |
| 121 | + fi |
| 122 | + echo "✓ Test uses .provision.chrome" |
| 123 | + |
| 124 | + # Check for TestDriver import |
| 125 | + if ! grep -q "from 'testdriverai/vitest/hooks'" tests/example.test.js; then |
| 126 | + echo "❌ Test does not import from testdriverai/vitest/hooks" |
| 127 | + cat tests/example.test.js |
| 128 | + exit 1 |
| 129 | + fi |
| 130 | + echo "✓ Test imports TestDriver from vitest/hooks" |
| 131 | + |
| 132 | + - name: Run the generated test |
| 133 | + working-directory: /tmp/test-init-project |
| 134 | + run: npm test |
| 135 | + env: |
| 136 | + TD_API_KEY: ${{ secrets.TD_API_KEY }} |
| 137 | + |
| 138 | + - name: Upload test results |
| 139 | + if: always() |
| 140 | + uses: actions/upload-artifact@v4 |
| 141 | + with: |
| 142 | + name: test-init-results |
| 143 | + path: /tmp/test-init-project/test-results/ |
| 144 | + retention-days: 7 |
| 145 | + if-no-files-found: warn |
0 commit comments