AL/Test-AppJsonFile.ps1

function Test-AppJsonFile {
    param (
        # Source path of app code
        [Parameter(Mandatory = $false)]
        [string]
        $SourcePath = (Get-Location),
        # Do not throw an error
        [Parameter(Mandatory = $false)]
        [switch]
        $SuppressError
    )
    
    $TestDependencyExists = $null -ne (Get-AppKeyValue $SourcePath 'test')
    foreach ($testapp in (Get-EnvironmentKeyValue $SourcePath 'testapps')) {
        if ($null -ne $testapp.appId) {
            if ($null -ne (Get-AppKeyValue $SourcePath 'dependencies' | Where-Object appId -eq $testapp.appId)) {
                $TestDependencyExists = $true
                break
            }
        }
        else {
            if ($null -ne (Get-AppKeyValue $SourcePath 'dependencies' | Where-Object id -eq $testapp.id)) {
                $TestDependencyExists = $true
                break
            }
        }
    }
    
    if (!$TestDependencyExists) {
        $TestDependencyExists = $null -ne (Get-AppKeyValue $SourcePath 'dependencies' | Where-Object {
                ($_.publisher -eq 'Microsoft') -and ($_.name -eq 'Tests-TestLibraries' -or $_.name -eq 'Library Assert') })
    }

    if ($TestDependencyExists) {
        if ($SuppressError.IsPresent) {
            return $false
        }
        else {
            throw 'app.json contains test dependencies'
        }
    }

    return $true
}