It depends on the drug, when it was last used and how it impacts the child. The damage can be apparent in the child for life. For example, fetal alcohol syndrome causes very marked physical features which are part of the individual's appearance for life. As for testing for the actual substance, you'd have to talk to the doctor about the specific circumstances to get an answer to your question.
If you are involved with such a situation, either as a drug addicted mother or the father of a child who's mother is addicted, etc., it's far better for the child if the medical team know about the drug history during the pregnancy and for the delivery as they can better protect the wellfare of both the mother and the child, and might be able to manage the addiction proactively. If the intention is to hide the addiction to avoid being found out to be using, this is silly as medical teams can recognize a drug impacted infant very easily and keeping the secret will be impossible.
I am not a medical professional but have read and heard experts who have stated that withdrawal during pregnancy can also be perilous. Every pregnant woman should seek regular medical care thorughout her pregnancy, and this becomes more critical when she is addicted. From a legal perspective, if she seeks medical help and help with the addiction issues related to her pregnancy, I believe that doing so would be viewed as a responsible act and a good sign for her fitness to parent, whereas ignoring the problem would not be.