How were the covid vaccines approved when it takes an average of quite a few years to make and most importantly, test, a vaccine?

They’re being approved under an EUA – Emergency Use Authorization. “For an EUA to be issued for a vaccine, for which there is adequate manufacturing information to ensure quality and consistency, FDA must determine that the known and potential benefits outweigh the known and potential risks of the vaccine.” For more info see the CDC site: bit.ly/EUADetails