|
| 1 | +name: "Run Playwright tests" |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - 'releases/*' |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + test-linux: |
| 13 | + name: Playwright tests on ${{ matrix.os }} (headless=${{ matrix.headless }}) |
| 14 | + runs-on: ubuntu-20.04 # Specify the Ubuntu version you prefer |
| 15 | + |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + headless: [true] |
| 20 | + |
| 21 | + steps: |
| 22 | + # 1. Checkout the repository |
| 23 | + - uses: actions/checkout@v3 |
| 24 | + |
| 25 | + # 2. Setup Node.js |
| 26 | + - name: Setup Node.js |
| 27 | + uses: actions/setup-node@v3 |
| 28 | + with: |
| 29 | + node-version: 18 |
| 30 | + |
| 31 | + # 3. Setup pnpm |
| 32 | + - name: Setup pnpm |
| 33 | + uses: pnpm/action-setup@v2 |
| 34 | + with: |
| 35 | + version: 7.x |
| 36 | + |
| 37 | + # 4. Cache pnpm dependencies |
| 38 | + - name: Cache pnpm dependencies |
| 39 | + uses: actions/cache@v3 |
| 40 | + with: |
| 41 | + path: ~/.pnpm-store |
| 42 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 43 | + restore-keys: | |
| 44 | + ${{ runner.os }}-pnpm-store- |
| 45 | +
|
| 46 | + # 5. Install dependencies |
| 47 | + - name: Install dependencies |
| 48 | + run: pnpm install |
| 49 | + |
| 50 | + # 6. Build the @instructure/idb-cache package |
| 51 | + - name: Build idb-cache package |
| 52 | + run: pnpm --filter @instructure/idb-cache build |
| 53 | + |
| 54 | + # 7. Build the idb-cache-app |
| 55 | + - name: Build idb-cache-app |
| 56 | + run: pnpm --filter idb-cache-app build |
| 57 | + |
| 58 | + # 8. Serve the idb-cache-app |
| 59 | + - name: Serve idb-cache-app |
| 60 | + run: pnpm --filter idb-cache-app preview -- --port 3000 & |
| 61 | + # The '&' runs the serve command in the background |
| 62 | + |
| 63 | + # 9. Wait for the server to be ready |
| 64 | + - name: Wait for idb-cache-app to be ready |
| 65 | + run: | |
| 66 | + for i in {1..60}; do |
| 67 | + if curl -s http://localhost:3000 > /dev/null; then |
| 68 | + echo "Server is ready!" |
| 69 | + break |
| 70 | + fi |
| 71 | + echo "Waiting for server to be ready... ($i/60)" |
| 72 | + sleep 1 |
| 73 | + done |
| 74 | +
|
| 75 | + # 10. Run Playwright tests in headless mode |
| 76 | + - name: Run Playwright tests (Headless) |
| 77 | + if: ${{ matrix.headless == true }} |
| 78 | + run: pnpm --filter idb-cache-app playwright test |
| 79 | + |
| 80 | + # 11. Run Playwright tests in headful mode on Linux |
| 81 | + - name: Run Playwright tests (Headful) |
| 82 | + if: ${{ matrix.headless == false }} |
| 83 | + run: | |
| 84 | + export HEADFUL=true |
| 85 | + xvfb-run --auto-servernum -- pnpm --filter idb-cache-app playwright test |
0 commit comments