# This is a basic workflow to help you get started with Actions

name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

  workflow_dispatch:

jobs:
  test:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js environment
        uses: actions/setup-node@v4.0.2
        with:
          node-version-file: ".nvmrc"

      - name: Reuse npm cache folder
        uses: actions/cache@v4
        env:
          cache-name: cache-node-modules
        with:
          path: |
            ~/.npm
            ./node_modules
          key: ${{ runner.os }}-npm-test-x1-${{ hashFiles('**/package.json') }}
          restore-keys: |
            ${{ runner.os }}-npm-test-x1-

      - name: install npm dependencies
        run: npm install --legacy-peer-deps
        
      - name: build
        run: npm run build

      - name: test:node
        run: npm run test:node

      - name: test:browser
        uses: GabrielBB/xvfb-action@v1
        with:
          run: npm run test:browser

      - name: lint
        run: npm run lint
