name: Test
on:
    pull_request:
    push:
jobs:
  test:
    runs-on: ubuntu-22.04
    strategy:
      fail-fast: false
      matrix:
        node: [22, 24]
    name: Node ${{ matrix.node }}
    steps:
      - uses: actions/checkout@v2

      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node }}

      - run: npm install

      - name: Setup
        run: |
          wget -q http://downloads.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-8.0.7.tgz
          tar xf mongodb-linux-x86_64-ubuntu2204-8.0.7.tgz
          mkdir -p ./data/db/27017 ./data/db/27000
          printf "\n--timeout 8000" >> ./test/mocha.opts
          ./mongodb-linux-x86_64-ubuntu2204-8.0.7/bin/mongod --fork --dbpath ./data/db/27017 --syslog --port 27017
          sleep 2
          echo `pwd`/mongodb-linux-x86_64-ubuntu2204-8.0.7/bin >> $GITHUB_PATH

      - run: npm test

  lint:
    runs-on: ubuntu-latest
    name: Linter
    steps:
      - uses: actions/checkout@v2

      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: 22

      - run: npm install

      - name: Linter
        run: npm run lint
