Refactor tests middleware into history-support middleware