Skip to content

Commit

Permalink
build,test: add test-npm.ps1 to test npm on windows
Browse files Browse the repository at this point in the history
test-npm.ps1 should mimic test-npm.sh on Windows.

Also adds the test-npm target to vcbuild.bat
  • Loading branch information
gibfahn committed Jan 24, 2017
1 parent 390b74c commit 66bb063
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tools/test-npm.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Port of tools/test-npm.sh to windows

# Handle parameters
param (
[string]$progress = "classic",
[string]$logfile
)

# Always change the working directory to the project's root directory
$dp0 = (Get-Item -Path ".\" -Verbose).FullName
cd $~dp0\..

# Use rmdir to get around long file path issues
Cmd /C "rmdir /S /Q test-npm"
Remove-Item test-npm.tap -ErrorAction SilentlyContinue

# Make a copy of deps/npm to run the tests on
Copy-Item deps\npm test-npm -Recurse
cd test-npm

# Do a rm first just in case deps/npm contained these
Remove-Item npm-cache -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item npm-tmp -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item npm-prefix -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item npm-userconfig -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item npm-home -Force -Recurse -ErrorAction SilentlyContinue

New-Item -ItemType directory -Path npm-cache
New-Item -ItemType directory -Path npm-tmp
New-Item -ItemType directory -Path npm-prefix
New-Item -ItemType directory -Path npm-userconfig
New-Item -ItemType directory -Path npm-home

# Set some npm env variables to point to our new temporary folders
$pwd = (Get-Item -Path ".\" -Verbose).FullName
Set-Variable -Name npm_config_cache -value ("$pwd\npm-cache") -Scope Global
Set-Variable -Name npm_config_prefix -value ("$pwd\npm-prefix") -Scope Global
Set-Variable -Name npm_config_tmp -value ("$pwd\npm-tmp") -Scope Global
Set-Variable -Name npm_config_userconfig -value ("$pwd\npm-userconfig") -Scope Global
Set-Variable -Name home -value ("$pwd\npm-home") -Scope Global -Force

# Ensure npm always uses the local node
Set-Variable -Name NODEPATH -value (Get-Item -Path "..\Release" -Verbose).FullName
$env:Path = ("$NODEPATH;$env:Path")
Remove-Variable -Name NODEPATH -ErrorAction SilentlyContinue

# Make sure the binaries from the non-dev-deps are available
node cli.js rebuild
# Install npm devDependencies and run npm's tests
node cli.js install --ignore-scripts

# Run the tests with logging if set
if ($logfile -eq $null)
{
node cli.js run test-node -- --reporter=$progress
} else {
node cli.js run test-node -- --reporter=$progress 2>&1 | Tee-Object -FilePath "..\$logfile"
}

# Move npm-debug.log out of test-npm so it isn't cleaned up
if (Test-Path -path "npm-debug.log") {
Move-Item npm-debug.log ..
}

# Clean up everything in one single shot
cd ..
Cmd /C "rmdir /S /Q test-npm"
9 changes: 9 additions & 0 deletions vcbuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ if /i "%1"=="test-tick-processor" set test_args=%test_args% tick-processor&goto
if /i "%1"=="test-internet" set test_args=%test_args% internet&goto arg-ok
if /i "%1"=="test-pummel" set test_args=%test_args% pummel&goto arg-ok
if /i "%1"=="test-all" set test_args=%test_args% sequential parallel message gc inspector internet pummel&set buildnodeweak=1&set jslint=1&goto arg-ok
if /i "%1"=="test-npm" set test_args=%test_args% npm&goto arg-ok
if /i "%1"=="test-known-issues" set test_args=%test_args% known_issues&goto arg-ok
if /i "%1"=="jslint" set jslint=1&goto arg-ok
if /i "%1"=="jslint-ci" set jslint_ci=1&goto arg-ok
Expand Down Expand Up @@ -334,6 +335,13 @@ goto run-tests

:run-tests
if "%test_args%"=="" goto jslint

if "%test_args%"=="%test_args:npm=%" goto node-tests
set test_args="%test_args:npm=%"
powershell .\tools\test-npm.ps1 -progress tap -logfile test-npm.tap
goto exit

:node-tests
if "%config%"=="Debug" set test_args=--mode=debug %test_args%
if "%config%"=="Release" set test_args=--mode=release %test_args%
echo running 'cctest %cctest_args%'
Expand Down Expand Up @@ -371,6 +379,7 @@ echo vcbuild.bat : builds release build
echo vcbuild.bat debug : builds debug build
echo vcbuild.bat release msi : builds release build and MSI installer package
echo vcbuild.bat test : builds debug build and runs tests
echo vcbuild.bat test-npm : builds debug build and runs test-npm.bat
echo vcbuild.bat build-release : builds the release distribution as used by nodejs.org
echo vcbuild.bat enable-vtune : builds nodejs with Intel VTune profiling support to profile JavaScript
goto exit
Expand Down

0 comments on commit 66bb063

Please sign in to comment.