Pregnancy test

How many days before my period can you do a pregnancy test? Or is it worth it to just wait?