node tests: Split up tutorial into smaller examples.

I didn't bother to keep the very last test from
tutorial, which has some complications related
to clearing stream_list data and was kind of
overkill.
This commit is contained in:
Steve Howell
2021-03-15 12:03:00 +00:00
committed by Steve Howell
parent bbec2d9625
commit 198c67a9bd
10 changed files with 766 additions and 810 deletions

View File

@@ -93,25 +93,6 @@ exports.mock_esm = (request, obj = {}) => {
return exports.mock_cjs(request, {...obj, __esModule: true});
};
exports.unmock_module = (request) => {
const filename = Module._resolveFilename(
request,
require.cache[callsites()[1].getFileName()],
false,
);
if (!module_mocks.has(filename)) {
throw new Error(`Cannot unmock ${filename}, which was not mocked`);
}
if (!used_module_mocks.has(filename)) {
throw new Error(`You asked to mock ${filename} but we never saw it during compilation.`);
}
module_mocks.delete(filename);
used_module_mocks.delete(filename);
};
exports.set_global = function (name, val) {
if (val === null) {
throw new Error(`