Replies: 7 comments 7 replies
-
The const theme = await browser.electron.execute(async () => {
const { ipcRenderer } = await import('electron/renderer')
return ipcRenderer.sendSync("get-system-theme")
}) @goosewobbler what do you think? Is it worth exposing the IPC renderer in some way? |
Beta Was this translation helpful? Give feedback.
-
Thank you for your prompt reply. 🌹 Will this approach bring additional performance burden? (And it can be expected that it will slow down the progress of testing, especially when there are many Currently I can implement it through the const theme = await browser.execute(() => window.Context.getSystemTheme()); Because I defined them ahead of time in contextBridge.exposeInMainWorld('Context', {
// ...
getSystemTheme: () => ipcRenderer.sendSync('get-system-theme') as string,
/ ...
}); I think there is no need to expose the Maybe I'll close this discussion, of course, if you guys have anything to add. Thank you very much again. 😄 |
Beta Was this translation helpful? Give feedback.
-
@christian-bromann Are there any major changes in the latest version? When I upgraded to the latest version, both of the above methods became unavailable. const theme = await browser.execute(() => window.Context.getSystemTheme()); Error: TSError: ⨯ Unable to compile TypeScript:
src/__tests__/specs/api.spec.ts(19,58): error TS2551: Property 'Context' does not exist on type 'Window & typeof globalThis'. Did you mean 'context'? const theme = await browser.electron.execute(async () => {
const { ipcRenderer } = await import("electron/renderer");
return ipcRenderer.sendSync("get-system-theme");
}); javascript error: javascript error: Error invoking remote method 'wdio-electron.execute': ReferenceError: __awaiter is not defined
(Session info: chrome=120.0.6099.276) I checked the documentation and couldn't find any relevant instructions or solutions. |
Beta Was this translation helpful? Give feedback.
-
@1111mp I'm just catching up with this - I can see what you are trying to do with the nativeTheme, can you not implement this in a much more direct way with
As for the latest version, it just contains a few new mocking functions, there are no major changes. What version did you upgrade from? |
Beta Was this translation helpful? Give feedback.
-
Thank you for your reply. 🌹 from:
upgrade to:
I'm afraid not, because I need to test these // api.spec.ts
import { expect } from "@wdio/globals";
import { browser } from "wdio-electron-service";
const { productName, version } = globalThis.packageJson;
describe("Electron APIs", () => {
describe("app", () => {
it("should retrieve app metadata through the electron API", async () => {
const appName = await browser.electron.execute((electron) => electron.app.getName());
expect(appName).toEqual(productName);
const appVersion = await browser.electron.execute((electron) => electron.app.getVersion());
expect(appVersion).toEqual(version);
});
});
describe("IPC Renderer", () => {
describe("get-system-theme", () => {
it("should return the value of system theme", async () => {
const theme = await browser.execute(() => window.Context.getSystemTheme());
expect(theme).toHaveText(["light", "dark"]);
});
});
describe("setting-data-get", () => {
it("should return the value of setting", async () => {
const setting = await browser.execute(() => window.Context.getSettingData());
expect(setting).toBeDefined();
expect(setting).toHaveProperty("locale");
expect(setting).toHaveProperty("mirror");
expect(setting).toHaveProperty("theme");
});
});
});
});
// preload.ts
contextBridge.exposeInMainWorld('Context', {
// ...
updateSettingData: (setting: Nvmd.Setting) =>
ipcRenderer.invoke('setting-data-set', setting) as Promise<void>,
getSystemTheme: () => ipcRenderer.sendSync('get-system-theme') as string,
// ...
}) I can test them before upgrading through If you need any more information from me, please feel free to let me know. Thank you so much. 🌹 If you want to see the complete code, you can check the code at https://github.com/1111mp/nvm-desktop. By the way, you should ignore the |
Beta Was this translation helpful? Give feedback.
-
I checked out your code and tried a couple of things. In order to get the tests to work I had to make some hacky changes, I put these in a draft PR so you can see what they are and hopefully give you a starting point to work out what is wrong: https://github.com/1111mp/nvm-desktop/pull/59/files Firstly I pinned all the versions to the ones you posted as "before upgrade" - the API tests fail, the service is complaining about the context bridge being unavailable. So this would imply the upgrade is not the issue here. I then manually set the isTest value in |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for your patience and reply. 🌹 🚀 I'm really sorry for my delay in replying (I was on the train all night last night, it was such a long journey...) Yes, with your help I have now located the problem: test failed due to // error TS2551: Property 'Context' does not exist on type 'Window & typeof globalThis'.
const theme = await browser.execute(() => window.Context.getSystemTheme());
// it will be fine
const theme = await browser.execute(() => ((window as unknown as { Context: any }).Context.getSystemTheme())); However, // wdio.conf.ts
export const config: Options.Testrunner = {
//
// ====================
// Runner Configuration
// ====================
// WebdriverIO supports running e2e tests as well as unit and component tests.
runner: "local",
outputDir: "wdio-logs",
autoCompileOpts: {
autoCompile: true,
tsNodeOpts: {
project: "./tsconfig.test.json",
transpileOnly: true
}
},
// ...
}
// tsconfig.test.json
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true,
"allowJs": true,
"types": ["node", "@wdio/globals/types", "@wdio/mocha-framework", "wdio-electron-service"]
},
"ts-node": {
"transpileOnly": true,
"files": true
},
"include": ["src/__tests__/**/*.spec.ts", "src/preload/preload.d.ts"]
}
// src/preload/preload.d.ts
import { ElectronHandler } from './index'
declare global {
interface Window {
Context: ElectronHandler
}
}
export {} In the end, I avoided this error by adding "test": "TS_NODE_TRANSPILE_ONLY=true wdio run ./wdio.conf.ts" I guess it is because the configuration of Thank you very much again for your patient reply. 😄 |
Beta Was this translation helpful? Give feedback.
-
How to implement it now?
I tried like this:
But it will report an error:
Thanks in advance. 🌹
Currently I can achieve the same goal through the following method:
Or is there a better way...
Beta Was this translation helpful? Give feedback.
All reactions