Fix/improve npm test compatibility on windows

A refactored version of PR #1295

@kayhadrin, refactoring this was hell, so could you download it to your windows machine and make sure it works as you wanted it to?