facebook / memlab

A framework for finding JavaScript memory leaks and analyzing heap snapshots
https://facebook.github.io/memlab/
MIT License
4.37k stars 119 forks source link

Invalid scenario file #93

Closed jdelbarcogarza-softtek closed 10 months ago

jdelbarcogarza-softtek commented 1 year ago

`Hello, I'm trying to test memlab for a project. While following the tutorial it worked, but now when trying to run a scenario in my project. The errorInvalid scenario file: .\tests\test.jscomes up. Context: I placed thescenario.jsfile inside/src/test` folders.

Here is my scenario:


module.exports = {
    url: () => "http://localhost:5173/apps/music%20app/",
    action: async () => {
        // enter requests route by clicking link
        const elements = await page.$x(
            "//a[contains(., 'Requests')]"
        )

        if (elements.length > 0) {
            const [a] = elements;
            await a.click();

            // Clean up external references from memlab
            await Promise.all(elements.map((e) => e.dispose()));
        } else {
            console.log("No matching elements found.");
        }
    },
    back: async () => await page.click("a[contains(., 'Dashboard')]"),
};

Could someone put me in the right direction here on how to get memlab up and running?

jdelbarcogarza-softtek commented 1 year ago

Update: when the file is extracted from the project's folder, memlab works. But should memlab be able to run code inside the project's codebase?

JacksonGL commented 1 year ago

The scenario file doesn't define page function parameter for action and back, not sure why it works when it is outside the project's codebase

mrdulin commented 7 months ago

same issue.

JacksonGL commented 7 months ago

Do not forget about the page parameter in the scenario definition.

module.exports = {
  url: ...
  // do not forget about the `page` parameter here
  action: async (page) => { ... }
  // same
  back: async (page) => { ... }
}
mrdulin commented 7 months ago

Do not forget about the page parameter in the scenario definition.

module.exports = {
  url: ...
  // do not forget about the `page` parameter here
  action: async (page) => { ... }
  // same
  back: async (page) => { ... }
}

OP's code has forgotten the page parameter, but this will not solve the issue.

JacksonGL commented 7 months ago

@mrdulin To help understand and investigate the issue, can you share the steps to reproduce the issue you got? E.g., what the scenario file looked like, how you run the scenario file, and the error message.

0918nobita commented 7 months ago

I was also facing the same issue. By removing the "type": "module" from package.json in npm package containing scenario.js to run and re-running memlab, the issue was resolved.

0918nobita commented 7 months ago

Alternatively, the issue can also be resolved by renaming scenario.js to scenario.cjs .