St Helens survived a difficult test against a tough Huddersfield Giants team, as they ground out a 12-14 win.