-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spelling: Remove deprecated --no-install, replace with --no #9013
Open
danieljurek
wants to merge
9
commits into
main
Choose a base branch
from
djurek/spelling-npx-no
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b9f5245
Spelling: Remove deprecated --no-install, replace with --no
danieljurek 1cd5f29
Extract testing, use npm exec instead of npx
danieljurek 309ace6
Move tests to eng/common-tests/
danieljurek 6487f69
Tag tests
danieljurek 93511cb
Ensure .vscode/cspell.json exists for tests
danieljurek 06a1a70
Add git identity in cases where it's not already present (Windows)
danieljurek d78a3a4
Disable unnecessary errors
danieljurek f8a820e
Cleanup, documentation
danieljurek cb5556f
More cleanup
danieljurek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Describe 'Tool Version' { | ||
BeforeAll { | ||
$ShouldCleanUpVscodeDirectory = $false | ||
|
||
$cspellConfigPath = "$PSScriptRoot/../../../.vscode/cspell.json" | ||
if (!(Test-Path $cspellConfigPath)) { | ||
$ShouldCleanUpVscodeDirectory = $true | ||
|
||
$vscodeDirectory = Split-Path $cspellConfigPath -Parent | ||
New-Item -ItemType Directory -Path $vscodeDirectory -Force | Out-Null | ||
$configJsonContent = @" | ||
{ | ||
"version": "0.2", | ||
"language": "en", | ||
"ignorePaths": [ | ||
".vscode/cspell.json", | ||
] | ||
} | ||
"@ | ||
$configJsonContent > $cspellConfigPath | ||
} | ||
} | ||
|
||
AfterAll { | ||
if ($ShouldCleanUpVscodeDirectory) { | ||
Remove-Item -Path $vscodeDirectory -Recurse -Force | Out-Null | ||
} | ||
} | ||
|
||
It 'Should have the correct version' -Tag 'UnitTest' { | ||
# Arrange | ||
$expectedPackageVersion = '6.31.2' | ||
|
||
# Act | ||
$actual = &"$PSScriptRoot/../../common/spelling/Invoke-Cspell.ps1" ` | ||
-JobType '--version' | ||
|
||
# Assert | ||
$actual | Should -Be $expectedPackageVersion | ||
} | ||
} |
196 changes: 196 additions & 0 deletions
196
eng/common-tests/spelling/check-spelling-in-changed-files.tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
Describe 'Spell checking' -Tag 'UnitTest' { | ||
BeforeAll { | ||
$workingDirectory = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName()) | ||
|
||
Write-Host "Create test temp dir: $workingDirectory" | ||
New-Item -ItemType Directory -Force -Path $workingDirectory | Out-Null | ||
|
||
Push-Location $workingDirectory | Out-Null | ||
git init | ||
|
||
# Set up git user information for this specific repo if no user | ||
# information is set globally. Windows DevOps machines do not have a | ||
# global git identity set. | ||
if (!(git config --get user.email)) { | ||
git config user.email "test@contoso.com" | ||
} | ||
if (!(git config --get user.name)) { | ||
git config user.name "Test User" | ||
} | ||
|
||
New-Item -ItemType Directory -Force -Path "./excluded" | ||
New-Item -ItemType Directory -Force -Path "./included" | ||
New-Item -ItemType Directory -Force -Path "./.vscode" | ||
|
||
"Placeholder" > "./excluded/placeholder.txt" | ||
"Placeholder" > "./included/placeholder.txt" | ||
|
||
$configJsonContent = @" | ||
{ | ||
"version": "0.2", | ||
"language": "en", | ||
"ignorePaths": [ | ||
".vscode/cspell.json", | ||
"excluded/**" | ||
] | ||
} | ||
"@ | ||
$configJsonContent > "./.vscode/cspell.json" | ||
|
||
git add -A | ||
git commit -m "Init" | ||
|
||
# This forces normal Write-Error behavior (as seen on desktop) for | ||
# errors encountered during testing of | ||
# check-spelling-in-changed-files.ps1. Setting this keeps errors out of | ||
# the DevOps logs for successful tests. Any errors produced by these | ||
# tests are expected or will result in test failures. | ||
$OriginalTeamProjectId = $env:SYSTEM_TEAMPROJECTID | ||
$env:SYSTEM_TEAMPROJECTID = $null | ||
Comment on lines
+43
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed to prevent DevOps from showing a bunch of fake error messages produced by the testing. |
||
} | ||
|
||
AfterAll { | ||
Pop-Location | Out-Null | ||
Write-Host "Remove test temp dir: $workingDirectory" | ||
Remove-Item -Path $workingDirectory -Recurse -Force | Out-Null | ||
|
||
$env:SYSTEM_TEAMPROJECTID = $OriginalTeamProjectId | ||
} | ||
|
||
BeforeEach { | ||
$initCommit = git rev-parse HEAD | ||
} | ||
|
||
AfterEach { | ||
# Empty out the working tree | ||
git checkout . | ||
git clean -xdf | ||
|
||
$revCount = git rev-list --count HEAD | ||
if ($revCount -gt 1) { | ||
# Reset N-1 changes so there is only the initial commit | ||
$revisionsToReset = $revCount - 1 | ||
git reset --hard HEAD~$revisionsToReset | ||
} | ||
} | ||
|
||
|
||
It 'Exits 0 when all files are excluded' { | ||
# Arrange | ||
"sepleing errrrrorrrrr" > ./excluded/excluded-file.txt | ||
git add -A | ||
git commit -m "One change" | ||
|
||
# Act | ||
&"$PSScriptRoot/../../common/scripts/check-spelling-in-changed-files.ps1" ` | ||
-CspellConfigPath "./.vscode/cspell.json" ` | ||
-SpellCheckRoot "./" ` | ||
-ExitWithError ` | ||
-SourceCommittish (git rev-parse HEAD) ` | ||
-TargetCommittish $initCommit | ||
|
||
# Assert | ||
$LASTEXITCODE | Should -Be 0 | ||
} | ||
|
||
It 'Exits 1 when included file has spelling error' { | ||
# Arrange | ||
"sepleing errrrrorrrrr" > ./included/included-file.txt | ||
git add -A | ||
git commit -m "One change" | ||
|
||
# Act | ||
&"$PSScriptRoot/../../common/scripts/check-spelling-in-changed-files.ps1" ` | ||
-CspellConfigPath "./.vscode/cspell.json" ` | ||
-SpellCheckRoot "./" ` | ||
-ExitWithError ` | ||
-SourceCommittish (git rev-parse HEAD) ` | ||
-TargetCommittish $initCommit | ||
|
||
# Assert | ||
$LASTEXITCODE | Should -Be 1 | ||
} | ||
|
||
It 'Exits 0 when included file has no spelling error' { | ||
# Arrange | ||
"correct spelling" > ./included/included-file.txt | ||
git add -A | ||
git commit -m "One change" | ||
|
||
# Act | ||
&"$PSScriptRoot/../../common/scripts/check-spelling-in-changed-files.ps1" ` | ||
-CspellConfigPath "./.vscode/cspell.json" ` | ||
-SpellCheckRoot "./" ` | ||
-ExitWithError ` | ||
-SourceCommittish (git rev-parse HEAD) ` | ||
-TargetCommittish $initCommit | ||
|
||
# Assert | ||
$LASTEXITCODE | Should -Be 0 | ||
} | ||
|
||
It 'Exits 1 when changed file already has spelling error' { | ||
# Arrange | ||
"sepleing errrrrorrrrr" > ./included/included-file.txt | ||
git add -A | ||
git commit -m "First change" | ||
|
||
"A statement without spelling errors" >> ./included/included-file.txt | ||
git add -A | ||
git commit -m "Second change" | ||
|
||
# Act | ||
&"$PSScriptRoot/../../common/scripts/check-spelling-in-changed-files.ps1" ` | ||
-CspellConfigPath "./.vscode/cspell.json" ` | ||
-SpellCheckRoot "./" ` | ||
-ExitWithError ` | ||
-SourceCommittish (git rev-parse HEAD) ` | ||
-TargetCommittish $initCommit | ||
|
||
# Assert | ||
$LASTEXITCODE | Should -Be 1 | ||
} | ||
|
||
It 'Exits 0 when unaltered file has spelling error' { | ||
# Arrange | ||
"sepleing errrrrorrrrr" > ./included/included-file-1.txt | ||
git add -A | ||
git commit -m "One change" | ||
|
||
# Use baseCommit instead of initCommit to simulate a scenario where the | ||
# file with the spelling error is already checked in. | ||
$baseCommit = git rev-parse HEAD | ||
|
||
"A statement without spelling errors" > ./included/included-file-2.txt | ||
git add -A | ||
git commit -m "Second change" | ||
|
||
# Act | ||
&"$PSScriptRoot/../../common/scripts/check-spelling-in-changed-files.ps1" ` | ||
-CspellConfigPath "./.vscode/cspell.json" ` | ||
-SpellCheckRoot "./" ` | ||
-ExitWithError ` | ||
-SourceCommittish (git rev-parse HEAD) ` | ||
-TargetCommittish $baseCommit | ||
|
||
# Assert | ||
$LASTEXITCODE | Should -Be 0 | ||
} | ||
|
||
It 'Exits 0 when spelling errors and no ExitWithError' { | ||
# Arrange | ||
"sepleing errrrrorrrrr" > ./included/included-file-1.txt | ||
git add -A | ||
git commit -m "One change" | ||
|
||
# Act | ||
&"$PSScriptRoot/../../common/scripts/check-spelling-in-changed-files.ps1" ` | ||
-CspellConfigPath "./.vscode/cspell.json" ` | ||
-SpellCheckRoot "./" ` | ||
-SourceCommittish (git rev-parse HEAD) ` | ||
-TargetCommittish $initCommit | ||
|
||
# Assert | ||
$LASTEXITCODE | Should -Be 0 | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weshaggard -- This is done in lieu of adding a .vscode/cspell.json file to this repo's root.