testdouble / quibble

Makes it easy to replace require'd dependencies.
94 stars 25 forks source link

quibble doesn't throw when file can't be found #64

Closed TimDaub closed 2 years ago

TimDaub commented 2 years ago
// index.mjs
import quibble from "quibble";

const run = async () => {
  await quibble.esm("./fantasy/fantasy.mjs");
};
run().catch(console.log).then(console.log);

when you run node index.mjs it just returns undefined. My expectation is that it should throw.

searls commented 2 years ago

I don't think this is a bug. If you see this test of non-ESM, quibble has always supported faking non-existent paths

TimDaub commented 2 years ago

I found it quite confusing and it cost me some time only understanding that it wouldn't throw.

Maybe, would you be willing to allow the esm function to throw if a special input is passed. Or maybe a safeEsm function that always throws?

Otherwise, maybe making people more aware in the readme could help too.

searls commented 2 years ago

I understand your point, but because this is a mature/stable/low-config library I would not support a new option for branching behavior like this. Happy to look at a PR that warns replacing paths to non-existent files is supported, however