Skip to content
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

Support for Electron >= 29 #119

Open
lesn1kk opened this issue Jun 7, 2024 · 12 comments
Open

Support for Electron >= 29 #119

lesn1kk opened this issue Jun 7, 2024 · 12 comments

Comments

@lesn1kk
Copy link

lesn1kk commented Jun 7, 2024

Hi,

It looks like the provider does not work with Electron version 29 and above (considering also the workaround proposed in another issue).

Do you plan adding such support in nearest future?
Could you provide me some details how can I debug the hook responsible for decorating and mocking the electron stuff?

Thanks

@Bayheck
Copy link
Contributor

Bayheck commented Jun 10, 2024

We have not researched the issue yet because we are focused on other tasks.

You can try using VSCode Uncaught Exceptions breakpoints for debugging.

@thomas-jakemeyn
Copy link

Hello @Bayheck,

I believe that this issue should be reopened because the problem for Electron 29+ is not the same as for Electron 28. As originally stated by @lesn1kk, applying the fix from #110 does not solve the problem for Electron 29+. So this issue is not a duplicate.

What's the plan regarding the maintenance of this Electron plugin? It has not been made compatible with Electron 28 (2023/12) yet, despite the availability of a documented solution. Will it be deprecated? Thanks in advance for clarifying the situation (and letting us prepare ourselves accordingly).

@thomas-jakemeyn
Copy link

thomas-jakemeyn commented Jun 10, 2024

I managed to make our TestCafe tests start with Electron 30.0.9 by patching src/injectable/index.js as followed (just replace the entire file content).

module.exports = function (config, testPageUrl) {
	const appEntryPoint = require.resolve(config.appPath);
	config.appEntryPoint = appEntryPoint;
	process.argv.push(appEntryPoint);

	const originalAppCodeLoaded = process.appCodeLoaded;
	process.appCodeLoaded = () => {
		require('./electron-mocks')(config, testPageUrl);
		originalAppCodeLoaded();
	};
};

Note that I got rid of the decorator for Module._load(). This reduces complexity, increases robustness and is a step in the right direction for the compatibility with ESM (I could successfully run my test with a .mjs entrypoint).

@Bayheck
Copy link
Contributor

Bayheck commented Jun 11, 2024

I will reopen the issue, but we cannot give any estimates of when we will fix it.

@thomas-jakemeyn
Copy link

UPDATE: the patch above works fine with Electron 30.0.9. But we just upgraded to 30.1.1 and the tests do not start anymore.

@thomas-jakemeyn
Copy link

thomas-jakemeyn commented Jun 18, 2024

After some preliminary investigations, it looks like this function of the TestCafe test-run module is never invoked when running the tests for Electron 30.1.1. As a consequence, 'connected' is never emitted and the tests do not start (see here).

@thomas-jakemeyn
Copy link

The problem is actually related to this code block in Hammerhead. It triggers an error that breaks the transport mechanism, which ultimately prevents the tests from starting. It is only executed for Electron 30.1.1 because of this code change that makes fetch available on the window object. But win.Response and win.Request are both undefined in web workers because of a bug in Electron. See this comment for more details.

The solution is to wait for a fix of Electron. The workaround is to comment out the code block in node_modules / testcafe-hammerhead / lib / client / transport-worker.js.

@thomas-jakemeyn
Copy link

I have reported the issue to the Electron team.

Copy link

This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.

Copy link

We're closing this issue after a prolonged period of inactivity. If it still affects you, please add a comment to this issue with up-to-date information. Thank you.

@bd-halkoaho
Copy link

This is still an issue. I assume some changes are needed in testcafe-browser-provider-electron even with the electron fix, but I don't know.

@lesn1kk
Copy link
Author

lesn1kk commented Jan 7, 2025

We were able to run our e2e using Electron 33.2.0, testcafe 3.7.0 and the slightly modified fix provided in this issue by @thomas-jakemeyn.

Since we are also running against compiled exe, in such case the appEntryPoint should not be set with config.appPath, we simply provide electronPath in .testcafe-electron-rc instead.

// src/injectable/index.js
module.exports = function (config, testPageUrl) {
    if (config.appPath) {
        const appEntryPoint = require.resolve(config.appPath);
        config.appEntryPoint = appEntryPoint;
        process.argv.push(appEntryPoint);
    }

    const originalAppCodeLoaded = process.appCodeLoaded;
    process.appCodeLoaded = () => {
        require('./electron-mocks')(config, testPageUrl);
        originalAppCodeLoaded();
    };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants