Skip to content

Instantly share code, notes, and snippets.

@johnkors
Created May 2, 2013 09:02
Show Gist options
  • Save johnkors/5501060 to your computer and use it in GitHub Desktop.
Save johnkors/5501060 to your computer and use it in GitHub Desktop.
Powershell script to install karma test runner on Windows. This uses Chocolatey to install node.js, but could also be done by downloading the msi. The script needs to be run with Administrator privileges.
# helper to update ps sessions env variables
function Update-Environment {
$locations = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
'HKCU:\Environment'
$locations | ForEach-Object {
$k = Get-Item $_
$k.GetValueNames() | ForEach-Object {
$name = $_
$value = $k.GetValue($_)
if ($userLocation -and $name -ieq 'PATH') {
Env:\Path += ";$value"
} else {
Set-Item -Path Env:\$name -Value $value
}
}
$userLocation = $true
}
}
# Needed to run remote scripts
Set-ExecutionPolicy Unrestricted
# Install Chocolatey
$chocolateyInstallScriptUrl = "https://raw.github.com/chocolatey/chocolatey/master/chocolateyInstall/InstallChocolatey.ps1"
iex ((new-object net.webclient).DownloadString($chocolateyInstallScriptUrl))
write-host "**** INSTALLED CHOCOLATEY *****"
# Install node.js via Chocolatey
& cinst NodeJs.install
write-host "**** INSTALLED NODE.JS *****"
# Update Env variables in session so npm is available
Update-Environment
# Install karma test-runner from node package manager (npm) into global node_modules
& powershell -command {npm install -g karma}
write-host "**** INSTALLED KARMA *****"
# Set ENV variables for browsers, due to a bug in karma on Windows:
$CHROME_BIN = "C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe"
$FIREFOX_BIN = "C:\Program Files (x86)\Mozilla Firefox\Firefox.exe"
[Environment]::SetEnvironmentVariable("CHROME_BIN", $CHROME_BIN, "User")
[Environment]::SetEnvironmentVariable("FIREFOX_BIN", $FIREFOX_BIN, "User")
write-host "**** ADDED BROWSERS TO USER ENV VARIABLES *****"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment