Skip to content

Commit

Permalink
Merge pull request #747 from webdriverio-community/sm/improve-old-ele…
Browse files Browse the repository at this point in the history
…ctron-errors

fix: detect old electron versions and throw error
  • Loading branch information
goosewobbler authored Aug 22, 2024
2 parents 24ac6f2 + ef24506 commit 63d29a8
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 13 deletions.
2 changes: 1 addition & 1 deletion fixtures/electron-in-dependencies/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Electron found in dependencies",
"scripts": {},
"dependencies": {
"electron": "^25.0.0"
"electron": "^26.0.0"
},
"devDependencies": {}
}
2 changes: 1 addition & 1 deletion fixtures/electron-in-dev-dependencies/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"scripts": {},
"dependencies": {},
"devDependencies": {
"electron": "^25.0.0"
"electron": "^26.0.0"
}
}
10 changes: 10 additions & 0 deletions fixtures/old-electron/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "fixture-old-electron",
"version": "1.0.0",
"description": "Old Electron found in devDependencies",
"scripts": {},
"dependencies": {},
"devDependencies": {
"electron": "^25.0.0"
}
}
10 changes: 9 additions & 1 deletion packages/wdio-electron-service/src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ export default class ElectronLaunchService implements Services.ServiceInstance {

await Promise.all(
caps.map(async (cap) => {
const electronVersion = cap.browserVersion || localElectronVersion;
const electronVersion = cap.browserVersion || localElectronVersion || '';
const chromiumVersion = await getChromiumVersion(electronVersion);
log.info(`Found Electron v${electronVersion} with Chromedriver v${chromiumVersion}`);

if (Number.parseInt(electronVersion.split('.')[0]) < 26 && !cap['wdio:chromedriverOptions']?.binary) {
const invalidElectronVersionError = new SevereServiceError(
'Electron version must be 26 or higher for auto-configuration of Chromedriver. If you want to use an older version of Electron, you must configure Chromedriver manually using the wdio:chromedriverOptions capability',
);
log.error(invalidElectronVersionError.message);
throw invalidElectronVersionError;
}

let {
appBinaryPath,
appEntryPoint,
Expand Down
77 changes: 67 additions & 10 deletions packages/wdio-electron-service/test/launcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ beforeEach(async () => {
version: '26.2.2',
chrome: '116.0.5845.190',
},
{
version: '32.0.1',
chrome: '128.0.6613.36',
},
]);
});

Expand Down Expand Up @@ -88,6 +92,59 @@ describe('onPrepare', () => {
);
});

it('should throw an error when the local Electron version is older than v26 and Chromedriver is not configured manually', async () => {
instance = new LaunchService(
options,
[] as never,
{
services: [['electron', options]],
rootDir: getFixtureDir('old-electron'),
} as Options.Testrunner,
);
const capabilities: WebdriverIO.Capabilities[] = [
{
browserName: 'electron',
},
];
await expect(() => instance?.onPrepare({} as never, capabilities)).rejects.toThrow(
'Electron version must be 26 or higher for auto-configuration of Chromedriver. If you want to use an older version of Electron, you must configure Chromedriver manually using the wdio:chromedriverOptions capability',
);
});

it('should not throw an error when the local Electron version is older than v26 and Chromedriver is configured manually', async () => {
instance = new LaunchService(
options,
[] as never,
{
services: [['electron', options]],
rootDir: getFixtureDir('old-electron'),
} as Options.Testrunner,
);
const capabilities: WebdriverIO.Capabilities[] = [
{
'browserName': 'electron',
'wdio:chromedriverOptions': {
binary: '/path/to/chromedriver',
},
},
];
await instance?.onPrepare({} as never, capabilities);
expect(capabilities[0]).toEqual({
'browserName': 'chrome',
'browserVersion': '114.0.5735.45',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
windowTypes: ['app', 'webview'],
},
'wdio:chromedriverOptions': {
binary: '/path/to/chromedriver',
},
'wdio:electronServiceOptions': {},
'wdio:enforceWebDriverClassic': true,
});
});

it('should throw an error when appBinaryPath is not specified and no build tool is found', async () => {
delete options.appBinaryPath;
(getAppBuildInfo as Mock).mockRejectedValueOnce(new Error('b0rk - no build tool found'));
Expand Down Expand Up @@ -230,7 +287,7 @@ describe('onPrepare', () => {
await instance?.onPrepare({} as never, capabilities);
expect(capabilities[0]).toEqual({
'browserName': 'chrome',
'browserVersion': '114.0.5735.45',
'browserVersion': '116.0.5845.82',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
Expand Down Expand Up @@ -286,7 +343,7 @@ describe('onPrepare', () => {
await instance?.onPrepare({} as never, capabilities);
expect(capabilities[0]).toEqual({
'browserName': 'chrome',
'browserVersion': '114.0.5735.45',
'browserVersion': '116.0.5845.82',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
Expand Down Expand Up @@ -533,7 +590,7 @@ describe('onPrepare', () => {
myElectronProject: {
capabilities: {
browserName: 'electron',
browserVersion: '26.2.2',
browserVersion: '32.0.1',
},
},
chrome: {
Expand All @@ -546,7 +603,7 @@ describe('onPrepare', () => {
firstMatch: [],
alwaysMatch: {
browserName: 'electron',
browserVersion: '25.0.0',
browserVersion: '26.2.2',
},
},
},
Expand All @@ -561,7 +618,7 @@ describe('onPrepare', () => {
myElectronProject: {
capabilities: {
'browserName': 'chrome',
'browserVersion': '116.0.5845.190',
'browserVersion': '128.0.6613.36',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
Expand All @@ -581,7 +638,7 @@ describe('onPrepare', () => {
firstMatch: [],
alwaysMatch: {
'browserName': 'chrome',
'browserVersion': '114.0.5735.45',
'browserVersion': '116.0.5845.190',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
Expand All @@ -606,7 +663,7 @@ describe('onPrepare', () => {
myElectronProject: {
capabilities: {
browserName: 'electron',
browserVersion: '26.2.2',
browserVersion: '32.0.1',
},
},
},
Expand All @@ -621,7 +678,7 @@ describe('onPrepare', () => {
firstMatch: [],
alwaysMatch: {
browserName: 'electron',
browserVersion: '25.0.0',
browserVersion: '26.2.2',
},
},
},
Expand All @@ -638,7 +695,7 @@ describe('onPrepare', () => {
myElectronProject: {
capabilities: {
'browserName': 'chrome',
'browserVersion': '116.0.5845.190',
'browserVersion': '128.0.6613.36',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
Expand All @@ -660,7 +717,7 @@ describe('onPrepare', () => {
firstMatch: [],
alwaysMatch: {
'browserName': 'chrome',
'browserVersion': '114.0.5735.45',
'browserVersion': '116.0.5845.190',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
Expand Down

0 comments on commit 63d29a8

Please sign in to comment.