|
| 1 | +# Copyright (c) Microsoft Corporation. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +Import-Module HelpersCommon |
| 5 | +$moduleRootFilePath = Split-Path -Path $PSScriptRoot -Parent |
| 6 | + |
| 7 | +# Identify the repository root path of the resource module |
| 8 | +$repoRootPath = (Resolve-Path -LiteralPath (Join-Path $moduleRootFilePath "../..")).ProviderPath |
| 9 | +$repoRootPathFound = $false |
| 10 | + |
| 11 | +Describe 'Common Tests - Validate Markdown Files' -Tag 'CI' { |
| 12 | + BeforeAll { |
| 13 | + Push-Location $psscriptroot |
| 14 | + $skip = $false |
| 15 | + $NpmInstalled = "not installed" |
| 16 | + if (Get-Command -Name 'yarn' -ErrorAction SilentlyContinue) |
| 17 | + { |
| 18 | + $NpmInstalled = "Installed" |
| 19 | + Write-Verbose -Message "Checking if Gulp is installed. This may take a few moments." -Verbose |
| 20 | + start-nativeExecution { yarn } |
| 21 | + if(!(Get-Command -Name 'gulp' -ErrorAction SilentlyContinue)) |
| 22 | + { |
| 23 | + start-nativeExecution { |
| 24 | + sudo yarn global add '[email protected]' |
| 25 | + } |
| 26 | + } |
| 27 | + if(!(Get-Command -Name 'node' -ErrorAction SilentlyContinue)) |
| 28 | + { |
| 29 | + throw "node not found" |
| 30 | + } |
| 31 | + } |
| 32 | + if(!(Get-Command -Name 'node' -ErrorAction SilentlyContinue)) |
| 33 | + { |
| 34 | + <# |
| 35 | + On Windows, pre-requisites are missing |
| 36 | + For now we will skip, and write a warning. Work to resolve this is tracked in: |
| 37 | + https://github.com/PowerShell/PowerShell/issues/3429 |
| 38 | + #> |
| 39 | + Write-Warning "Node and yarn are required to run this test" |
| 40 | + $skip = $true |
| 41 | + } |
| 42 | + |
| 43 | + $mdIssuesPath = Join-Path -Path $PSScriptRoot -ChildPath "markdownissues.txt" |
| 44 | + Remove-Item -Path $mdIssuesPath -Force -ErrorAction SilentlyContinue |
| 45 | + } |
| 46 | + |
| 47 | + AfterAll { |
| 48 | + Pop-Location |
| 49 | + } |
| 50 | + |
| 51 | + It "Should not have errors in any markdown files" -Skip:$skip { |
| 52 | + $NpmInstalled | Should -BeExactly "Installed" |
| 53 | + $mdErrors = 0 |
| 54 | + Push-Location -Path $PSScriptRoot |
| 55 | + try |
| 56 | + { |
| 57 | + $docsToTest = @( |
| 58 | + './.github/*.md' |
| 59 | + './README.md' |
| 60 | + './demos/python/*.md' |
| 61 | + './docker/*.md' |
| 62 | + './docs/building/*.md' |
| 63 | + './docs/community/*.md' |
| 64 | + './docs/host-powershell/*.md' |
| 65 | + './docs/cmdlet-example/*.md' |
| 66 | + './docs/maintainers/*.md' |
| 67 | + './test/powershell/README.md' |
| 68 | + './tools/*.md' |
| 69 | + './.github/ISSUE_TEMPLATE/*.md' |
| 70 | + ) |
| 71 | + $filter = ($docsToTest -join ',') |
| 72 | + |
| 73 | + # Gulp 4 beta is returning non-zero exit code even when there is not an error |
| 74 | + Start-NativeExecution { |
| 75 | + &"gulp" test-mdsyntax --silent ` |
| 76 | + --rootpath $repoRootPath ` |
| 77 | + --filter $filter |
| 78 | + } -VerboseOutputOnError -IgnoreExitcode |
| 79 | + |
| 80 | + } |
| 81 | + finally |
| 82 | + { |
| 83 | + Pop-Location |
| 84 | + } |
| 85 | + |
| 86 | + $mdIssuesPath | Should -Exist |
| 87 | + |
| 88 | + [string[]] $markdownErrors = Get-Content -Path $mdIssuesPath |
| 89 | + Remove-Item -Path $mdIssuesPath -Force -ErrorAction SilentlyContinue |
| 90 | + |
| 91 | + if ($markdownErrors -ne "--EMPTY--") |
| 92 | + { |
| 93 | + $markdownErrors += ' (See https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md for an explanation of the error codes)' |
| 94 | + } |
| 95 | + |
| 96 | + $markdownErrors | Write-Host |
| 97 | + |
| 98 | + $markdownErrors -join "`n" | Should -BeExactly "--EMPTY--" |
| 99 | + } |
| 100 | +} |
0 commit comments