Efficient way to run PowerShell Pester tests from Sublime Text - powershell

I'm using Sublime Text (ST) to create my PowerShell scripts, Pester to test them.
To run test script, one must to switch to that tab, then press CTRL + B. This process must be repeated for each test script.
Is there an easy way to Sublime Text to run all of the tests in the project's directory?
Is there a way to have these test automatically run when a script or test changes (similar to guard)?

I added a script named Tests.ps1 to the project's directory with a single instruction:
Invoke-Pester
To run all tests, I open this file and press Ctrl+B.
** edit **
Created a new build system named 'Pester'. The contents of Pester.sublimebuild:
{
"cmd": ["powershell.exe", "-noprofile", "Invoke-Pester"],
"selector": "source.powershell"
}
To run all tests, press Ctrl+B.
If this doesn't work automatically, assign Pester as the build system using Tools | Build System | Pester and try again.

Related

How to build AHK scripts automatically on startup?

Each time I restart my computer, I have to rebuild all my AHK Scripts so the keyboard shortcuts will work.
For instance, I have a script that assigns Ctrl+j to set up an instance of the MEAN stack and open my web site. After restarting my computer, pressing ^j does nothing until I go into Sublime and ^b (Build). I could build from AHK, but I do a lot of work in Sublime, so it's easier to build there.
How can my AHK Scripts automatically build on startup?
What I've tried so far:
Looking to build a post startup, startup script: This Is concerned with using an AHK script to start many programs on starup. I use Windows' Task Manager > Startup to do this, thus has nothing to do with making. I want to not have to rebuild all my scripts after every restart.
Windows 10 - run script on windows startup problem: This assumes the start script is already written and implemented. However, it doesn't appear to give the script.
AutoHotKey FAQ: I eventually found a solution here, but it took a long time to dig through the questions so I figured I'd post a question anyway to help others who run into this.
Simply add a shortcut (don't need to be the actual file) of your script in the Windows 'Startup' folder.
Three ways to get there:
1- In Windows Explorer, go to %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup (for current user startup list) or %ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Startup (for every user startup list)
or
2- Open Windows' Run application (Windows + r) write shell:startup (current user) or shell:common startup (every user) in the edit field and click on the 'ok' button.
or
3- Start > Programs > Startup (old Windows versions)
In AutoHotKey you can access this folder with the Built-in Variables %A_Startup% (current user) or %A_StartupCommon% (every user)
To create the (current user) shortcut automatically from your script, use the following line:
FileCreateShortcut, %A_ScriptFullPath%, %A_Startup%\shortcutname.lnk
To do the same for all users, use this line instead:
FileCreateShortcut, %A_ScriptFullPath%, %A_StartupCommon%\shortcutname.lnk
(in the case of having a file with the same name in the folder, the file would be overwritten)
ps: Win10 blocks scripts in startup with AHK running as admin... read the comments of this post for extra info.
Run at startup in Windows 10:
Compile the script to *.exe
Put the shortcut of that exe in startup folder "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup"
That's all. Do NOT set it to run as admin. Programs in Win10 don't run at startup which are marked as run as admin.
Run Script as admin at Startup in Windows 10:
Go to ahk script and mark it run as admin.
Create the VBScript using a text editor
'put it in startup folder to run the mentioned ahk script at startup
Set WshShell = CreateObject("WScript.Shell" )
WshShell.Run """C:\Users\jerry\Downloads\scripts\some_script.ahk""", 0 'Must quote command if it has spaces; must escape quotes
Set WshShell = Nothing
Replace C:\Users\jerry\Downloads\scripts\some_script.ahk with the path to your script with extension and save it as .vbs.
Place this .vbs script at startup folder %appdata%\Microsoft\Windows\Start Menu\Programs\Startup
PS: My fav AHK scripts: https://gourav.io/blog/autohotkey-scripts-windows
Open note pad or any other text editor
write Start "" "C:\ahk\yourdirectory\yourahk.ahk"
press save as
navigate to %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup
name the filename anything.bat
As a Windows 7 user, I have limited experience with Windows 10. I have heard that W10 can be finicky with regard to running programs underground administratie or limited user. In W7, you just add the .AHK file link to the startup dir.
A simple solution without writing any code, using the Windows Task Scheduler, set the script to start when the user logs on. If it is set to system startup it will error because it is too early.
To allow the script to automate administrative programs without running as admin, here're the required steps:
When installing AHK, check the "Add 'Run with UI Access' to context menus" option.
After installation, find AutoHotkeyU64_UIA.exe on your disk.
Open the .ahk script's properties, change the "Open with" option to the AutoHotkeyU64_UIA.exe you just found.
Create a shortcut to this script.
Open %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup in the file explorer.
Move that shortcut to this folder.
And you're done.
How does it work?
The "Add 'Run with UI Access' to context menus" option provides a workaround for common UAC-related issues by allowing the script to automate administrative programs without running as admin.
Reference: Run with UI Access.
Open windows run (win+r) and type “shelll:startup”
Copy paste the ahk file into there
Close the folder
And that‘s all!

MSTest from command line

I am trying to run MSTest from command line in powershell.
mstest /testcontainer:Common.Tests.dll
I am in the project bin/debug folder. It opens a new command window and the window closes either with no output or output that I can't read, as a result of the window immediately closing. The test run successfully in Visual Studio and the project builds successfully using MSBuild and in Visual Studio. I assume that something is breaking but I have no idea how to determine what it could be.
I am using VS 14.0.
I have also tried vstest.console with the same result.
Well, one way to do that would be:
mstest /testcontainer:Common.Tests.dll > result.txt 2>&1
that would redirect all output to the result.txt
You can assign the output to a variable and then use it however you wish, like just outputting it to screen...
$mstest = Invoke-Expression "mstest /testcontainer:Common.Tests.dll"
Write-Output $mstest

Run powershell without 'run script'

I have a powershell file (folderWatcher.ps1), which I run using powershell ISE.
I have placed 'folderWatcher.ps1' in my startup folder, so the file opens up when the machine is switched on.
However, the script does not run unless I select the "Run Script" button (or F5) once.
(After that the script runs perfectly till the machine is shut down.)
Now, my query is: How do I run the script without selecting "Run script" button ? -- All my tasks in this process are automated, except the "Run script".
Instead of placing the PS1 file in your start-up folder place a shortcut there.
I have tested the following successfully:
In the folder
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
I created a windows shortcut with this text in the target:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file C:\Scripts\FolderWatcher.ps1
This script ran without prompting at log on.

Program group item with custom command line for different Launchers

I am using install4j to install an exe program and associated files. This is a cross platform C# program that can be run with Mono on Linux/Mac or just run as is on Windows. I am not finding any examples on creating a desktop icon and program group icon for this. On windows I just want to have the exe inside of the installed files with an icon I choose. On Linux/Mac I want to have a command run "mono myprogram.exe"
In the launchers section, you can add external launchers. The "Create program group" action will treat them like the generated launchers.
On Linux/Mac I want to have a command run "mono myprogram.exe"
You should put that command into a shell script and use that shell script as an external launcher.

Set run configuration for multiple files at once?

Is there a way to set run configuration (e.g. "command line arguments") for multiple files all at once in Eclipse? It would be convenient when running single testing test script, right now any arguments are added script by script.