Skip to content

Instantly share code, notes, and snippets.

@soutarm
Last active May 10, 2018 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save soutarm/4ebafc4951811e68e1bbe00f172a53d4 to your computer and use it in GitHub Desktop.
Save soutarm/4ebafc4951811e68e1bbe00f172a53d4 to your computer and use it in GitHub Desktop.
AppVeyor PS function for running tests against Ghost Inspector. e.g. RunTest -suiteId '123xyz' -testName 'My Tests' -apiKey 'abc123'
Function RunTest {
Param ([string]$suiteId, [string]$testName, [string]$apiKey)
Process {
Write-Host -backgroundcolor White -foregroundcolor Black ' - Running'$testName' - '
$uri = 'https://api.ghostinspector.com/v1/suites/' + $suiteId + '/execute/?apiKey=' + $apiKey
$resp = Invoke-RestMethod -Method Get -Uri $uri
$resultUri = 'https://app.ghostinspector.com/suite-results/' + $resp.data.suiteResult[0]
if ($resp.data.passing.Contains($false)) {
# display each failed test
for($i=0; $i -lt $resp.data.passing.length; $i++) {
if (!$resp.data.passing[$i]) {
Add-AppveyorTest -Name $resp.data.testName[$i] -Framework 'Ghost Inspector' -FileName 'app.js' -Outcome Failed -Duration $resp.data.executionTime[$i]
}
}
throw ' - ' + $testName + ' FAILED - ' + $resultUri + ' - '
} else {
$duration = ($resp.data.executionTime | measure -Maximum).maximum
Add-AppveyorTest -Name $testName -Framework 'Ghost Inspector' -FileName 'app.js' -Outcome Passed -Duration $duration
Write-Host -foregroundcolor Green ' -'$testName' PASSED - '$resultUri' - '
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment