name: tests

on:
  push:
    branches:
      - master
      - release-*
  pull_request:
    branches:
      - master
      - release-*

env:
  # Force terminal colors. @see https://www.npmjs.com/package/colors
  FORCE_COLOR: 1
  FLAKINESS_CONNECTION_STRING: ${{ secrets.FLAKINESS_CONNECTION_STRING }}

jobs:
  test_linux:
    name: ${{ matrix.os }} (${{ matrix.browser }})
    strategy:
      fail-fast: false
      matrix:
        browser: [chromium, firefox, webkit]
        os: [ubuntu-18.04, ubuntu-20.04]
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 10
    - run: npm ci
    - run: npm run build
    - run: node lib/cli/cli install-deps ${{ matrix.browser }} chromium
    - run: mkdir -p coredumps
    # Set core dump file name pattern
    - run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern'
    # XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
    # Wrap `npm run` in a subshell to redirect STDERR to file.
    # Enable core dumps in the subshell.
    - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && npx folio test/ --workers=1 --forbid-only --global-timeout=5400000 --retries=3 --reporter=dot,json && node test/checkCoverage.js"
      env:
        BROWSER: ${{ matrix.browser }}
        FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
    - run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
      if: always() && github.repository == 'microsoft/playwright' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-'))
    - uses: actions/upload-artifact@v1
      if: always()
      with:
        name: ${{ matrix.browser }}-${{ matrix.os }}-test-results
        path: test-results

  test_mac:
    name: ${{ matrix.os }} (${{ matrix.browser }})
    strategy:
      fail-fast: false
      matrix:
        os: [macos-10.15, macos-11.0]
        browser: [chromium, firefox, webkit]
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 10
    - run: npm ci
    - run: npm run build
    - run: node lib/cli/cli install-deps ${{ matrix.browser }} chromium
    - run: npx folio test/ --workers=1 --forbid-only --global-timeout=5400000 --retries=3 --reporter=dot,json
      env:
        BROWSER: ${{ matrix.browser }}
        FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
    - run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
      if: always() && github.repository == 'microsoft/playwright' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-'))
    - uses: actions/upload-artifact@v1
      if: ${{ always() }}
      with:
        name: ${{ matrix.browser }}-${{ matrix.os }}-test-results
        path: test-results

  test_win:
    name: "Windows"
    strategy:
      fail-fast: false
      matrix:
        browser: [chromium, firefox, webkit]
    runs-on: windows-latest
    steps:
    - name: Install Media Pack
      shell: powershell
      run: Install-WindowsFeature Server-Media-Foundation
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 10
    - run: npm ci
    - run: npm run build
    - run: node lib/cli/cli install-deps
    - run: npx folio test/ --workers=1 --forbid-only --global-timeout=5400000 --retries=3 --reporter=dot,json
      shell: bash
      env:
        BROWSER: ${{ matrix.browser }}
        FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
    - run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
      if: always() && github.repository == 'microsoft/playwright' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-'))
      shell: bash
    - uses: actions/upload-artifact@v1
      if: ${{ always() }}
      with:
        name: ${{ matrix.browser }}-win-test-results
        path: test-results

  test-package-installations:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node_version:
        - "^10.17.0" # pre 10.17, --unhandled-rejections=strict was not an option (https://github.com/nodejs/node/pull/26599) which we need in our tests
        - "^12.0.0"
        - "^14.1.0"  # pre 14.1, zip extraction was broken (https://github.com/microsoft/playwright/issues/1988)
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node_version }}
    - run: npm ci
    - run: npm run build
    - run: node lib/cli/cli install-deps
    - run: bash packages/installation-tests/installation-tests.sh

  headful_linux:
    name: "Headful Linux"
    strategy:
      fail-fast: false
      matrix:
        browser: [chromium, firefox, webkit]
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 10
    - run: npm ci
    - run: npm run build
    - run: node lib/cli/cli install-deps ${{ matrix.browser }} chromium
    - run: mkdir -p coredumps
    # Set core dump file name pattern
    - run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern'
    # XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
    # Wrap `npm run` in a subshell to redirect STDERR to file.
    # Enable core dumps in the subshell.
    - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && npx folio test/ --workers=1 --forbid-only --global-timeout=5400000 --retries=3 --reporter=dot,json"
      if: ${{ always() }}
      env:
        BROWSER: ${{ matrix.browser }}
        HEADFUL: 1
        FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
    - run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
      if: always() && github.repository == 'microsoft/playwright' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-'))
    - uses: actions/upload-artifact@v1
      if: ${{ always() }}
      with:
        name: headful-${{ matrix.browser }}-linux-test-results
        path: test-results

  transport_linux:
    name: "Transport"
    strategy:
      fail-fast: false
      matrix:
        mode: [driver, service]
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 10
    - run: npm ci
    - run: npm run build
    - run: node lib/cli/cli install-deps chromium
    - run: mkdir -p coredumps
    # Set core dump file name pattern
    - run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern'
    # XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
    # Wrap `npm run` in a subshell to redirect STDERR to file.
    # Enable core dumps in the subshell.
    - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && npx folio test/ --workers=1 --forbid-only --global-timeout=5400000 --retries=3 --reporter=dot,json"
      env:
        BROWSER: "chromium"
        PWMODE: "${{ matrix.mode }}"
        FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
    - run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
      if: always() && github.repository == 'microsoft/playwright' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-'))
    - uses: actions/upload-artifact@v1
      if: ${{ always() }}
      with:
        name: mode-${{ matrix.mode }}-linux-test-results
        path: test-results

  video_linux:
    name: "Video Linux"
    strategy:
      fail-fast: false
      matrix:
        browser: [chromium, firefox, webkit]
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 10
    - run: npm ci
    - run: npm run build
    - run: node lib/cli/cli install-deps ${{ matrix.browser }} chromium
    - run: mkdir -p coredumps
    # Set core dump file name pattern
    - run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern'
    # XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
    # Wrap `npm run` in a subshell to redirect STDERR to file.
    # Enable core dumps in the subshell.
    - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && npx folio test/ --workers=1 --forbid-only --timeout=60000 --global-timeout=5400000 --retries=3 --reporter=dot,json -p video"
      env:
        BROWSER: ${{ matrix.browser }}
        FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
    - run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
      if: always() && github.repository == 'microsoft/playwright' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-'))
    - uses: actions/upload-artifact@v1
      if: ${{ always() }}
      with:
        name: video-${{ matrix.browser }}-linux-test-results
        path: test-results

  test_android:
    name: Android Emulator
    runs-on: macos-10.15
    env:
      FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
      PW_ANDROID_TESTS: 1
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 14
    - run: npm ci
    - run: npm run build
    - run: node lib/cli/cli install-deps
    - name: Create Android Emulator
      run: utils/avd_recreate.sh
    - name: Start Android Emulator
      run: utils/avd_start.sh
    - name: Run device tests
      run: npx folio test/android -p browserName=chromium --workers=1 --forbid-only --timeout=120000 --global-timeout=5400000 --retries=3 --reporter=dot,json
    - name: Run page tests
      run: npx folio test/page -p browserName=chromium --workers=1 --forbid-only --timeout=120000 --global-timeout=5400000 --retries=3 --reporter=dot,json
    - run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
      if: always() && github.repository == 'microsoft/playwright' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-'))
    - uses: actions/upload-artifact@v1
      if: ${{ always() }}
      with:
        name: android-test-results
        path: test-results

  chrome_stable_linux:
    name: "Chrome Stable (Linux)"
    strategy:
      fail-fast: false
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 10
    - name: Install Chrome Stable
      run: sudo apt install google-chrome-stable
    - run: npm ci
      env:
        PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
    - run: npm run build
    - run: node lib/cli/cli install-deps chromium
    # This only created problems, should we move ffmpeg back into npm?
    - run: node lib/cli/cli install ffmpeg
    - run: mkdir -p coredumps
    # Set core dump file name pattern
    - run: sudo bash -c 'echo "$(pwd -P)/coredumps/core-pid_%p.dump" > /proc/sys/kernel/core_pattern'
    # XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
    # Wrap `npm run` in a subshell to redirect STDERR to file.
    # Enable core dumps in the subshell.
    - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && npx folio test/ --workers=1 --forbid-only --timeout=60000 --global-timeout=5400000 --retries=3 --reporter=dot,json"
      env:
        BROWSER: "chromium"
        PW_CHROMIUM_CHANNEL: "chrome"
        FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
    - uses: actions/upload-artifact@v1
      if: ${{ always() }}
      with:
        name: chrome-stable-linux-test-results
        path: test-results

  chrome_stable_win:
    name: "Chrome Stable (Win)"
    runs-on: windows-latest
    steps:
    - name: Install Media Pack
      shell: powershell
      run: Install-WindowsFeature Server-Media-Foundation
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 10
    - run: npm ci
      env:
        PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
    - run: npm run build
    # This only created problems, should we move ffmpeg back into npm?
    - run: node lib/cli/cli install ffmpeg
    - run: npx folio test/ --workers=1 --forbid-only --global-timeout=5400000 --retries=3 --reporter=dot,json
      shell: bash
      env:
        BROWSER: "chromium"
        PW_CHROMIUM_CHANNEL: "chrome"
        FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
    - uses: actions/upload-artifact@v1
      if: ${{ always() }}
      with:
        name: chrome-stable-win-test-results
        path: test-results

  chrome_stable_mac:
    name: "Chrome Stable (Mac)"
    runs-on: macos-10.15
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 10
    - run: npm ci
      env:
        PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
    - run: npm run build
    # This only created problems, should we move ffmpeg back into npm?
    - run: node lib/cli/cli install ffmpeg
    - run: npx folio test/ --workers=1 --forbid-only --global-timeout=5400000 --retries=3 --reporter=dot,json
      env:
        BROWSER: "chromium"
        PW_CHROMIUM_CHANNEL: "chrome"
        FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
    - uses: actions/upload-artifact@v1
      if: ${{ always() }}
      with:
        name: chrome-stable-mac-test-results
        path: test-results

  edge_stable_win:
    name: "Edge Stable (Win)"
    runs-on: windows-latest
    steps:
    - name: Install Media Pack
      shell: powershell
      run: Install-WindowsFeature Server-Media-Foundation
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 10
    - run: npm ci
      env:
        PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
    - run: npm run build
    # This only created problems, should we move ffmpeg back into npm?
    - run: node lib/cli/cli install ffmpeg
    - run: npx folio test/ --workers=1 --forbid-only --global-timeout=5400000 --retries=3 --reporter=dot,json
      shell: bash
      env:
        BROWSER: "chromium"
        PW_CHROMIUM_CHANNEL: "msedge"
        FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
    - uses: actions/upload-artifact@v1
      if: ${{ always() }}
      with:
        name: edge-stable-win-test-results
        path: test-results
