Added logic and test for case without terminal (eg. Jenkins)