test_runner: fix mocking modules with quote in their URL

PR-URL: https://github.com/nodejs/node/pull/55083
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tierney Cyren <hello@bnb.im>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
Antoine du Hamel authored and Michaël Zasso committed 2024-10-04 10:20:27 +02:00
1 parent fdae57f1e1
commit 7eaeba499a
3 files changed
+11 -1

No files matched your search

@@ -413,6 +413,15 @@ test('modules cannot be mocked multiple times at once', async (t) => {
t.mock.module(fixture, { namedExports: { fn() { return 42; } } });
await assert.rejects(import(fixture), { code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME' });
});
await t.test('Importing a module with a quote in its URL should work', async (t) => {
const fixture = fixtures.fileURL('module-mocking', 'don\'t-open.mjs');
t.mock.module(fixture, { namedExports: { fn() { return 42; } } });
const mocked = await import(fixture);
assert.strictEqual(mocked.fn(), 42);
});
});
test('mocks are automatically restored', async (t) => {