Skip to content

Commit

Permalink
Changes to markdown test
Browse files Browse the repository at this point in the history
Fixed the markdown test so that node_modules can be deleted when path contains an apostrophe (issue PowerShell#166).
  • Loading branch information
johlju committed Aug 8, 2017
1 parent 11a0885 commit 5e7dcb3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 58 deletions.
105 changes: 72 additions & 33 deletions Meta.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -733,27 +733,47 @@ Describe 'Common Tests - Validate Markdown Files' -Tag 'Markdown' {

if (Get-Command -Name 'npm' -ErrorAction SilentlyContinue)
{
Write-Warning -Message "NPM is checking Gulp is installed. This may take a few moments."

$null = Start-Process `
-FilePath "npm" `
-ArgumentList @('install','--silent') `
-Wait `
-WorkingDirectory $PSScriptRoot `
-PassThru `
-NoNewWindow
$null = Start-Process `
-FilePath "npm" `
-ArgumentList @('install','-g','gulp','--silent') `
-Wait `
-WorkingDirectory $PSScriptRoot `
-PassThru `
-NoNewWindow
$npmAdditionalAdditionalParametersForStartProcess = @{
FilePath = 'npm'
ArgumentList = ''
WorkingDirectory = $PSScriptRoot
Wait = $true
WindowStyle = 'Hidden'
}

It 'Should not throw an error when installing dependencies' {
Write-Verbose -Message "NPM is checking Gulp is installed. This may take a few moments." -Verbose

{
<#
gulp; gulp is a toolkit that helps you automate painful or time-consuming tasks in your development workflow.
gulp must be installed globally to be able to be called through Start-Process
#>
$npmAdditionalAdditionalParametersForStartProcess['ArgumentList'] = 'install -g gulp'
Start-Process @npmAdditionalAdditionalParametersForStartProcess

# gulp must also be installed locally to be able to be referenced in the javascript file.
$npmAdditionalAdditionalParametersForStartProcess['ArgumentList'] = 'install gulp'
Start-Process @npmAdditionalAdditionalParametersForStartProcess

# Used in gulpfile.js; A tiny wrapper around Node streams2 Transform to avoid explicit sub classing noise
$npmAdditionalAdditionalParametersForStartProcess['ArgumentList'] = 'install through2'
Start-Process @npmAdditionalAdditionalParametersForStartProcess

# Used in gulpfile.js; A Node.js style checker and lint tool for Markdown/CommonMark files.
$npmAdditionalAdditionalParametersForStartProcess['ArgumentList'] = 'install markdownlint'
Start-Process @npmAdditionalAdditionalParametersForStartProcess

# gulp-concat is installed as devDependencies. Used in gulpfile.js; Concatenates files
$npmAdditionalAdditionalParametersForStartProcess['ArgumentList'] = 'install gulp-concat -D'
Start-Process @npmAdditionalAdditionalParametersForStartProcess
} | Should Not Throw
}

if (Test-Path -Path (Join-Path -Path $repoRootPath -ChildPath '.markdownlint.json'))
{
Write-Verbose -Message ('Using markdownlint settings file from repository folder ''{0}''.' -f $repoRootPath) -Verbose
$markdownlintSettingsFilePath = Join-Path -Path $repoRootPath -Childpath '.markdownlint.json'
$markdownlintSettingsFilePath = Join-Path -Path $repoRootPath -ChildPath '.markdownlint.json'
}
else
{
Expand Down Expand Up @@ -808,28 +828,47 @@ Describe 'Common Tests - Validate Markdown Files' -Tag 'Markdown' {
"run 'npm install -g gulp' in order to have this " + `
"text execute.")
}

if ($optIn)
{
$mdErrors | Should Be 0
}
}

# We're using this tool to delete the node_modules folder because it gets too long
# for PowerShell to remove.
$null = Start-Process `
-FilePath "npm" `
-ArgumentList @('install','rimraf','-g','--silent') `
-Wait `
-WorkingDirectory $PSScriptRoot `
-PassThru `
-NoNewWindow
$null = Start-Process `
-FilePath "rimraf" `
-ArgumentList @(Join-Path -Path $PSScriptRoot -ChildPath 'node_modules') `
-Wait `
-WorkingDirectory $PSScriptRoot `
-PassThru `
-NoNewWindow
<#
We're uninstalling the dependencies so that the node_modules folder
do not linger on a users computer if run locally.
Also, this fixes so that when there is a apostrophe in the path for
$PSScriptRoot, the node_modules folder is correctly removed.
#>
It 'Should not throw an error when uninstalling dependencies' {
Write-Verbose -Message "NPM is uninstalling Gulp. This may take a few moments." -Verbose

{
# Uninstalled npm packages in reverse order
$npmAdditionalAdditionalParametersForStartProcess['ArgumentList'] = 'uninstall gulp-concat -D'
Start-Process @npmAdditionalAdditionalParametersForStartProcess

$npmAdditionalAdditionalParametersForStartProcess['ArgumentList'] = 'uninstall markdownlint'
Start-Process @npmAdditionalAdditionalParametersForStartProcess

$npmAdditionalAdditionalParametersForStartProcess['ArgumentList'] = 'uninstall through2'
Start-Process @npmAdditionalAdditionalParametersForStartProcess

$npmAdditionalAdditionalParametersForStartProcess['ArgumentList'] = 'uninstall gulp'
Start-Process @npmAdditionalAdditionalParametersForStartProcess

$npmAdditionalAdditionalParametersForStartProcess['ArgumentList'] = 'uninstall -g gulp'
Start-Process @npmAdditionalAdditionalParametersForStartProcess

# Remove folder node_modules that npm created.
$npmNodeModulesPath = (Join-Path -Path $PSScriptRoot -ChildPath 'node_modules')
if( Test-Path -Path $npmNodeModulesPath)
{
Remove-Item -Path $npmNodeModulesPath -Recurse -Force
}
} | Should Not Throw
}
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ Invoke-AppveyorAfterTestTask `
* Change README.md to resolve lint error MD029 and MD036.
* Added module manifest for manifest common tests to pass.
* Added status badges to README.md.
* Fixed the markdown test so that node_modules can be deleted when path contains
an apostrophe ([issue #166](https://github.com/PowerShell/DscResource.Tests/issues/166)).

### 0.2.0.0

Expand Down
25 changes: 0 additions & 25 deletions package.json

This file was deleted.

0 comments on commit 5e7dcb3

Please sign in to comment.