@wdio/browser-runner
Version:
A WebdriverIO runner to run unit tests tests in the browser.
34 lines (33 loc) • 1.21 kB
JavaScript
// src/browser/spy.ts
export * from "@vitest/spy";
var a = document.createElement("a");
function resolveUrl(path) {
a.href = path;
return a.href;
}
var ERROR_MESSAGE = '[wdio] There was an error, when mocking a module. If you are using the "mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://webdriver.io/docs/component-testing/mocking';
async function mock(path, factory) {
if (!factory || typeof factory !== "function") {
return;
}
const actualImport = arguments[2];
const mockLocalFile = path.startsWith("/") || path.startsWith("./") || path.startsWith("../");
const mockPath = mockLocalFile ? new URL(resolveUrl(window.__wdioSpec__.split("/").slice(0, -1).join("/") + "/" + path)).pathname.replace(/\.[^/.]+$/, "") : path;
try {
const resolvedMock = await factory(actualImport);
window.__wdioMockCache__.set(mockPath, resolvedMock);
} catch (err) {
const error = err;
throw new Error("".concat(ERROR_MESSAGE, "\n").concat(error.message, ": ").concat(error.stack));
}
}
function unmock(moduleName) {
}
function mocked(item) {
return item;
}
export {
mock,
mocked,
unmock
};