Add test to check that 'end' is emitted before 'close'