-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Leak on prettyDOM calls while waiting for expect.element #7139
Comments
@sheremet-va if you havent started working on it yet, do you mind sharing the approach youd like to take here? i have some free time today and would be nice to have a contribution to the project EDIT: I think we have a few options
Let me know if im missing something EDIT 2: I dont think option 3 is easily feasible because of the sync nature of how prettyDOM is used in that scenario. In other hand, I gave a shot to option 1 locally and it works well. Instead of flagging the last attempt, I just try one last time before rejecting the promise here. Copy-pasting the hardcoded solution I have locally so you can check:
return function(...args) {
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
const promise = () => new Promise((resolve, reject) => {
let intervalId;
let timeoutId;
let lastError;
const { setTimeout, clearTimeout } = getSafeTimers();
const check = async () => {
try {
chai$1.util.flag(assertion, "_name", key);
const obj = await fn();
chai$1.util.flag(assertion, "object", obj);
resolve(await assertionFunction.call(assertion, ...args));
clearTimeout(intervalId);
clearTimeout(timeoutId);
} catch (err) {
lastError = err;
- intervalId = setTimeout(check, interval);
+ if (!chai$1.util.flag(assertion, "_isLastPollAttempt")) {
+ intervalId = setTimeout(check, interval);
+ }
}
};
timeoutId = setTimeout(async () => {
clearTimeout(intervalId);
+ chai$1.util.flag(assertion, "_isLastPollAttempt", true);
+ await check();
reject(
copyStackTrace$1(
new Error(`Matcher did not succeed in ${timeout}ms`, {
cause: lastError
}),
STACK_TRACE_ERROR
)
);
}, timeout);
check();
});
}
return expect.poll(function element() {
if (elementOrLocator instanceof Element || elementOrLocator == null) {
return elementOrLocator;
}
chai.util.flag(this, "_poll.element", true);
const isNot = chai.util.flag(this, "negate");
const name = chai.util.flag(this, "_name");
+ const isLatPollAttempt = chai.util.flag(this, "_isLastPollAttempt");
if (isNot && name === "toBeInTheDocument") {
return elementOrLocator.query();
}
+ if (isLatPollAttempt) {
+ return elementOrLocator.element();
+ }
+
+ const result = elementOrLocator.query();
+
+ if (!result) {
+ throw new Error(`Cannot find element with locator: ${JSON.stringify(elementOrLocator)}`);
+ }
+
+ return result;
}, options); |
that's what I would've done |
Describe the bug
While waiting for expect.element to resolve, prettyDOM will be called on every attempt and its going to send the whole body as
dom
parameter. This makes memory usage go wild and at some point it goes OOM. Can confirm removingprettyDom
usage in following line fixes the issue:vitest/packages/browser/src/client/tester/public-utils.ts
Line 69 in f4406f1
IDK how Im the first person to notice this bug... I wonder if Im missing a config param or something.
Reproduction
Had to reproduce it on private codebase so I cant really share code here.
After removing the
prettyDOM
call, all tests pass successfully:System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: