version: "{build}"

environment:
  matrix:
    - nodejs_version: "18"
    - nodejs_version: "20"
    - nodejs_version: "21"

branches:
  only:
    - master
    - /^maint\/.+/
    - /v\d+\.\d+\.\d+/

install:
  - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version)
  - npm install

services:
  - mssql2017

cache:
  - node_modules

build: off

before_test:
  - npm prune

  - sc config sqlbrowser start= auto
  - net start sqlbrowser

test_script:
  - node --version
  - npm --version

  - pwsh: |-
      $ErrorActionPreference = "Stop"

      npm run-script test
      if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }

      Copy-Item -Force test/config.appveyor.ts test/config.ts

      $env:NTLM_USERNAME = $env:USERNAME
      $env:NTLM_PASSWORD = [Microsoft.Win32.Registry]::GetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", '')
      $env:NTLM_DOMAIN = $env:COMPUTERNAME

      $env:TEDIOUS_TDS_VERSION = '7_4'
      npm run-script test-integration
      if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }

      $env:TEDIOUS_TDS_VERSION = '7_3_B'
      npm run-script test-integration
      if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }

      $env:TEDIOUS_TDS_VERSION = '7_3_A'
      npm run-script test-integration
      if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }

      $env:TEDIOUS_TDS_VERSION = '7_2'
      npm run-script test-integration
      if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }

      $env:TEDIOUS_TDS_VERSION = '7_1'
      npm run-script test-integration
      if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
